Add condition for left sidebar's existence

This commit is contained in:
Helen Chong 2023-08-29 13:41:45 +08:00
parent edef108656
commit d6b90271b8
1 changed files with 12 additions and 1 deletions

View File

@ -47,13 +47,24 @@ window.addEventListener('DOMContentLoaded', (event) => {
}
tocOl.append(tocFragment);
toc.append(tocOl);
const tocClone = tocOl.cloneNode(true);
tocSidebar.appendChild(tocClone);
if (tocSidebar) {
tocSidebar.appendChild(tocClone);
}
} else {
toc.classList.add('hidden');
leftSidebar.classList.add('hidden');
}
// Close article ToC accordion and the left sidebar for small screen sizes
if (window.innerWidth < 480) {
toc.removeAttribute("open");
leftSidebar.classList.add("hidden");
} else {
toc.setAttribute("open", true);
}
// Remove the stickiness of the sidebar ToC if it is larger than screen height
function preventSidebarOverflow() {
if (document.documentElement.clientHeight < tocSidebar.offsetHeight + 50) {