');
$(this).find('figcaption div.level-left').append($(this).find('figcaption').find('span'));
$(this).find('figcaption div.level-right').append($(this).find('figcaption').find('a'));
} else {
if (clipboard || fold) {
$(this).prepend('
');
}
}
});
if (typeof ClipboardJS !== 'undefined' && clipboard) {
$('figure.highlight').each(function() {
const id = 'code-' + Date.now() + (Math.random() * 1000 | 0);
const button = '
';
$(this).attr('id', id);
$(this).find('figcaption div.level-right').append(button);
});
new ClipboardJS('.highlight .copy'); // eslint-disable-line no-new
}
if (fold) {
$('figure.highlight').each(function() {
if ($(this).find('figcaption').find('span').length > 0) {
const span = $(this).find('figcaption').find('span');
if (span[0].innerText.indexOf('>folded') > -1) {
span[0].innerText = span[0].innerText.replace('>folded', '');
$(this).find('figcaption div.level-left').prepend(createFoldButton('folded'));
toggleFold(this, true);
return;
}
}
$(this).find('figcaption div.level-left').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
let data;
try {
data = new URL(input, 'http://' + sitehost);
} catch (e) { return false; }
// 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));