2021-01-25 10:08:52 +08:00
|
|
|
/* global KEEP */
|
|
|
|
|
2020-12-30 18:11:46 +08:00
|
|
|
function initLeftSideToggle() {
|
2020-11-20 12:02:22 +08:00
|
|
|
KEEP.utils.leftSideToggle = {
|
2021-01-25 10:08:52 +08:00
|
|
|
toggleBar: document.querySelector('.page-aside-toggle'),
|
|
|
|
pageTopDom: document.querySelector('.page-main-content-top'),
|
|
|
|
containerDom: document.querySelector('.page-container'),
|
|
|
|
leftAsideDom: document.querySelector('.page-aside'),
|
|
|
|
toggleBarIcon: document.querySelector('.page-aside-toggle i'),
|
|
|
|
|
|
|
|
isOpenPageAside: false,
|
2020-10-21 19:36:38 +08:00
|
|
|
|
|
|
|
initToggleBarButton() {
|
2022-09-30 11:40:30 +08:00
|
|
|
this.toggleBar &&
|
|
|
|
this.toggleBar.addEventListener('click', () => {
|
|
|
|
this.isOpenPageAside = !this.isOpenPageAside
|
|
|
|
KEEP.styleStatus.isOpenPageAside = this.isOpenPageAside
|
|
|
|
KEEP.setStyleStatus()
|
|
|
|
this.changePageLayoutWhenOpenToggle(this.isOpenPageAside)
|
|
|
|
})
|
2020-10-21 19:36:38 +08:00
|
|
|
},
|
|
|
|
|
|
|
|
changePageLayoutWhenOpenToggle(isOpen) {
|
2022-09-30 11:40:30 +08:00
|
|
|
this.toggleBarIcon &&
|
|
|
|
(this.toggleBarIcon.className = isOpen ? 'fas fa-outdent' : 'fas fa-indent')
|
|
|
|
const pageAsideWidth = KEEP.theme_config.style.left_side_width || '260px'
|
|
|
|
this.containerDom.style.paddingLeft = isOpen ? pageAsideWidth : '0'
|
|
|
|
this.pageTopDom.style.paddingLeft = isOpen ? pageAsideWidth : '0'
|
|
|
|
this.leftAsideDom.style.left = isOpen ? '0' : `-${pageAsideWidth}`
|
2020-10-21 19:36:38 +08:00
|
|
|
},
|
2021-01-25 10:08:52 +08:00
|
|
|
|
|
|
|
pageAsideHandleOfTOC(isOpen) {
|
2022-09-30 11:40:30 +08:00
|
|
|
this.toggleBar.style.display = 'flex'
|
|
|
|
this.isOpenPageAside = isOpen
|
|
|
|
this.changePageLayoutWhenOpenToggle(isOpen)
|
2021-01-25 10:08:52 +08:00
|
|
|
}
|
2020-10-21 19:36:38 +08:00
|
|
|
}
|
2022-09-30 11:40:30 +08:00
|
|
|
KEEP.utils.leftSideToggle.initToggleBarButton()
|
2020-12-30 18:11:46 +08:00
|
|
|
}
|
2020-10-21 19:36:38 +08:00
|
|
|
|
2021-01-25 10:08:52 +08:00
|
|
|
if (KEEP.theme_config.pjax.enable === true && KEEP.utils) {
|
2022-09-30 11:40:30 +08:00
|
|
|
initLeftSideToggle()
|
2020-12-30 18:11:46 +08:00
|
|
|
} else {
|
2022-09-30 11:40:30 +08:00
|
|
|
window.addEventListener('DOMContentLoaded', initLeftSideToggle)
|
2020-12-30 18:11:46 +08:00
|
|
|
}
|