hexo-theme-amane/source/js/main.js

97 lines
4.0 KiB
JavaScript
Raw Normal View History

2019-06-26 03:00:04 +00:00
(function ($) {
2018-10-16 05:28:42 +00:00
$('.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>');
2018-04-28 19:13:05 +00:00
}
}
2018-10-16 05:28:42 +00:00
});
2019-06-26 03:00:04 +00:00
if (typeof (moment) === 'function') {
2018-10-16 05:28:42 +00:00
$('.article-meta time').each(function () {
$(this).text(moment($(this).attr('datetime')).fromNow());
});
2018-10-16 05:28:42 +00:00
}
2018-10-22 04:51:51 +00:00
2019-06-26 03:00:04 +00:00
$('.article > .content > table').each(function () {
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);
$('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) {
2019-06-26 03:00:04 +00:00
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);