Skip to content

Commit

Permalink
perf: optimize TOC handle logic
Browse files Browse the repository at this point in the history
  • Loading branch information
XPoet committed Sep 20, 2023
1 parent d0eae9f commit 9403947
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 8 deletions.
9 changes: 3 additions & 6 deletions source/js/post/toc.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@ function initTOC() {
const tabletTocContainer = document.querySelector('.tablet-post-toc')

if (KEEP.utils.hasToc) {
KEEP.utils = {
...KEEP.utils,

KEEP.utils.tocHelper = {
pcTocNavSections: [],

tabletTocNavSections: [],
Expand Down Expand Up @@ -119,9 +117,8 @@ function initTOC() {
}
}
}

KEEP.utils.handleShowWhenHasToc()
KEEP.utils.registerTocNav()
KEEP.utils.tocHelper.handleShowWhenHasToc()
KEEP.utils.tocHelper.registerTocNav()
} else {
pcTocContainer && postPageContainer.removeChild(pcTocContainer)
if (tabletTocContainer) {
Expand Down
4 changes: 2 additions & 2 deletions source/js/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,8 @@ KEEP.initUtils = () => {
this.styleHandleWhenScroll()

// TOC scroll handle
if (KEEP.theme_config?.toc?.enable === true && KEEP.utils.hasOwnProperty('activeNav')) {
KEEP.utils.activeNav()
if (KEEP.theme_config?.toc?.enable === true && KEEP.utils?.tocHelper) {
KEEP.utils.tocHelper.activeNav()
}

// header shrink
Expand Down

0 comments on commit 9403947

Please sign in to comment.