2018-09-27 08:54:10 +00:00
|
|
|
(function ($) {
|
2018-10-02 02:40:31 +00:00
|
|
|
// Fancybox caption
|
2018-09-27 08:54:10 +00:00
|
|
|
$('.article-entry').each(function (i) {
|
|
|
|
$(this).find('img').each(function () {
|
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
|
|
|
|
|
|
|
var alt = this.alt
|
|
|
|
|
|
|
|
if (alt) {
|
|
|
|
$(this).after('<span class="caption">' + alt + '</span>')
|
|
|
|
}
|
|
|
|
|
|
|
|
$(this).wrap('<a href="' + this.src + '" title="' + alt + '" class="fancybox"></a>')
|
|
|
|
})
|
|
|
|
|
|
|
|
$(this).find('.fancybox').each(function () {
|
|
|
|
$(this).attr('rel', 'article' + i)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
if ($.fancybox) {
|
|
|
|
$('.fancybox').fancybox()
|
|
|
|
}
|
|
|
|
|
2018-10-25 09:03:38 +00:00
|
|
|
// Add "Copy" button to code snippet
|
|
|
|
var code = document.getElementsByClassName('code')
|
2018-09-27 08:54:10 +00:00
|
|
|
|
2018-09-30 03:51:59 +00:00
|
|
|
for (var i = 0; i < code.length; i++) {
|
2018-10-25 09:03:38 +00:00
|
|
|
var button = document.createElement('button')
|
|
|
|
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
|
|
|
|
2018-10-25 09:03:38 +00:00
|
|
|
$(document).ready(function () {
|
2018-09-30 03:51:59 +00:00
|
|
|
// Add copy to clipboard button for code snippet
|
2018-09-29 09:07:34 +00:00
|
|
|
var copyCode = new ClipboardJS('.copy-button', {
|
2018-10-25 09:03:38 +00:00
|
|
|
target: function (trigger) {
|
|
|
|
return trigger.previousElementSibling
|
|
|
|
}
|
|
|
|
})
|
2018-09-27 08:54:10 +00:00
|
|
|
|
2018-10-25 09:03:38 +00:00
|
|
|
copyCode.on('success', function (event) {
|
|
|
|
event.clearSelection()
|
|
|
|
event.trigger.textContent = 'Copied'
|
|
|
|
window.setTimeout(function () {
|
|
|
|
event.trigger.textContent = 'Copy'
|
|
|
|
}, 2000)
|
|
|
|
})
|
2018-09-29 09:07:34 +00:00
|
|
|
|
2018-10-25 09:03:38 +00:00
|
|
|
copyCode.on('error', function (event) {
|
|
|
|
event.trigger.textContent = 'Press "Ctrl + C" to copy'
|
|
|
|
window.setTimeout(function () {
|
|
|
|
event.trigger.textContent = 'Copy'
|
|
|
|
}, 2000)
|
|
|
|
})
|
2018-09-29 09:07:34 +00:00
|
|
|
|
|
|
|
// Navigation menu
|
2018-09-27 08:54:10 +00:00
|
|
|
$('#menu').click(function (event) {
|
2018-10-25 09:03:38 +00:00
|
|
|
var nav = $('#main-nav')
|
|
|
|
nav.toggle('fast')
|
|
|
|
})
|
2018-09-27 08:54:10 +00:00
|
|
|
|
2018-09-29 09:07:34 +00:00
|
|
|
// Show navigation button for smaller screen
|
2018-09-27 08:54:10 +00:00
|
|
|
$(window).resize(function () {
|
2018-10-25 09:03:38 +00:00
|
|
|
var viewportWidth = $(window).width()
|
2018-09-27 08:54:10 +00:00
|
|
|
if (viewportWidth > 468) {
|
2018-10-25 09:03:38 +00:00
|
|
|
$('#main-nav').show('fast')
|
2018-09-27 08:54:10 +00:00
|
|
|
} else {
|
2018-10-25 09:03:38 +00:00
|
|
|
$('#main-nav').hide('fast')
|
2018-09-27 08:54:10 +00:00
|
|
|
}
|
2018-10-25 09:03:38 +00:00
|
|
|
})
|
|
|
|
})
|
2018-09-29 09:07:34 +00:00
|
|
|
})(jQuery)
|