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

21 lines
753 B
JavaScript
Raw Normal View History

2018-09-09 12:08:48 +00:00
function hideAllButCurrent(){
//by default all submenu items are hidden
2019-07-16 19:21:01 +00:00
//but we need to rehide them for search
document.querySelectorAll("nav > ul > li > ul li").forEach(function(parent) {
parent.style.display = "none";
});
2018-09-09 12:08:48 +00:00
//only current page (if it exists) should be opened
2019-07-16 19:21:01 +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";
});
}
});
2018-09-09 12:08:48 +00:00
}
2019-07-16 19:21:01 +00:00
hideAllButCurrent();