Passed
Push — 0.8.x ( 53eb78...43c31c )
by Alexander
17:28 queued 13:37
created

src/components/Debug/Resources/compiled/js/debug.base.js   A

Complexity

Total Complexity 19
Complexity/F 2.71

Size

Lines of Code 116
Function Count 7

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 63
dl 0
loc 116
rs 10
c 0
b 0
f 0
wmc 19
mnd 12
bc 12
fnc 7
bpm 1.7142
cpm 2.7142
noi 5

2 Functions

Rating   Name   Duplication   Size   Complexity  
D debug.base.js ➔ changeTo 0 8 12
A debug.base.js ➔ selectFrameInfo 0 10 3
1
(function(d) {
2
    /** 
3
     * CODE FOR SELECTION OF FRAMES 
4
     */
5
6
    /* IE8 Incompatibility crap */
7
    let elements = ['section', 'header', 'nav', 'footer'];
8
9
    for (let i = 0; i < elements.length; i++) {
10
        d.createElement(elements[i]);
11
    }
12
13
    /**
14
     * CODE FOR CONTROL OF ELEMENTS HTML IN THE HEADER
15
     */
16
17
    let header = d.querySelector('header');
18
    let message = d.querySelector('.time');
19
20
    message.style = "display: none";
21
    
22
    window.addEventListener('scroll', (e) => {
0 ignored issues
show
Unused Code introduced by
The parameter e is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
23
        if (d.documentElement.scrollTop > 10) {
24
            if (localStorage.getItem('dark-mode') === 'true') {
0 ignored issues
show
Bug introduced by
The variable localStorage seems to be never declared. If this is a global, consider adding a /** global: localStorage */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
25
                header.style.background = '#1F2937';
26
                header.style.borderBottom = '1px solid rgba(36, 68, 86, 0.5)';
27
                header.style.boxShadow = '0 0 15px 4px rgba(0, 0, 0, 0.2)';
28
            } else {
29
                header.style.background = '#F3F4F6';
30
                header.style.borderBottom = 'none';
31
                header.style.boxShadow = '0 0 15px 4px rgba(0, 0, 0, 0.2)';
32
            }
33
        } else {
34
            if (localStorage.getItem('dark-mode') === 'true') {
35
                header.style.background = 'none';
36
                header.style.borderBottom = '1px solid rgba(31, 41, 51, 1)';
37
                header.style.boxShadow = 'none';
38
            } else {
39
                header.style.background = 'none';
40
                header.style.borderBottom = 'none';
41
                header.style.boxShadow = 'none';
42
            }
43
        }
44
45
        if (d.documentElement.scrollTop > 150) {
46
            message.style = "display: block";
47
        } else {
48
            message.style = "display: none";
49
        }
50
51
    });
52
53
    var dropdown = d.querySelector('.dropdown');
54
    var config = d.querySelector('nav:nth-child(2) a');
55
    let evento = ((document.ontouchstart !== null) ? 'mouseup' : 'touchstart');
56
57
    config.addEventListener(evento, function (e) {
58
        if (e.target) {
59
            dropdown.classList.toggle("active");
60
        }
61
    });
62
63
    /**
64
     * CODE FOR SELECTED THE FRAMES
65
     */
66
67
    var previousFrame = null;
68
    var previousInfo  = null;
69
    var allFrames     = d.querySelectorAll('.frame');
70
    var allFramesCode = d.querySelectorAll('.code-source');
71
72
    function changeTo(el) 
73
    {
74
        if (previousInfo) previousInfo.classList.remove("active");
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
75
76
        previousInfo = el;
77
78
        el.classList.add("active");
79
    }
80
81
    function selectFrameInfo(index)
82
    {
83
        var el = allFramesCode[index];
84
85
        if (el) {
0 ignored issues
show
Complexity Best Practice introduced by
There is no return statement if el is false. Are you sure this is correct? If so, consider adding return; explicitly.

This check looks for functions where a return statement is found in some execution paths, but not in all.

Consider this little piece of code

function isBig(a) {
    if (a > 5000) {
        return "yes";
    }
}

console.log(isBig(5001)); //returns yes
console.log(isBig(42)); //returns undefined

The function isBig will only return a specific value when its parameter is bigger than 5000. In any other case, it will implicitly return undefined.

This behaviour may not be what you had intended. In any case, you can add a return undefined to the other execution path to make the return value explicit.

Loading history...
86
            if (el.closest('[data-frame]')) {
0 ignored issues
show
Complexity Best Practice introduced by
There is no return statement if el.closest("[data-frame]") is false. Are you sure this is correct? If so, consider adding return; explicitly.

This check looks for functions where a return statement is found in some execution paths, but not in all.

Consider this little piece of code

function isBig(a) {
    if (a > 5000) {
        return "yes";
    }
}

console.log(isBig(5001)); //returns yes
console.log(isBig(42)); //returns undefined

The function isBig will only return a specific value when its parameter is bigger than 5000. In any other case, it will implicitly return undefined.

This behaviour may not be what you had intended. In any case, you can add a return undefined to the other execution path to make the return value explicit.

Loading history...
87
                return changeTo(el);
88
            }
89
        }
90
    }
91
92
    for (let i = 0; i < allFrames.length; i++) {
93
        (function(i, el) {
94
            var el = allFrames[i];
95
96
            el.addEventListener(evento, (e) => {
97
                e.preventDefault();
98
99
                allFrames[0].classList.remove("active");
100
                allFramesCode[0].classList.remove("active");
101
                
102
                if (previousFrame) {
103
                    previousFrame.classList.remove("active");                    
104
                }
105
                
106
                el.classList.add("active");  
107
                      
108
                previousFrame = el;
109
                                
110
                selectFrameInfo(el.attributes["data-index"].value);
111
            });
112
113
        })(i);
114
    }
115
116
})(document);