/* eslint-disable node/no-unsupported-features/node-builtins */ (function($, moment, ClipboardJS, config) { $('.columns .column-right-shadow').append($('.columns .column-right').children().clone()); $('.article img:not(".not-gallery-item")').each(function() { // wrap images with link and add caption if possible if ($(this).parent('a').length === 0) { $(this).wrap(''); if (this.alt) { $(this).after('
' + this.alt + '
'); } } }); if (typeof moment === 'function') { $('.article-meta time').each(function() { $(this).text(moment($(this).attr('datetime')).fromNow()); }); } $('.article > .content > table').each(function() { if ($(this).width() > $(this).parent().width()) { $(this).wrap('
'); } }); function adjustNavbar() { const navbarWidth = $('.navbar-main .navbar-start').outerWidth() + $('.navbar-main .navbar-end').outerWidth(); if ($(document).outerWidth() < navbarWidth) { $('.navbar-main .navbar-menu').addClass('is-flex-start'); } else { $('.navbar-main .navbar-menu').removeClass('is-flex-start'); } } adjustNavbar(); $(window).resize(adjustNavbar); function toggleFold(codeBlock, isFolded) { const $toggle = $(codeBlock).find('.fold i'); !isFolded ? $(codeBlock).removeClass('folded') : $(codeBlock).addClass('folded'); !isFolded ? $toggle.removeClass('fa-angle-right') : $toggle.removeClass('fa-angle-down'); !isFolded ? $toggle.addClass('fa-angle-down') : $toggle.addClass('fa-angle-right'); } function createFoldButton(fold) { return '' + (fold === 'unfolded' ? '' : '') + ''; } $('figure.highlight table').wrap('
'); if (typeof config !== 'undefined' && typeof config.article !== 'undefined' && typeof config.article.highlight !== 'undefined') { $('figure.highlight').addClass('hljs'); $('figure.highlight .code .line span').each(function() { const classes = $(this).attr('class').split(/\s+/); if (classes.length === 1) { $(this).addClass('hljs-' + classes[0]); $(this).removeClass(classes[0]); } }); if (typeof ClipboardJS !== 'undefined' && config.article.highlight.clipboard) { $('figure.highlight').each(function() { const id = 'code-' + Date.now() + (Math.random() * 1000 | 0); const button = ''; $(this).attr('id', id); if ($(this).find('figcaption').length) { $(this).find('figcaption').prepend(button); } else { $(this).prepend('
' + button + '
'); } }); new ClipboardJS('.highlight .copy'); // eslint-disable-line no-new } const fold = config.article.highlight.fold; if (fold.trim()) { $('figure.highlight').each(function() { if ($(this).find('figcaption').length) { // fold individual code block if ($(this).find('figcaption').find('span').length > 0) { const span = $(this).find('figcaption').find('span').eq(0); if (span[0].innerText.indexOf('>folded') > -1) { span[0].innerText = span[0].innerText.replace('>folded', ''); $(this).find('figcaption').prepend(createFoldButton('folded')); toggleFold(this, true); return; } } $(this).find('figcaption').prepend(createFoldButton(fold)); } else { $(this).prepend('
' + createFoldButton(fold) + '
'); } toggleFold(this, fold === 'folded'); }); $('figure.highlight figcaption .fold').click(function() { const $code = $(this).closest('figure.highlight'); toggleFold($code.eq(0), !$code.hasClass('folded')); }); } } const $toc = $('#toc'); if ($toc.length > 0) { const $mask = $('
'); $mask.attr('id', 'toc-mask'); $('body').append($mask); function toggleToc() { // eslint-disable-line no-inner-declarations $toc.toggleClass('is-active'); $mask.toggleClass('is-active'); } $toc.on('click', toggleToc); $mask.on('click', toggleToc); $('.navbar-main .catalogue').on('click', toggleToc); } // hexo-util/lib/is_external_link.js function isExternalLink(input, sitehost, exclude) { try { sitehost = new URL(sitehost).hostname; } catch (e) { } if (!sitehost) return false; // handle relative url const data = new URL(input, 'http://' + sitehost); // handle mailto: javascript: vbscript: and so on if (data.origin === 'null') return false; const host = data.hostname; if (exclude) { exclude = Array.isArray(exclude) ? exclude : [exclude]; if (exclude && exclude.length) { for (const i of exclude) { if (host === i) return false; } } } if (host !== sitehost) return true; return false; } if (typeof config !== 'undefined' && typeof config.site.url !== 'undefined' && typeof config.site.external_link !== 'undefined' && config.site.external_link.enable) { $('.article .content a').filter((i, link) => { return link.href && !$(link).attr('href').startsWith('#') && link.classList.length === 0 && isExternalLink(link.href, config.site.url, config.site.external_link.exclude); }).each((i, link) => { link.relList.add('noopener'); link.target = '_blank'; }); } }(jQuery, window.moment, window.ClipboardJS, window.IcarusThemeSettings));