Total Complexity | 12 |
Complexity/F | 2.4 |
Lines of Code | 67 |
Function Count | 5 |
Duplicated Lines | 0 |
Ratio | 0 % |
Changes | 0 |
1 | (function(d) |
||
2 | { |
||
3 | /* IE8 Incompatibility crap */ |
||
4 | var elements = ['section', 'header', 'footer']; |
||
5 | |||
6 | for (let i = 0; i < elements.length; i++) |
||
7 | { |
||
8 | d.createElement(elements[i]); |
||
9 | } |
||
10 | |||
11 | var previousFrame = null; |
||
12 | var previousInfo = null; |
||
13 | var allFrames = d.querySelectorAll('.frame'); |
||
14 | var allFramesCode = d.querySelectorAll('.code-source'); |
||
15 | let evento = ((document.ontouchstart !== null) ? 'mouseup' : 'touchstart'); |
||
16 | |||
17 | function changeTo(el) |
||
18 | { |
||
19 | if (previousInfo) previousInfo.classList.remove("active"); |
||
|
|||
20 | |||
21 | previousInfo = el; |
||
22 | |||
23 | el.classList.add("active"); |
||
24 | } |
||
25 | |||
26 | function selectFrameInfo(index) |
||
27 | { |
||
28 | var el = allFramesCode[index]; |
||
29 | |||
30 | if (el) |
||
31 | { |
||
32 | if (el.closest('[data-frame]')) |
||
33 | { |
||
34 | return changeTo(el); |
||
35 | } |
||
36 | } |
||
37 | } |
||
38 | |||
39 | for (let i = 0; i < allFrames.length; i++) |
||
40 | { |
||
41 | (function(i, el) |
||
42 | { |
||
43 | var el = allFrames[i]; |
||
44 | |||
45 | el.addEventListener(evento, (e) => |
||
46 | { |
||
47 | e.preventDefault(); |
||
48 | |||
49 | allFrames[0].classList.remove("active"); |
||
50 | allFramesCode[0].classList.remove("active"); |
||
51 | |||
52 | if (previousFrame) |
||
53 | { |
||
54 | previousFrame.classList.remove("active"); |
||
55 | } |
||
56 | |||
57 | el.classList.add("active"); |
||
58 | |||
59 | previousFrame = el; |
||
60 | |||
61 | selectFrameInfo(el.attributes["data-index"].value); |
||
62 | }); |
||
63 | |||
64 | })(i); |
||
65 | } |
||
66 | |||
67 | })(document); |
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 you or someone else later decides to put another statement in, only the first statement will be executed.
In this case the statement
b = 42
will always be executed, while the logging statement will be executed conditionally.ensures that the proper code will be executed conditionally no matter how many statements are added or removed.