Completed
Branch master (d2f96a)
by Rafael S.
02:27
created

docs/scripts/collapse.js   A

Complexity

Total Complexity 5
Complexity/F 1.25

Size

Lines of Code 20
Function Count 4

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
wmc 5
eloc 10
mnd 1
bc 1
fnc 4
dl 0
loc 20
rs 10
bpm 0.25
cpm 1.25
noi 0
c 0
b 0
f 0
1
function hideAllButCurrent(){
2
    //by default all submenut items are hidden
3
    //but we need to rehide them for search
4
    document.querySelectorAll("nav > ul > li > ul li").forEach(function(parent) {
5
        parent.style.display = "none";
6
    });
7
    
8
    //only current page (if it exists) should be opened
9
    var file = window.location.pathname.split("/").pop().replace(/\.html/, '');
10
    document.querySelectorAll("nav > ul > li > a").forEach(function(parent) {
11
        var href = parent.attributes.href.value.replace(/\.html/, '');
12
        if (file === href) {
13
            parent.parentNode.querySelectorAll("ul li").forEach(function(elem) {
14
                elem.style.display = "block";
15
            });
16
        }
17
    });
18
}
19
20
hideAllButCurrent();