Completed
Push — master ( c8749b...21bf41 )
by Dongxin
32s
created

cument.addEventListener(ꞌclickꞌ)   B

Complexity

Conditions 8
Paths 9

Size

Total Lines 53

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 8
c 0
b 0
f 0
nc 9
nop 1
dl 0
loc 53
rs 7.1199

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
// Copyright © 2017 Tangdongxin
2
3
// Permission is hereby granted, free of charge, to any person obtaining
4
// a copy of this software and associated documentation files (the "Software"),
5
// to deal in the Software without restriction, including without limitation
6
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
7
// and/or sell copies of the Software, and to permit persons to whom the
8
// Software is furnished to do so, subject to the following conditions:
9
10
// The above copyright notice and this permission notice shall be included
11
// in all copies or substantial portions of the Software.
12
13
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
14
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
15
// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
16
// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
17
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
18
// TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
19
// OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
20
21
22
// ===========================================
23
// READ CONFIG
24
// ===========================================
25
function onConfig(result) {
26
    if (!result) {
27
        console.log("No Config find");
0 ignored issues
show
Debugging Code introduced by
console.log looks like debug code. Are you sure you do not want to remove it?
Loading history...
28
        fontStyle    = "Consolas";
0 ignored issues
show
Bug introduced by
The variable fontStyle seems to be never declared. Assigning variables without defining them first makes them global. If this was intended, consider making it explicit like using window.fontStyle.
Loading history...
29
        fontSize     = "14px";
0 ignored issues
show
Bug introduced by
The variable fontSize seems to be never declared. Assigning variables without defining them first makes them global. If this was intended, consider making it explicit like using window.fontSize.
Loading history...
30
        bgColor      = "#FDF6E3";
0 ignored issues
show
Bug introduced by
The variable bgColor seems to be never declared. Assigning variables without defining them first makes them global. If this was intended, consider making it explicit like using window.bgColor.
Loading history...
31
        intColor     = "#657A81";
0 ignored issues
show
Bug introduced by
The variable intColor seems to be never declared. Assigning variables without defining them first makes them global. If this was intended, consider making it explicit like using window.intColor.
Loading history...
32
        strColor     = "#2AA198";
0 ignored issues
show
Bug introduced by
The variable strColor seems to be never declared. Assigning variables without defining them first makes them global. If this was intended, consider making it explicit like using window.strColor.
Loading history...
33
        keyColor     = "#B58900";
0 ignored issues
show
Bug introduced by
The variable keyColor seems to be never declared. Assigning variables without defining them first makes them global. If this was intended, consider making it explicit like using window.keyColor.
Loading history...
34
        defaultColor = "#586E75";
0 ignored issues
show
Bug introduced by
The variable defaultColor seems to be never declared. Assigning variables without defining them first makes them global. If this was intended, consider making it explicit like using window.defaultColor.
Loading history...
35
36
        strictOnly   = false;
0 ignored issues
show
Bug introduced by
The variable strictOnly seems to be never declared. Assigning variables without defining them first makes them global. If this was intended, consider making it explicit like using window.strictOnly.
Loading history...
37
        hideDetails  = false;
0 ignored issues
show
Bug introduced by
The variable hideDetails seems to be never declared. Assigning variables without defining them first makes them global. If this was intended, consider making it explicit like using window.hideDetails.
Loading history...
38
        dontBeatify  = false;
0 ignored issues
show
Bug introduced by
The variable dontBeatify seems to be never declared. Assigning variables without defining them first makes them global. If this was intended, consider making it explicit like using window.dontBeatify.
Loading history...
39
        return;
40
    }
41
    if (result && result[0]) {
42
        fontStyle    = result[0].fontStyle    || "Consolas";
43
        fontSize     = result[0].fontSize     || "14px";
44
        bgColor      = result[0].bgColor      || "#FDF6E3";
45
        intColor     = result[0].intColor     || "#657A81";
46
        strColor     = result[0].strColor     || "#2AA198";
47
        keyColor     = result[0].keyColor     || "#B58900";
48
        defaultColor = result[0].defaultColor || "#586E75";
49
50
        strictOnly   = result[0].strictOnly   || false;
51
        hideDetails  = result[0].hideDetails  || false;
52
        dontBeatify  = result[0].dontBeatify  || false;
53
    } else {
54
        fontStyle    = result.fontStyle       || "Consolas";
55
        fontSize     = result.fontSize        || "14px";
56
        bgColor      = result.bgColor         || "#FDF6E3";
57
        intColor     = result.intColor        || "#657A81";
58
        strColor     = result.strColor        || "#2AA198";
59
        keyColor     = result.keyColor        || "#B58900";
60
        defaultColor = result.defaultColor    || "#586E75";
61
62
        strictOnly   = result.strictOnly      || false;
63
        hideDetails  = result.hideDetails     || false;
64
        dontBeatify  = result.dontBeatify     || false;
65
    }
66
67
    document.addEventListener("click", function(e) {
68
        console.log(e);
0 ignored issues
show
Debugging Code introduced by
console.log looks like debug code. Are you sure you do not want to remove it?
Loading history...
69
        var target = e.target;
70
        if (target.tagName.toUpperCase() == "I") {
71
            var isClose = target.classList.contains(COLL);
0 ignored issues
show
Bug introduced by
The variable COLL seems to be never declared. If this is a global, consider adding a /** global: COLL */ 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...
72
            console.log(isClose);
73
            var classname = target.classList[0];
74
            console.log(classname);
75
            if (isClose) {
76
                target.removeAttribute("class");
77
                target.setAttribute("class", classname);
78
            } else {
79
                target.removeAttribute("class");
80
                target.setAttribute("class", classname + " C" + classname.substring(1));
81
            }
82
            e.preventDefault();
83
        } else if (target.tagName.toUpperCase() == "STR") {
84
            var parentElement = target.parentElement;
85
            var originStr = parentElement.innerHTML;
86
            parentElement.innerHTML = parentElement.getAttribute("content");
87
            parentElement.setAttribute("content", originStr);
88
        } else if (target.tagName.toUpperCase() == "JSON") {
89
            if (document.getElementById("light")) {
90
                var lightDiv = document.getElementById("light");
91
                lightDiv.parentElement.removeChild(lightDiv);
92
            }
93
            if (document.getElementById("fade")) {
94
                var fadeDiv = document.getElementById("fade");
95
                fadeDiv.parentElement.removeChild(fadeDiv);
96
            }
97
98
            var parentElement = target.parentElement;
0 ignored issues
show
Comprehensibility Naming Best Practice introduced by
The variable parentElement already seems to be declared on line 84. Consider using another variable name or omitting the var keyword.

This check looks for variables that are declared in multiple lines. There may be several reasons for this.

In the simplest case the variable name was reused by mistake. This may lead to very hard to locate bugs.

If you want to reuse a variable for another purpose, consider declaring it at or near the top of your function and just assigning to it subsequently so it is always declared.

Loading history...
99
100
            var fadeDiv = document.createElement("div");
0 ignored issues
show
Comprehensibility Naming Best Practice introduced by
The variable fadeDiv already seems to be declared on line 94. Consider using another variable name or omitting the var keyword.

This check looks for variables that are declared in multiple lines. There may be several reasons for this.

In the simplest case the variable name was reused by mistake. This may lead to very hard to locate bugs.

If you want to reuse a variable for another purpose, consider declaring it at or near the top of your function and just assigning to it subsequently so it is always declared.

Loading history...
101
            fadeDiv.setAttribute("id", "fade");
102
            fadeDiv.classList.add("black_overlay");
103
            document.body.appendChild(fadeDiv);
104
105
            var lightDiv = document.createElement("div");
0 ignored issues
show
Comprehensibility Naming Best Practice introduced by
The variable lightDiv already seems to be declared on line 90. Consider using another variable name or omitting the var keyword.

This check looks for variables that are declared in multiple lines. There may be several reasons for this.

In the simplest case the variable name was reused by mistake. This may lead to very hard to locate bugs.

If you want to reuse a variable for another purpose, consider declaring it at or near the top of your function and just assigning to it subsequently so it is always declared.

Loading history...
106
            lightDiv.setAttribute("id", "light");
107
            lightDiv.classList.add("white_content");
108
            document.body.appendChild(lightDiv);
109
110
            document.getElementById('light').style.display = 'block';
111
            document.getElementById('fade').style.display = 'block';
112
            draw(eval(parentElement.getAttribute("json")), lightDiv);
0 ignored issues
show
Security Performance introduced by
Calls to eval are slow and potentially dangerous, especially on untrusted code. Please consider whether there is another way to achieve your goal.
Loading history...
113
        } else if (target.classList.contains("black_overlay")) {
114
            var fadeDiv = document.getElementById("fade");
0 ignored issues
show
Comprehensibility Naming Best Practice introduced by
The variable fadeDiv already seems to be declared on line 94. Consider using another variable name or omitting the var keyword.

This check looks for variables that are declared in multiple lines. There may be several reasons for this.

In the simplest case the variable name was reused by mistake. This may lead to very hard to locate bugs.

If you want to reuse a variable for another purpose, consider declaring it at or near the top of your function and just assigning to it subsequently so it is always declared.

Loading history...
115
            fadeDiv.parentElement.removeChild(fadeDiv);
116
            var lightDiv = document.getElementById("light");
0 ignored issues
show
Comprehensibility Naming Best Practice introduced by
The variable lightDiv already seems to be declared on line 90. Consider using another variable name or omitting the var keyword.

This check looks for variables that are declared in multiple lines. There may be several reasons for this.

In the simplest case the variable name was reused by mistake. This may lead to very hard to locate bugs.

If you want to reuse a variable for another purpose, consider declaring it at or near the top of your function and just assigning to it subsequently so it is always declared.

Loading history...
117
            lightDiv.parentElement.removeChild(lightDiv);
118
        }
119
    }, true);
120
}
121
122