diff options
Diffstat (limited to 'plugins/base/src/main/resources/dokka/scripts/navigation-loader.js')
-rw-r--r-- | plugins/base/src/main/resources/dokka/scripts/navigation-loader.js | 44 |
1 files changed, 27 insertions, 17 deletions
diff --git a/plugins/base/src/main/resources/dokka/scripts/navigation-loader.js b/plugins/base/src/main/resources/dokka/scripts/navigation-loader.js index 0d9948ad..7b6aeb1f 100644 --- a/plugins/base/src/main/resources/dokka/scripts/navigation-loader.js +++ b/plugins/base/src/main/resources/dokka/scripts/navigation-loader.js @@ -1,31 +1,29 @@ -window.addEventListener('load', () => { - fetch(pathToRoot + "navigation.html") - .then(response => response.text()) - .then(data => { - document.getElementById("sideMenu").innerHTML = data; - }).then(() => { +navigationPageText = fetch(pathToRoot + "navigation.html").then(response => response.text()) + +displayNavigationFromPage = () => { + navigationPageText.then(data => { + document.getElementById("sideMenu").innerHTML = data; + }).then(() => { document.querySelectorAll(".overview > a").forEach(link => { link.setAttribute("href", pathToRoot + link.getAttribute("href")); }) }).then(() => { document.querySelectorAll(".sideMenuPart").forEach(nav => { - if (!nav.classList.contains("hidden")) nav.classList.add("hidden") + if (!nav.classList.contains("hidden")) + nav.classList.add("hidden") }) }).then(() => { revealNavigationForCurrentPage() }) - - /* Smooth scrolling support for going to the top of the page */ document.querySelectorAll('.footer a[href^="#"]').forEach(anchor => { anchor.addEventListener('click', function (e) { e.preventDefault(); - document.querySelector(this.getAttribute('href')).scrollIntoView({ behavior: 'smooth' }); }); }); -}) +} revealNavigationForCurrentPage = () => { let pageId = document.getElementById("content").attributes["pageIds"].value.toString(); @@ -35,9 +33,9 @@ revealNavigationForCurrentPage = () => { parts.forEach(part => { if (part.attributes['pageId'].value.indexOf(pageId) !== -1 && found === 0) { found = 1; - if (part.classList.contains("hidden")){ - part.classList.remove("hidden"); - part.setAttribute('data-active',""); + if (part.classList.contains("hidden")) { + part.classList.remove("hidden"); + part.setAttribute('data-active', ""); } revealParents(part) } @@ -45,10 +43,22 @@ revealNavigationForCurrentPage = () => { pageId = pageId.substring(0, pageId.lastIndexOf("/")) } while (pageId.indexOf("/") !== -1 && found === 0) }; - revealParents = (part) => { if (part.classList.contains("sideMenuPart")) { - if (part.classList.contains("hidden")) part.classList.remove("hidden"); + if (part.classList.contains("hidden")) + part.classList.remove("hidden"); revealParents(part.parentNode) } -};
\ No newline at end of file +}; + +/* + This is a work-around for safari being IE of our times. + It doesn't fire a DOMContentLoaded, presumabely because eventListener is added after it wants to do it +*/ +if (document.readyState == 'loading') { + window.addEventListener('DOMContentLoaded', () => { + displayNavigationFromPage() + }) +} else { + displayNavigationFromPage() +}
\ No newline at end of file |