Passed
Push — master ( b7f732...42e110 )
by Andreas
18:16
created

static/midcom.admin.help/twisty.js   A

Complexity

Total Complexity 6
Complexity/F 2

Size

Lines of Code 42
Function Count 3

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 27
dl 0
loc 42
rs 10
c 0
b 0
f 0
wmc 6
mnd 3
bc 3
fnc 3
bpm 1
cpm 2
noi 1

3 Functions

Rating   Name   Duplication   Size   Complexity  
A twisty.js ➔ add_anchor 0 3 1
A twisty.js ➔ toggle_twisty 0 18 3
A twisty.js ➔ remove_anchor 0 17 2
1
const slide_speed = 0.4;
0 ignored issues
show
Unused Code introduced by
The constant slide_speed seems to be never used. Consider removing it.
Loading history...
2
3
function toggle_twisty(id) {
4
    var element = document.getElementById(id);
5
6
    if (!element) {
7
        return;
8
    }
9
    let twisty = element.previousSibling.previousSibling.firstChild.nextSibling;
10
    twisty.classList.toggle('fa-caret-up');
11
    twisty.classList.toggle('fa-caret-down');
12
13
    if (element.parentNode.classList.contains('open')) {
14
        remove_anchor(id);
15
    } else {
16
        add_anchor(id);
17
    }
18
    element.parentNode.classList.toggle('open')
19
    element.parentNode.classList.toggle('closed')
20
}
21
22
function remove_anchor(id) {
23
    if (!window.location.hash) {
24
        return;
25
    }
26
27
    id = id.replace(/_contents[,]*/, '');
28
29
    var string = window.location.hash,
30
        regexp = new RegExp(id, 'g');
31
    string = string.replace(regexp, '');
32
33
    string = string.replace(/#[,]*/, '#');
34
    string = string.replace(/[,]*$/, '');
35
    string = string.replace(/,,/g, ',');
36
37
    window.location.hash = string;
38
}
39
40
function add_anchor(id) {
41
    window.location.hash = '#' + id.replace(/_contents$/, '');
42
}
43