next-boot.js 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  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. }), document.querySelectorAll('.sidebar-nav li').forEach(function (e, s) {
  21. e.addEventListener('click', function (e) {
  22. var t = e.currentTarget, i = 'sidebar-nav-active', o = 'sidebar-panel-active';
  23. if (!t.classList.contains(i)) {
  24. var n = document.querySelectorAll('.sidebar-panel'), a = n[s], r = n[1 - s];
  25. window.anime({
  26. targets: r,
  27. duration: 200,
  28. easing: 'linear',
  29. opacity: 0,
  30. complete: function () {
  31. r.classList.remove(o), a.style.opacity = 0, a.classList.add(o), window.anime({
  32. targets: a,
  33. duration: 200,
  34. easing: 'linear',
  35. opacity: 1
  36. });
  37. }
  38. }), [].concat(_toConsumableArray(t.parentNode.children)).forEach(function (e) {
  39. e.classList.remove(i);
  40. }), t.classList.add(i);
  41. }
  42. });
  43. }), window.addEventListener('resize', NexT.utils.initSidebarDimension), window.addEventListener('hashchange', function () {
  44. var e = location.hash;
  45. if ('' !== e && !e.match(/%\S{2}/)) {
  46. var t = document.querySelector('.tabs ul.nav-tabs li a[href="' + e + '"]');
  47. t && t.click();
  48. }
  49. });
  50. }, NexT.boot.refresh = function () {
  51. 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();
  52. }, NexT.boot.motion = function () {
  53. 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();
  54. }, window.addEventListener('DOMContentLoaded', function () {
  55. NexT.boot.registerEvents(), NexT.boot.refresh(), NexT.boot.motion();
  56. });