next-boot.js 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. 'use strict';
  2. function _toConsumableArray(e) {
  3. if (Array.isArray(e)) {
  4. for (var t = 0, i = Array(e.length); t < e.length; t++)
  5. i[t] = e[t];
  6. return i;
  7. }
  8. return Array.from(e);
  9. }
  10. NexT.boot = {}, NexT.boot.registerEvents = function () {
  11. NexT.utils.registerScrollPercent(), NexT.utils.registerCanIUseTag(), document.querySelector('.site-nav-toggle .toggle').addEventListener('click', function () {
  12. event.currentTarget.classList.toggle('toggle-close');
  13. var e = document.querySelector('.site-nav'), t = e.classList.contains('site-nav-on') ? 'slideUp' : 'slideDown';
  14. 'function' == typeof Velocity ? Velocity(e, t, {
  15. duration: 200,
  16. complete: function () {
  17. e.classList.toggle('site-nav-on');
  18. }
  19. }) : e.classList.toggle('site-nav-on');
  20. });
  21. document.querySelectorAll('.sidebar-nav li').forEach(function (e, s) {
  22. e.addEventListener('click', function (e) {
  23. var t = e.currentTarget, i = 'sidebar-nav-active', o = 'sidebar-panel-active';
  24. if (!t.classList.contains(i)) {
  25. var n = document.querySelectorAll('.sidebar-panel'), a = n[s], r = n[1 - s];
  26. window.anime({
  27. targets: r,
  28. duration: 200,
  29. easing: 'linear',
  30. opacity: 0,
  31. complete: function () {
  32. r.classList.remove(o), a.style.opacity = 0, a.classList.add(o), window.anime({
  33. targets: a,
  34. duration: 200,
  35. easing: 'linear',
  36. opacity: 1
  37. });
  38. }
  39. }), [].concat(_toConsumableArray(t.parentNode.children)).forEach(function (e) {
  40. e.classList.remove(i);
  41. }), t.classList.add(i);
  42. }
  43. });
  44. }), window.addEventListener('resize', NexT.utils.initSidebarDimension), window.addEventListener('hashchange', function () {
  45. var e = location.hash;
  46. if ('' !== e && !e.match(/%\S{2}/)) {
  47. var t = document.querySelector('.tabs ul.nav-tabs li a[href="' + e + '"]');
  48. t && t.click();
  49. }
  50. });
  51. }, NexT.boot.refresh = function () {
  52. CONFIG.fancybox && NexT.utils.wrapImageWithFancyBox(), CONFIG.mediumzoom && window.mediumZoom('.post-body :not(a) > img, .post-body > img'), CONFIG.lazyload && window.lozad('.post-body img').observe(), CONFIG.pangu && window.pangu.spacingPage(), CONFIG.exturl && NexT.utils.registerExtURL(), CONFIG.copycode.enable && NexT.utils.registerCopyCode(), NexT.utils.registerTabsTag(), NexT.utils.registerActiveMenuItem(), NexT.utils.registerLangSelect(), NexT.utils.registerSidebarTOC(), NexT.utils.wrapTableWithBox(), NexT.utils.registerVideoIframe();
  53. }, NexT.boot.motion = function () {
  54. CONFIG.motion.enable && NexT.motion.integrator.add(NexT.motion.middleWares.logo).add(NexT.motion.middleWares.menu).add(NexT.motion.middleWares.postList).add(NexT.motion.middleWares.sidebar).bootstrap(), NexT.utils.updateSidebarPosition();
  55. }, window.addEventListener('DOMContentLoaded', function () {
  56. NexT.boot.registerEvents(), NexT.boot.refresh(), NexT.boot.motion();
  57. });