From d6b90271b87f22f6e71ed6279c5d86ad660080b6 Mon Sep 17 00:00:00 2001 From: Helen Chong <119173961+helenclx@users.noreply.github.com> Date: Tue, 29 Aug 2023 13:41:45 +0800 Subject: [PATCH] Add condition for left sidebar's existence --- js/toc.js | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/js/toc.js b/js/toc.js index 4658285b..d095f839 100644 --- a/js/toc.js +++ b/js/toc.js @@ -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) {