Skip to content

Commit

Permalink
fix(toc): fixed an error when removeChild
Browse files Browse the repository at this point in the history
  • Loading branch information
XPoet committed Sep 6, 2023
1 parent 58adea9 commit 8c004a4
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions source/js/toc.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

function initTOC() {
const pageContainer = document.querySelector('.page-container')
const postPageContainer = document.querySelector('.post-page-container')
const pcTocContainer = document.querySelector('.pc-post-toc')
const tabletTocContainer = document.querySelector('.tablet-post-toc')

Expand Down Expand Up @@ -122,12 +123,14 @@ function initTOC() {
KEEP.utils.handleShowWhenHasToc()
KEEP.utils.registerTocNav()
} else {
pcTocContainer && pageContainer.removeChild(pcTocContainer)
tabletTocContainer && pageContainer.removeChild(tabletTocContainer)
pcTocContainer && postPageContainer.removeChild(pcTocContainer)
if (tabletTocContainer) {
pageContainer.removeChild(document.querySelector('.tablet-post-toc-mask'))
}
}
}

if (KEEP.theme_config.pjax.enable === true && KEEP.utils) {
if (KEEP.theme_config?.pjax?.enable === true && KEEP.utils) {
initTOC()
} else {
window.addEventListener('DOMContentLoaded', initTOC)
Expand Down

0 comments on commit 8c004a4

Please sign in to comment.