diff --git a/scripts/events/lib/config.js b/scripts/events/lib/config.js index 9066734..17aeb4c 100644 --- a/scripts/events/lib/config.js +++ b/scripts/events/lib/config.js @@ -1,6 +1,6 @@ 'use strict'; -const merge = require('hexo-util').deepMerge || require('lodash/merge'); +const merge = require('hexo-util').deepMerge; module.exports = hexo => { const data = hexo.locals.get('data'); diff --git a/source/js/next-boot.js b/source/js/next-boot.js index 9888830..6262daa 100644 --- a/source/js/next-boot.js +++ b/source/js/next-boot.js @@ -16,32 +16,9 @@ NexT.boot.registerEvents = function() { document.body.classList.toggle('site-nav-on'); }); - const duration = 200; document.querySelectorAll('.sidebar-nav li').forEach((element, index) => { element.addEventListener('click', () => { - if (element.matches('.sidebar-toc-active .sidebar-nav-toc, .sidebar-overview-active .sidebar-nav-overview')) return; - const sidebar = document.querySelector('.sidebar-inner'); - const panel = document.querySelector('.sidebar-panel-container'); - const activeClassName = ['sidebar-toc-active', 'sidebar-overview-active']; - - window.anime({ - duration, - targets : panel, - easing : 'linear', - opacity : 0, - translateY: [0, -20], - complete : () => { - // Prevent adding TOC to Overview if Overview was selected when close & open sidebar. - sidebar.classList.replace(activeClassName[1 - index], activeClassName[index]); - window.anime({ - duration, - targets : panel, - easing : 'linear', - opacity : [0, 1], - translateY: [-20, 0] - }); - } - }); + NexT.utils.activateSidebarPanel(index); }); }); diff --git a/source/js/pjax.js b/source/js/pjax.js index 9f65a71..5126b29 100644 --- a/source/js/pjax.js +++ b/source/js/pjax.js @@ -27,6 +27,6 @@ document.addEventListener('pjax:success', () => { } const hasTOC = document.querySelector('.post-toc'); document.querySelector('.sidebar-inner').classList.toggle('sidebar-nav-active', hasTOC); - document.querySelector(hasTOC ? '.sidebar-nav-toc' : '.sidebar-nav-overview').click(); + NexT.utils.activateSidebarPanel(hasTOC ? 0 : 1); NexT.utils.updateSidebarPosition(); }); diff --git a/source/js/utils.js b/source/js/utils.js index ab207f4..76d95f6 100644 --- a/source/js/utils.js +++ b/source/js/utils.js @@ -305,6 +305,34 @@ NexT.utils = { } }, + activateSidebarPanel: function(index) { + const duration = 200; + const sidebar = document.querySelector('.sidebar-inner'); + const panel = document.querySelector('.sidebar-panel-container'); + const activeClassName = ['sidebar-toc-active', 'sidebar-overview-active']; + + if (sidebar.classList.contains(activeClassName[index])) return; + + window.anime({ + duration, + targets : panel, + easing : 'linear', + opacity : 0, + translateY: [0, -20], + complete : () => { + // Prevent adding TOC to Overview if Overview was selected when close & open sidebar. + sidebar.classList.replace(activeClassName[1 - index], activeClassName[index]); + window.anime({ + duration, + targets : panel, + easing : 'linear', + opacity : [0, 1], + translateY: [-20, 0] + }); + } + }); + }, + getScript: function(src, options = {}, legacyCondition) { if (typeof options === 'function') { return this.getScript(src, {