2019-05-21 01:32:49 +00:00
|
|
|
(($) => {
|
2018-10-02 02:40:31 +00:00
|
|
|
// Fancybox caption
|
2019-05-21 01:32:49 +00:00
|
|
|
$('.article-entry').each((i) => {
|
|
|
|
$(this).find('img').each(() => {
|
2018-10-02 02:40:31 +00:00
|
|
|
// Don't insert fancybox element to cloudinary's cld-responsive img class
|
|
|
|
if ($(this).hasClass('cld-responsive') || $(this).parent().hasClass('fancybox')) return
|
2018-09-27 08:54:10 +00:00
|
|
|
|
2019-04-10 10:48:45 +00:00
|
|
|
const alt = this.alt
|
2018-09-27 08:54:10 +00:00
|
|
|
|
|
|
|
if (alt) {
|
|
|
|
$(this).after('<span class="caption">' + alt + '</span>')
|
|
|
|
}
|
|
|
|
|
|
|
|
$(this).wrap('<a href="' + this.src + '" title="' + alt + '" class="fancybox"></a>')
|
|
|
|
})
|
|
|
|
|
2019-05-21 01:32:49 +00:00
|
|
|
$(this).find('.fancybox').each(() => {
|
2018-09-27 08:54:10 +00:00
|
|
|
$(this).attr('rel', 'article' + i)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
if ($.fancybox) {
|
|
|
|
$('.fancybox').fancybox()
|
|
|
|
}
|
|
|
|
|
2018-10-25 09:03:38 +00:00
|
|
|
// Add "Copy" button to code snippet
|
2019-04-10 10:48:45 +00:00
|
|
|
const code = document.getElementsByClassName('code')
|
2018-09-27 08:54:10 +00:00
|
|
|
|
2019-04-10 10:48:45 +00:00
|
|
|
for (let i = 0; i < code.length; i++) {
|
|
|
|
const button = document.createElement('button')
|
2018-10-25 09:03:38 +00:00
|
|
|
button.className = 'copy-button'
|
|
|
|
button.textContent = 'Copy'
|
2018-09-29 09:07:34 +00:00
|
|
|
|
2018-10-25 09:03:38 +00:00
|
|
|
code[i].appendChild(button)
|
2018-09-30 03:51:59 +00:00
|
|
|
}
|
2018-09-29 09:07:34 +00:00
|
|
|
|
2019-05-21 01:32:49 +00:00
|
|
|
$(document).ready(() => {
|
2018-09-30 03:51:59 +00:00
|
|
|
// Add copy to clipboard button for code snippet
|
2019-04-10 10:48:45 +00:00
|
|
|
const copyCode = new ClipboardJS('.copy-button', {
|
2019-05-21 01:32:49 +00:00
|
|
|
target: (trigger) => {
|
2018-10-25 09:03:38 +00:00
|
|
|
return trigger.previousElementSibling
|
|
|
|
}
|
|
|
|
})
|
2018-09-27 08:54:10 +00:00
|
|
|
|
2019-05-21 01:32:49 +00:00
|
|
|
copyCode.on('success', (event) => {
|
2018-10-25 09:03:38 +00:00
|
|
|
event.clearSelection()
|
|
|
|
event.trigger.textContent = 'Copied'
|
2019-05-21 01:32:49 +00:00
|
|
|
window.setTimeout(() => {
|
2018-10-25 09:03:38 +00:00
|
|
|
event.trigger.textContent = 'Copy'
|
|
|
|
}, 2000)
|
|
|
|
})
|
2018-09-29 09:07:34 +00:00
|
|
|
|
2019-05-21 01:32:49 +00:00
|
|
|
copyCode.on('error', (event) => {
|
2018-10-25 09:03:38 +00:00
|
|
|
event.trigger.textContent = 'Press "Ctrl + C" to copy'
|
2019-05-21 01:32:49 +00:00
|
|
|
window.setTimeout(() => {
|
2018-10-25 09:03:38 +00:00
|
|
|
event.trigger.textContent = 'Copy'
|
|
|
|
}, 2000)
|
|
|
|
})
|
2019-05-21 01:19:30 +00:00
|
|
|
|
|
|
|
// Initialize Cloudinary responsive function
|
2019-05-21 01:32:49 +00:00
|
|
|
const cl = cloudinary.Cloudinary.new({ cloud_name: 'curben' })
|
2019-05-21 01:19:30 +00:00
|
|
|
cl.responsive()
|
2018-10-25 09:03:38 +00:00
|
|
|
})
|
2018-09-29 09:07:34 +00:00
|
|
|
})(jQuery)
|
2019-05-21 04:42:30 +00:00
|
|
|
|
|
|
|
// Search button function
|
|
|
|
const searchClick = document.getElementById('searchClick')
|
|
|
|
searchClick.onclick = function() {
|
|
|
|
window.open('https://gitlab.com/search?utf8=%E2%9C%93&search=' +
|
|
|
|
document.getElementById('searchTxt').value +
|
|
|
|
'&group_id=&project_id=8306723&search_code=true&repository_ref=master')
|
|
|
|
}
|