98 lines
4.0 KiB
JavaScript
98 lines
4.0 KiB
JavaScript
![]() |
(function ($) {
|
||
|
alert();
|
||
|
$('.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('<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>');
|
||
|
}
|
||
|
}
|
||
|
});
|
||
|
|
||
|
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('<div class="table-overflow"></div>');
|
||
|
}
|
||
|
});
|
||
|
|
||
|
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);
|
||
|
|
||
|
$('figure.highlight table').wrap('<div class="highlight-body">');
|
||
|
if (typeof (IcarusThemeSettings) !== 'undefined' &&
|
||
|
typeof (IcarusThemeSettings.article) !== 'undefined' &&
|
||
|
typeof (IcarusThemeSettings.article.highlight) !== 'undefined') {
|
||
|
if (typeof (ClipboardJS) !== 'undefined' && IcarusThemeSettings.article.highlight.clipboard) {
|
||
|
$('figure.highlight').each(function () {
|
||
|
var id = 'code-' + Date.now() + (Math.random() * 1000 | 0);
|
||
|
var button = '<a href="javascript:;" class="copy" title="Copy" data-clipboard-target="#' + id + ' .code"><i class="fas fa-copy"></i></a>';
|
||
|
$(this).attr('id', id);
|
||
|
if ($(this).find('figcaption').length) {
|
||
|
$(this).find('figcaption').prepend(button);
|
||
|
} else {
|
||
|
$(this).prepend('<figcaption>' + button + '</figcaption>');
|
||
|
}
|
||
|
});
|
||
|
new ClipboardJS('.highlight .copy');
|
||
|
}
|
||
|
var fold = IcarusThemeSettings.article.highlight.fold;
|
||
|
if (fold.trim()) {
|
||
|
var button = '<span class="fold">' + (fold === 'unfolded' ? '<i class="fas fa-angle-down"></i>' : '<i class="fas fa-angle-right"></i>') + '</span>';
|
||
|
$('figure.highlight').each(function () {
|
||
|
if ($(this).find('figcaption').length) {
|
||
|
$(this).find('figcaption').prepend(button);
|
||
|
} else {
|
||
|
$(this).prepend('<figcaption>' + button + '</figcaption>');
|
||
|
}
|
||
|
});
|
||
|
|
||
|
function toggleFold(codeBlock, isFolded) {
|
||
|
var $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');
|
||
|
}
|
||
|
|
||
|
$('figure.highlight').each(function () {
|
||
|
toggleFold(this, fold === 'folded');
|
||
|
});
|
||
|
$('figure.highlight figcaption .fold').click(function () {
|
||
|
var $code = $(this).closest('figure.highlight');
|
||
|
toggleFold($code.eq(0), !$code.hasClass('folded'));
|
||
|
});
|
||
|
}
|
||
|
}
|
||
|
|
||
|
var $toc = $('#toc');
|
||
|
if ($toc.length > 0) {
|
||
|
var $mask = $('<div>');
|
||
|
$mask.attr('id', 'toc-mask');
|
||
|
|
||
|
$('body').append($mask);
|
||
|
|
||
|
function toggleToc() {
|
||
|
$toc.toggleClass('is-active');
|
||
|
$mask.toggleClass('is-active');
|
||
|
}
|
||
|
|
||
|
$toc.on('click', toggleToc);
|
||
|
$mask.on('click', toggleToc);
|
||
|
$('.navbar-main .catalogue').on('click', toggleToc);
|
||
|
}
|
||
|
})(jQuery);
|