1
0
mirror of https://github.com/lancedikson/bowser synced 2024-10-27 20:34:22 +00:00
lancedikson_bowser/docs/scripts/collapse.js

20 lines
753 B
JavaScript
Raw Normal View History

2019-03-06 12:37:21 +00:00
function hideAllButCurrent(){
//by default all submenut items are hidden
2020-07-09 19:13:24 +00:00
//but we need to rehide them for search
document.querySelectorAll("nav > ul > li > ul li").forEach(function(parent) {
parent.style.display = "none";
});
2019-03-06 12:37:21 +00:00
//only current page (if it exists) should be opened
2020-07-09 19:13:24 +00:00
var file = window.location.pathname.split("/").pop().replace(/\.html/, '');
document.querySelectorAll("nav > ul > li > a").forEach(function(parent) {
var href = parent.attributes.href.value.replace(/\.html/, '');
if (file === href) {
parent.parentNode.querySelectorAll("ul li").forEach(function(elem) {
elem.style.display = "block";
});
}
});
2019-03-06 12:37:21 +00:00
}
2020-07-09 19:13:24 +00:00
hideAllButCurrent();