diff --git a/assets/scss/custom.scss b/assets/scss/custom.scss index 7cd0046b..81ded6b5 100644 --- a/assets/scss/custom.scss +++ b/assets/scss/custom.scss @@ -524,3 +524,98 @@ nav.foldable-nav { margin: initial; } } + +// Fix some visual bugs regarding sidebar_menu_foldable / foldable-nav support +// and extend it to ordered lists +nav.foldable-nav { + .with-child ol { + list-style: none; + padding: 0; + margin: 0; + } + + .ol-1 > li { + padding-left: 1.5em; + } + + ol.foldable { + max-height: 0; + overflow: hidden; + } + + input:checked ~ ol.foldable { + max-height: 100vmax; + } + + .ol-1 .with-child > label:before { + display: inline-block; + font-family: inherit; + font-style: normal; + font-variant: normal; + text-rendering: auto; + -webkit-font-smoothing: antialiased; + font-weight: 900; content: "+"; + position: absolute; + left: 0.1em; + padding-left: 0.4em; + padding-right: 0.4em; + font-size: 1em; + color: $gray-900; + transform: unset; + transition: unset; + } + + .ol-1 .with-child > input:checked ~ label:before { + color: $gray-900; + content: "-"; + transform: unset; + transition: unset; + } + + .with-child ol { margin-top: 0.1em; } + + /* Fix bugs and annoyances with unordered lists */ + .ul-1 .with-child > label:before { + font-weight: 900; content: "+"; + font-family: inherit; + transform: unset; + transition: unset; + } + + .ul-1 .with-child > input:checked ~ label:before { + color: $gray-900; + content: "-"; + transform: unset; + transition: unset; + } + +} + +@media (hover: hover) and (pointer: fine) { + nav.foldable-nav { + + .ul-1 .with-child > label:hover:before { + color: $gray-900; + transform: unset; + transition: unset; + } + + .ul-1 .with-child > input:checked ~ label:hover:before { + color: $gray-900; + transform: unset; + transition: unset; + } + + .ol-1 .with-child > label:hover:before { + color: $gray-900; + transform: unset; + transition: unset; + } + + .ol-1 .with-child > input:checked ~ label:hover:before { + color: $gray-900; + transform: unset; + transition: unset; + } + } +} diff --git a/static/js/toc.js b/static/js/toc.js index 6386e40d..4804ef67 100644 --- a/static/js/toc.js +++ b/static/js/toc.js @@ -107,9 +107,10 @@ function makeToc() { // we have to adjust heading IDs to ensure that they are unique const nav = document.createElement("nav"); + nav.classList.add("td-sidebar-nav", "foldable-nav"); nav.id = "TableOfContents"; - const section = makeTocSection(tocTargets, 0); + const section = makeTocSection(tocTargets, 0, 1); nav.appendChild(section.content); // build the TOC and append to it title and content const toc = document.createElement("div"); @@ -130,10 +131,24 @@ function makeToc() { // create a single ToC entry function makeTocEntry(heading) { const li = document.createElement("li"); + li.classList.add("td-sidebar-nav__section-title", "td-sidebar-nav__section"); + + const input = document.createElement("input"); + input.setAttribute("id", `toc-${heading.id}-check`); + input.setAttribute("type", "checkbox"); + const label = document.createElement("label"); + label.setAttribute("for", `toc-${heading.id}-check`); + const a = document.createElement("a"); a.setAttribute("href", `#${heading.id}`); + a.setAttribute("id", `toc-${heading.id}`); + a.classList.add("td-sidebar-link", "td-sidebar-link__page"); a.textContent = heading.textContent; - li.appendChild(a); + + li.appendChild(input); + li.appendChild(label); + label.appendChild(a); + return li; } @@ -142,8 +157,9 @@ Each ToC section is an `