UNPKG

1.59 kBJavaScriptView Raw
1function hideAllButCurrent(){
2 //by default all submenut items are hidden
3 //but we need to rehide them for search
4 document.querySelectorAll("nav > ul").forEach(function(parent) {
5 if (parent.className.indexOf("collapse_top") !== -1) {
6 parent.style.display = "none";
7 }
8 });
9 document.querySelectorAll("nav > ul > li > ul li").forEach(function(parent) {
10 parent.style.display = "none";
11 });
12 document.querySelectorAll("nav > h3").forEach(function(section) {
13 if (section.className.indexOf("collapsed_header") !== -1) {
14 section.addEventListener("click", function(){
15 if (section.nextSibling.style.display === "none") {
16 section.nextSibling.style.display = "block";
17 } else {
18 section.nextSibling.style.display = "none";
19 }
20 });
21 }
22 });
23
24 //only current page (if it exists) should be opened
25 var file = window.location.pathname.split("/").pop().replace(/\.html/, '');
26 document.querySelectorAll("nav > ul > li > a").forEach(function(parent) {
27 var href = parent.attributes.href.value.replace(/\.html/, '');
28 if (file === href) {
29 if (parent.parentNode.parentNode.className.indexOf("collapse_top") !== -1) {
30 parent.parentNode.parentNode.style.display = "block";
31 }
32 parent.parentNode.querySelectorAll("ul li").forEach(function(elem) {
33 elem.style.display = "block";
34 });
35 }
36 });
37}
38
39hideAllButCurrent();
\No newline at end of file