main.js 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. (function($){
  2. $('.article img:not(".not-gallery-item")').each(function () {
  3. // wrap images with link and add caption if possible
  4. if ($(this).parent('a').length === 0) {
  5. $(this).wrap('<a class="gallery-item" href="' + $(this).attr('src') + '"></a>');
  6. if (this.alt) {
  7. $(this).after('<div class="has-text-centered is-size-6 has-text-grey caption">' + this.alt + '</div>');
  8. }
  9. }
  10. });
  11. if (typeof(moment) === 'function') {
  12. $('.article-meta time').each(function () {
  13. $(this).text(moment($(this).attr('datetime')).fromNow());
  14. });
  15. }
  16. function adjustNavbar() {
  17. const navbarWidth = $('.navbar-main .navbar-start').outerWidth() + $('.navbar-main .navbar-end').outerWidth();
  18. if ($(document).outerWidth() < navbarWidth) {
  19. $('.navbar-main .navbar-menu').addClass('is-flex-start');
  20. } else {
  21. $('.navbar-main .navbar-menu').removeClass('is-flex-start');
  22. }
  23. }
  24. adjustNavbar();
  25. $(window).resize(adjustNavbar);
  26. var $toc = $('#toc');
  27. if ($toc.length > 0) {
  28. var $mask = $('<div>');
  29. $mask.attr('id', 'toc-mask');
  30. $('body').append($mask);
  31. function toggleToc() {
  32. $toc.toggleClass('is-active');
  33. $mask.toggleClass('is-active');
  34. }
  35. $toc.on('click', toggleToc);
  36. $mask.on('click', toggleToc);
  37. $('.navbar-main .catalogue').on('click', toggleToc);
  38. }
  39. })(jQuery);