diff --git a/assets/js/src/sidebar.js b/assets/js/src/sidebar.js index 9d827027ba..ab34d7d004 100644 --- a/assets/js/src/sidebar.js +++ b/assets/js/src/sidebar.js @@ -13,8 +13,23 @@ function scrollMenuItem() { } } +function toggleMenuItem(event) { + const section = event.currentTarget.parentElement; + const icon = section.querySelector(".icon"); + const subsection = section.querySelector("ul"); + subsection.classList.toggle("hidden"); + if (subsection.classList.contains("hidden")) { + icon.setAttribute("data-icon", "expand_more"); + } else { + icon.setAttribute("data-icon", "expand_less"); + } +} + const sectiontree = document.querySelector("#sectiontree"); const sidebar = document.querySelector("#sidebar"); if (sectiontree && sidebar) { scrollMenuItem(); + for (const button of sectiontree.querySelectorAll("button")) { + button.addEventListener("click", toggleMenuItem); + } } diff --git a/layouts/partials/sidebar.html b/layouts/partials/sidebar.html index 67f23c8ae6..8fce923c7a 100644 --- a/layouts/partials/sidebar.html +++ b/layouts/partials/sidebar.html @@ -18,14 +18,18 @@ {{ end }} {{ if $firstSection }} +{{ $allSections := slice }} +{{ range $i, $e := ($scratch.GetSortedMapValues "sections") }} +{{ $allSections = $allSections | append (index $e "title") }} +{{ end }}
-