jclyo1 commited on
Commit
4cd3d2e
1 Parent(s): 08ce3fb

Revert "clean up"

Browse files

This reverts commit 08ce3fb67bfdcd5f8a3f22ccbdcd169e6ef3e1da.

static/index.html CHANGED
@@ -7,6 +7,7 @@
7
  <link rel="stylesheet" href="style.css" />
8
  <link rel="stylesheet" href="json_viewer.css" />
9
  <script src="https://unpkg.com/@peculiar/x509"></script>
 
10
  <script type="module" src="script.js"></script>
11
  <script
12
  type="module"
 
7
  <link rel="stylesheet" href="style.css" />
8
  <link rel="stylesheet" href="json_viewer.css" />
9
  <script src="https://unpkg.com/@peculiar/x509"></script>
10
+ <script type="text/javascript" src="json_viewer.js"></script>
11
  <script type="module" src="script.js"></script>
12
  <script
13
  type="module"
static/json_viewer.css ADDED
@@ -0,0 +1,69 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ .json-viewer {
2
+ color: #000;
3
+ padding-left: 20px;
4
+ }
5
+
6
+ .json-viewer ul {
7
+ list-style-type: none;
8
+ margin: 0;
9
+ margin: 0 0 0 1px;
10
+ border-left: 1px dotted #ccc;
11
+ padding-left: 2em;
12
+ }
13
+
14
+ .json-viewer .hide {
15
+ display: none;
16
+ }
17
+
18
+ .json-viewer .type-string {
19
+ color: #0B7500;
20
+ }
21
+
22
+ .json-viewer .type-date {
23
+ color: #CB7500;
24
+ }
25
+
26
+ .json-viewer .type-boolean {
27
+ color: #1A01CC;
28
+ font-weight: bold;
29
+ }
30
+
31
+ .json-viewer .type-number {
32
+ color: #1A01CC;
33
+ }
34
+
35
+ .json-viewer .type-null, .json-viewer .type-undefined {
36
+ color: #90a;
37
+ }
38
+
39
+ .json-viewer a.list-link {
40
+ color: #000;
41
+ text-decoration: none;
42
+ position: relative;
43
+ }
44
+
45
+ .json-viewer a.list-link:before {
46
+ color: #aaa;
47
+ content: "\25BC";
48
+ position: absolute;
49
+ display: inline-block;
50
+ width: 1em;
51
+ left: -1em;
52
+ }
53
+
54
+ .json-viewer a.list-link.collapsed:before {
55
+ content: "\25B6";
56
+ }
57
+
58
+ .json-viewer a.list-link.empty:before {
59
+ content: "";
60
+ }
61
+
62
+ .json-viewer .items-ph {
63
+ color: #aaa;
64
+ padding: 0 1em;
65
+ }
66
+
67
+ .json-viewer .items-ph:hover {
68
+ text-decoration: underline;
69
+ }
static/json_viewer.js ADDED
@@ -0,0 +1,269 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /**
2
+ * JSONViewer - by Roman Makudera 2016 (c) MIT licence.
3
+ */
4
+ var JSONViewer = (function(document) {
5
+ var Object_prototype_toString = ({}).toString;
6
+ var DatePrototypeAsString = Object_prototype_toString.call(new Date);
7
+
8
+ /** @constructor */
9
+ function JSONViewer() {
10
+ this._dom_container = document.createElement("pre");
11
+ this._dom_container.classList.add("json-viewer");
12
+ };
13
+
14
+ /**
15
+ * Visualise JSON object.
16
+ *
17
+ * @param {Object|Array} json Input value
18
+ * @param {Number} [inputMaxLvl] Process only to max level, where 0..n, -1 unlimited
19
+ * @param {Number} [inputColAt] Collapse at level, where 0..n, -1 unlimited
20
+ */
21
+ JSONViewer.prototype.showJSON = function(jsonValue, inputMaxLvl, inputColAt) {
22
+ // Process only to maxLvl, where 0..n, -1 unlimited
23
+ var maxLvl = typeof inputMaxLvl === "number" ? inputMaxLvl : -1; // max level
24
+ // Collapse at level colAt, where 0..n, -1 unlimited
25
+ var colAt = typeof inputColAt === "number" ? inputColAt : -1; // collapse at
26
+
27
+ this._dom_container.innerHTML = "";
28
+ walkJSONTree(this._dom_container, jsonValue, maxLvl, colAt, 0);
29
+ };
30
+
31
+ /**
32
+ * Get container with pre object - this container is used for visualise JSON data.
33
+ *
34
+ * @return {Element}
35
+ */
36
+ JSONViewer.prototype.getContainer = function() {
37
+ return this._dom_container;
38
+ };
39
+
40
+ /**
41
+ * Recursive walk for input value.
42
+ *
43
+ * @param {Element} outputParent is the Element that will contain the new DOM
44
+ * @param {Object|Array} value Input value
45
+ * @param {Number} maxLvl Process only to max level, where 0..n, -1 unlimited
46
+ * @param {Number} colAt Collapse at level, where 0..n, -1 unlimited
47
+ * @param {Number} lvl Current level
48
+ */
49
+ function walkJSONTree(outputParent, value, maxLvl, colAt, lvl) {
50
+ var isDate = Object_prototype_toString.call(value) === DatePrototypeAsString;
51
+ var realValue = !isDate && typeof value === "object" && value !== null && "toJSON" in value ? value.toJSON() : value;
52
+ if (typeof realValue === "object" && realValue !== null && !isDate) {
53
+ var isMaxLvl = maxLvl >= 0 && lvl >= maxLvl;
54
+ var isCollapse = colAt >= 0 && lvl >= colAt;
55
+
56
+ var isArray = Array.isArray(realValue);
57
+ var items = isArray ? realValue : Object.keys(realValue);
58
+
59
+ if (lvl === 0) {
60
+ // root level
61
+ var rootCount = _createItemsCount(items.length);
62
+ // hide/show
63
+ var rootLink = _createLink(isArray ? "[" : "{");
64
+
65
+ if (items.length) {
66
+ rootLink.addEventListener("click", function() {
67
+ if (isMaxLvl) return;
68
+
69
+ rootLink.classList.toggle("collapsed");
70
+ rootCount.classList.toggle("hide");
71
+
72
+ // main list
73
+ outputParent.querySelector("ul").classList.toggle("hide");
74
+ });
75
+
76
+ if (isCollapse) {
77
+ rootLink.classList.add("collapsed");
78
+ rootCount.classList.remove("hide");
79
+ }
80
+ }
81
+ else {
82
+ rootLink.classList.add("empty");
83
+ }
84
+
85
+ rootLink.appendChild(rootCount);
86
+ outputParent.appendChild(rootLink); // output the rootLink
87
+ }
88
+
89
+ if (items.length && !isMaxLvl) {
90
+ var len = items.length - 1;
91
+ var ulList = document.createElement("ul");
92
+ ulList.setAttribute("data-level", lvl);
93
+ ulList.classList.add("type-" + (isArray ? "array" : "object"));
94
+
95
+ items.forEach(function(key, ind) {
96
+ var item = isArray ? key : value[key];
97
+ var li = document.createElement("li");
98
+
99
+ if (typeof item === "object") {
100
+ // null && date
101
+ if (!item || item instanceof Date) {
102
+ li.appendChild(document.createTextNode(isArray ? "" : key + ": "));
103
+ li.appendChild(createSimpleViewOf(item ? item : null, true));
104
+ }
105
+ // array & object
106
+ else {
107
+ var itemIsArray = Array.isArray(item);
108
+ var itemLen = itemIsArray ? item.length : Object.keys(item).length;
109
+
110
+ // empty
111
+ if (!itemLen) {
112
+ li.appendChild(document.createTextNode(key + ": " + (itemIsArray ? "[]" : "{}")));
113
+ }
114
+ else {
115
+ // 1+ items
116
+ var itemTitle = (typeof key === "string" ? key + ": " : "") + (itemIsArray ? "[" : "{");
117
+ var itemLink = _createLink(itemTitle);
118
+ var itemsCount = _createItemsCount(itemLen);
119
+
120
+ // maxLvl - only text, no link
121
+ if (maxLvl >= 0 && lvl + 1 >= maxLvl) {
122
+ li.appendChild(document.createTextNode(itemTitle));
123
+ }
124
+ else {
125
+ itemLink.appendChild(itemsCount);
126
+ li.appendChild(itemLink);
127
+ }
128
+
129
+ walkJSONTree(li, item, maxLvl, colAt, lvl + 1);
130
+ li.appendChild(document.createTextNode(itemIsArray ? "]" : "}"));
131
+
132
+ var list = li.querySelector("ul");
133
+ var itemLinkCb = function() {
134
+ itemLink.classList.toggle("collapsed");
135
+ itemsCount.classList.toggle("hide");
136
+ list.classList.toggle("hide");
137
+ };
138
+
139
+ // hide/show
140
+ itemLink.addEventListener("click", itemLinkCb);
141
+
142
+ // collapse lower level
143
+ if (colAt >= 0 && lvl + 1 >= colAt) {
144
+ itemLinkCb();
145
+ }
146
+ }
147
+ }
148
+ }
149
+ // simple values
150
+ else {
151
+ // object keys with key:
152
+ if (!isArray) {
153
+ li.appendChild(document.createTextNode(key + ": "));
154
+ }
155
+
156
+ // recursive
157
+ walkJSONTree(li, item, maxLvl, colAt, lvl + 1);
158
+ }
159
+
160
+ // add comma to the end
161
+ if (ind < len) {
162
+ li.appendChild(document.createTextNode(","));
163
+ }
164
+
165
+ ulList.appendChild(li);
166
+ }, this);
167
+
168
+ outputParent.appendChild(ulList); // output ulList
169
+ }
170
+ else if (items.length && isMaxLvl) {
171
+ var itemsCount = _createItemsCount(items.length);
172
+ itemsCount.classList.remove("hide");
173
+
174
+ outputParent.appendChild(itemsCount); // output itemsCount
175
+ }
176
+
177
+ if (lvl === 0) {
178
+ // empty root
179
+ if (!items.length) {
180
+ var itemsCount = _createItemsCount(0);
181
+ itemsCount.classList.remove("hide");
182
+
183
+ outputParent.appendChild(itemsCount); // output itemsCount
184
+ }
185
+
186
+ // root cover
187
+ outputParent.appendChild(document.createTextNode(isArray ? "]" : "}"));
188
+
189
+ // collapse
190
+ if (isCollapse) {
191
+ outputParent.querySelector("ul").classList.add("hide");
192
+ }
193
+ }
194
+ } else {
195
+ // simple values
196
+ outputParent.appendChild( createSimpleViewOf(value, isDate) );
197
+ }
198
+ };
199
+
200
+ /**
201
+ * Create simple value (no object|array).
202
+ *
203
+ * @param {Number|String|null|undefined|Date} value Input value
204
+ * @return {Element}
205
+ */
206
+ function createSimpleViewOf(value, isDate) {
207
+ var spanEl = document.createElement("span");
208
+ var type = typeof value;
209
+ var asText = "" + value;
210
+
211
+ if (type === "string") {
212
+ asText = '"' + value + '"';
213
+ } else if (value === null) {
214
+ type = "null";
215
+ //asText = "null";
216
+ } else if (isDate) {
217
+ type = "date";
218
+ asText = value.toLocaleString();
219
+ }
220
+
221
+ spanEl.className = "type-" + type;
222
+ spanEl.textContent = asText;
223
+
224
+ return spanEl;
225
+ };
226
+
227
+ /**
228
+ * Create items count element.
229
+ *
230
+ * @param {Number} count Items count
231
+ * @return {Element}
232
+ */
233
+ function _createItemsCount(count) {
234
+ var itemsCount = document.createElement("span");
235
+ itemsCount.className = "items-ph hide";
236
+ itemsCount.innerHTML = _getItemsTitle(count);
237
+
238
+ return itemsCount;
239
+ };
240
+
241
+ /**
242
+ * Create clickable link.
243
+ *
244
+ * @param {String} title Link title
245
+ * @return {Element}
246
+ */
247
+ function _createLink(title) {
248
+ var linkEl = document.createElement("a");
249
+ linkEl.classList.add("list-link");
250
+ linkEl.href = "javascript:void(0)";
251
+ linkEl.innerHTML = title || "";
252
+
253
+ return linkEl;
254
+ };
255
+
256
+ /**
257
+ * Get correct item|s title for count.
258
+ *
259
+ * @param {Number} count Items count
260
+ * @return {String}
261
+ */
262
+ function _getItemsTitle(count) {
263
+ var itemsTxt = count > 1 || count === 0 ? "items" : "item";
264
+
265
+ return (count + " " + itemsTxt);
266
+ };
267
+
268
+ return JSONViewer;
269
+ })(document);
static/script.js CHANGED
@@ -134,6 +134,7 @@ function setCertificateOutput(manifestStore = null) {
134
 
135
  certificates.forEach((certificate, index) => {
136
  var li = document.createElement("li");
 
137
  li.appendChild(document.createTextNode(certificate.transformed.commonName));
138
  li.addEventListener("click", function (e) {
139
  setCertificate(index);
 
134
 
135
  certificates.forEach((certificate, index) => {
136
  var li = document.createElement("li");
137
+ if (index == 0) li.classList.add('active');
138
  li.appendChild(document.createTextNode(certificate.transformed.commonName));
139
  li.addEventListener("click", function (e) {
140
  setCertificate(index);