2022-10-11 12:37:06 +08:00
|
|
|
/* global KEEP */
|
|
|
|
|
|
|
|
function initToggleShowToc() {
|
|
|
|
KEEP.utils.toggleShowTocHandler = {
|
|
|
|
postPageContainerDom: document.querySelector('.post-page-container'),
|
|
|
|
toggleShowTocBtnDom: document.querySelector('.toggle-show-toc'),
|
|
|
|
toggleShowTocIcon: document.querySelector('.toggle-show-toc i'),
|
|
|
|
isShowToc: false,
|
|
|
|
|
|
|
|
initToggle() {
|
|
|
|
this.toggleShowTocBtnDom &&
|
2022-10-11 12:42:11 +08:00
|
|
|
this.toggleShowTocBtnDom.addEventListener('click', () => {
|
|
|
|
this.isShowToc = !this.isShowToc
|
|
|
|
KEEP.styleStatus.isShowToc = this.isShowToc
|
|
|
|
KEEP.setStyleStatus()
|
|
|
|
this.handleToggle(this.isShowToc)
|
|
|
|
})
|
2022-10-11 12:37:06 +08:00
|
|
|
},
|
|
|
|
|
|
|
|
handleToggle(isOpen) {
|
|
|
|
if (isOpen) {
|
|
|
|
this.postPageContainerDom.classList.add('show-toc')
|
2022-10-11 23:05:45 +08:00
|
|
|
document.body.classList.add('has-toc')
|
2022-10-11 12:37:06 +08:00
|
|
|
} else {
|
|
|
|
this.postPageContainerDom.classList.remove('show-toc')
|
2022-10-11 23:05:45 +08:00
|
|
|
document.body.classList.remove('has-toc')
|
2022-10-11 12:37:06 +08:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
hasToc(isOpen) {
|
|
|
|
this.toggleShowTocBtnDom.style.display = 'flex'
|
|
|
|
this.isShowToc = isOpen
|
|
|
|
this.handleToggle(isOpen)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
KEEP.utils.toggleShowTocHandler.initToggle()
|
|
|
|
}
|
|
|
|
|
|
|
|
if (KEEP.theme_config.pjax.enable === true && KEEP.utils) {
|
|
|
|
initToggleShowToc()
|
|
|
|
} else {
|
|
|
|
window.addEventListener('DOMContentLoaded', initToggleShowToc)
|
|
|
|
}
|