|
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"); |
|
|
|
|
|
|
28
|
|
|
fontStyle = "Consolas"; |
|
|
|
|
|
|
29
|
|
|
fontSize = "14px"; |
|
|
|
|
|
|
30
|
|
|
bgColor = "#FDF6E3"; |
|
|
|
|
|
|
31
|
|
|
intColor = "#657A81"; |
|
|
|
|
|
|
32
|
|
|
strColor = "#2AA198"; |
|
|
|
|
|
|
33
|
|
|
keyColor = "#B58900"; |
|
|
|
|
|
|
34
|
|
|
defaultColor = "#586E75"; |
|
|
|
|
|
|
35
|
|
|
|
|
36
|
|
|
strictOnly = false; |
|
|
|
|
|
|
37
|
|
|
hideDetails = false; |
|
|
|
|
|
|
38
|
|
|
dontBeatify = false; |
|
|
|
|
|
|
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); |
|
|
|
|
|
|
69
|
|
|
var target = e.target; |
|
70
|
|
|
if (target.tagName.toUpperCase() == "I") { |
|
71
|
|
|
var isClose = target.classList.contains(COLL); |
|
|
|
|
|
|
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; |
|
|
|
|
|
|
99
|
|
|
|
|
100
|
|
|
var fadeDiv = document.createElement("div"); |
|
|
|
|
|
|
101
|
|
|
fadeDiv.setAttribute("id", "fade"); |
|
102
|
|
|
fadeDiv.classList.add("black_overlay"); |
|
103
|
|
|
document.body.appendChild(fadeDiv); |
|
104
|
|
|
|
|
105
|
|
|
var lightDiv = document.createElement("div"); |
|
|
|
|
|
|
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); |
|
|
|
|
|
|
113
|
|
|
} else if (target.classList.contains("black_overlay")) { |
|
114
|
|
|
var fadeDiv = document.getElementById("fade"); |
|
|
|
|
|
|
115
|
|
|
fadeDiv.parentElement.removeChild(fadeDiv); |
|
116
|
|
|
var lightDiv = document.getElementById("light"); |
|
|
|
|
|
|
117
|
|
|
lightDiv.parentElement.removeChild(lightDiv); |
|
118
|
|
|
} |
|
119
|
|
|
}, true); |
|
120
|
|
|
} |
|
121
|
|
|
|
|
122
|
|
|
|