Cleanup the Javascript and CSS of our custom TOC

This commit is contained in:
Urgau 2025-04-21 17:18:22 +02:00
parent 72f915aaca
commit 4cbcb44d70
2 changed files with 3 additions and 15 deletions

View file

@ -10,14 +10,6 @@
min-width: 50px;
}
.previous {
/*
adjust the space between the left sidebar or the left side of the screen
and the button that leads to the previous page
*/
margin-left: var(--page-padding);
}
@media only screen {
@media (max-width: 1179px) {
.sidebar-hidden #sidetoc {

View file

@ -71,7 +71,8 @@ function updatePageToc(elem = undefined) {
}
}
if (document.getElementById("sidetoc") === null) {
if (document.getElementById("sidetoc") === null &&
document.getElementsByClassName("header").length > 0) {
// The sidetoc element doesn't exist yet, let's create it
// Create the empty sidetoc and pagetoc elements
@ -80,16 +81,11 @@ if (document.getElementById("sidetoc") === null) {
sidetoc.id = "sidetoc";
pagetoc.id = "pagetoc";
sidetoc.appendChild(pagetoc);
// And append them to the current DOM
const main = document.querySelector('main');
main.insertBefore(sidetoc, main.firstChild);
}
if (document.getElementsByClassName("header").length <= 1) {
// There's one or less headings, we don't need a page table of contents
document.getElementById("sidetoc").remove();
} else {
// Populate sidebar on load
window.addEventListener("load", () => {
for (const header of document.getElementsByClassName("header")) {