2019-12-26 05:41:50 +00:00
|
|
|
/* eslint-disable node/no-unsupported-features/node-builtins */
|
|
|
|
(function($, moment, ClipboardJS, config) {
|
2019-12-24 05:36:39 +00:00
|
|
|
$('.columns .column-right-shadow').append($('.columns .column-right').children().clone());
|
|
|
|
|
2019-12-26 05:41:50 +00:00
|
|
|
$('.article img:not(".not-gallery-item")').each(function() {
|
2018-10-16 05:28:42 +00:00
|
|
|
// wrap images with link and add caption if possible
|
|
|
|
if ($(this).parent('a').length === 0) {
|
|
|
|
$(this).wrap('<a class="gallery-item" href="' + $(this).attr('src') + '"></a>');
|
|
|
|
if (this.alt) {
|
|
|
|
$(this).after('<div class="has-text-centered is-size-6 has-text-grey caption">' + this.alt + '</div>');
|
2018-04-28 19:13:05 +00:00
|
|
|
}
|
|
|
|
}
|
2018-10-16 05:28:42 +00:00
|
|
|
});
|
2018-04-30 15:06:32 +00:00
|
|
|
|
2019-12-26 05:41:50 +00:00
|
|
|
if (typeof moment === 'function') {
|
|
|
|
$('.article-meta time').each(function() {
|
2018-10-16 05:28:42 +00:00
|
|
|
$(this).text(moment($(this).attr('datetime')).fromNow());
|
2018-04-30 15:06:32 +00:00
|
|
|
});
|
2018-10-16 05:28:42 +00:00
|
|
|
}
|
2018-10-22 04:51:51 +00:00
|
|
|
|
2019-12-26 05:41:50 +00:00
|
|
|
$('.article > .content > table').each(function() {
|
2019-06-26 03:00:04 +00:00
|
|
|
if ($(this).width() > $(this).parent().width()) {
|
|
|
|
$(this).wrap('<div class="table-overflow"></div>');
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2018-10-22 04:51:51 +00:00
|
|
|
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);
|
2018-11-05 05:28:34 +00:00
|
|
|
|
2019-12-26 05:41:50 +00:00
|
|
|
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 '<span class="fold">' + (fold === 'unfolded' ? '<i class="fas fa-angle-down"></i>' : '<i class="fas fa-angle-right"></i>') + '</span>';
|
|
|
|
}
|
|
|
|
|
2019-08-13 03:41:41 +00:00
|
|
|
$('figure.highlight table').wrap('<div class="highlight-body">');
|
2019-12-26 05:41:50 +00:00
|
|
|
if (typeof config !== 'undefined'
|
|
|
|
&& typeof config.article !== 'undefined'
|
|
|
|
&& typeof config.article.highlight !== 'undefined') {
|
2019-12-20 20:26:49 +00:00
|
|
|
|
|
|
|
$('figure.highlight').addClass('hljs');
|
2019-12-26 05:41:50 +00:00
|
|
|
$('figure.highlight .code .line span').each(function() {
|
2019-12-20 20:26:49 +00:00
|
|
|
const classes = $(this).attr('class').split(/\s+/);
|
|
|
|
if (classes.length === 1) {
|
|
|
|
$(this).addClass('hljs-' + classes[0]);
|
|
|
|
$(this).removeClass(classes[0]);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2019-12-26 05:41:50 +00:00
|
|
|
if (typeof ClipboardJS !== 'undefined' && config.article.highlight.clipboard) {
|
|
|
|
$('figure.highlight').each(function() {
|
|
|
|
const id = 'code-' + Date.now() + (Math.random() * 1000 | 0);
|
|
|
|
const button = '<a href="javascript:;" class="copy" title="Copy" data-clipboard-target="#' + id + ' .code"><i class="fas fa-copy"></i></a>';
|
2019-08-13 03:41:41 +00:00
|
|
|
$(this).attr('id', id);
|
|
|
|
if ($(this).find('figcaption').length) {
|
|
|
|
$(this).find('figcaption').prepend(button);
|
|
|
|
} else {
|
|
|
|
$(this).prepend('<figcaption>' + button + '</figcaption>');
|
|
|
|
}
|
|
|
|
});
|
2019-12-26 05:41:50 +00:00
|
|
|
new ClipboardJS('.highlight .copy'); // eslint-disable-line no-new
|
2019-08-13 03:41:41 +00:00
|
|
|
}
|
2019-12-26 05:41:50 +00:00
|
|
|
const fold = config.article.highlight.fold;
|
2019-08-13 03:41:41 +00:00
|
|
|
if (fold.trim()) {
|
2019-12-26 05:41:50 +00:00
|
|
|
$('figure.highlight').each(function() {
|
2019-08-13 03:41:41 +00:00
|
|
|
if ($(this).find('figcaption').length) {
|
2019-12-26 05:41:50 +00:00
|
|
|
// 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));
|
2019-08-13 03:41:41 +00:00
|
|
|
} else {
|
2019-12-26 05:41:50 +00:00
|
|
|
$(this).prepend('<figcaption>' + createFoldButton(fold) + '</figcaption>');
|
2019-08-13 03:41:41 +00:00
|
|
|
}
|
|
|
|
toggleFold(this, fold === 'folded');
|
|
|
|
});
|
2019-12-26 05:41:50 +00:00
|
|
|
|
|
|
|
$('figure.highlight figcaption .fold').click(function() {
|
|
|
|
const $code = $(this).closest('figure.highlight');
|
2019-08-13 03:41:41 +00:00
|
|
|
toggleFold($code.eq(0), !$code.hasClass('folded'));
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-12-26 05:41:50 +00:00
|
|
|
const $toc = $('#toc');
|
2018-11-05 05:28:34 +00:00
|
|
|
if ($toc.length > 0) {
|
2019-12-26 05:41:50 +00:00
|
|
|
const $mask = $('<div>');
|
2018-11-05 05:28:34 +00:00
|
|
|
$mask.attr('id', 'toc-mask');
|
|
|
|
|
|
|
|
$('body').append($mask);
|
|
|
|
|
2019-12-26 05:41:50 +00:00
|
|
|
function toggleToc() { // eslint-disable-line no-inner-declarations
|
2018-11-05 05:28:34 +00:00
|
|
|
$toc.toggleClass('is-active');
|
|
|
|
$mask.toggleClass('is-active');
|
|
|
|
}
|
|
|
|
|
|
|
|
$toc.on('click', toggleToc);
|
|
|
|
$mask.on('click', toggleToc);
|
|
|
|
$('.navbar-main .catalogue').on('click', toggleToc);
|
|
|
|
}
|
2019-12-20 23:05:36 +00:00
|
|
|
|
|
|
|
// 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;
|
|
|
|
}
|
|
|
|
|
2019-12-26 05:41:50 +00:00
|
|
|
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) => {
|
2019-12-20 23:05:36 +00:00
|
|
|
link.relList.add('noopener');
|
|
|
|
link.target = '_blank';
|
|
|
|
});
|
|
|
|
}
|
2019-12-26 05:41:50 +00:00
|
|
|
}(jQuery, window.moment, window.ClipboardJS, window.IcarusThemeSettings));
|