-
Notifications
You must be signed in to change notification settings - Fork 9
/
dash.html
374 lines (357 loc) · 12.2 KB
/
dash.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
<!DOCTYPE html>
<html>
<head>
<link href="resources/css/site.css" rel="stylesheet"/>
<script src="//code.jquery.com/jquery-3.6.4.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/remarkable/1.7.1/remarkable.js"></script>
<script src="download/jsviews.js"></script>
<script src="datatypes.js"></script>
<script src="documentation/contents-categories.js"></script>
</head>
<body class="dashboard">
<div id="testHtml" style="display:none;"></div>
<h2>JsViews dashboard</h2>
<label>Allow Edit: <input type="checkbox" data-link="allowEdit" /></label>
<label>Use Storage: <input type="checkbox" data-link="useStorage" /></label>
<p><button id="save">Save to storage</button></p>
<p><button id="normalize">Normalize</button></p>
<p><button id="compile">Compile</button></p>
<a href="/">JsViews.com</a><br/>
<a href="/index.html">local JsViews.com</a>
<script>
var md = new Remarkable('full', {
html: true,
breaks: false,
linkify: true,
typographer: true
}),
testDiv = $("#testHtml")[0];
function save(categoryName) {
$.getScript("documentation/contents-" + categoryName + ".js")
.done(function() {
localStorage.setItem("JsViewsDocTopics/" + categoryName, stringify(content[categoryName]));
});
}
function normalize(categoryName) {
// Used to combine sections as paragraphs under one section. (No longer needs to be used...?)
$.getScript("documentation/contents-" + categoryName + ".js")
.done(function() {
var topic,
topics = content[categoryName];
for (topic in topics) {
combineSections(topics[topic].sections);
}
localStorage.setItem("JsViewsDocTopics/" + categoryName, stringify(content[categoryName]))
});
}
function stringify(val) {
return JSON.stringify(val, null, ' ');
}
function combineSections(sections) {
var nextSection, nextType, titleItemType, itemType, len,
titleItem = sections[0];
sections.forEach(function(section, i) {
if (section._type === "sample") {
combineSections(section.sections);
}
titleItem = section.title ? section : titleItem;
titleItemType = titleItem && titleItem._type;
nextSection = sections[i+1];
if (titleItem && titleItem === section) {
nextType = nextSection && nextSection._type;
if (nextSection && !nextSection.title && (nextType ==="para" ||nextType ==="code" ||nextType ==="data" ||nextType ==="template")) {
switch (titleItemType) {
case "code":
titleItem._type = "para";
titleItem.text = "```js\n" + titleItem.code.replace(/\n*$/, "") + "\n```";
delete titleItem.code;
break;
case "template":
titleItem._type = "para";
titleItem.text = "```jsr\n" + titleItem.markup.replace(/\n*$/, "") + "\n```";
delete titleItem.markup;
break;
case "data":
titleItem._type = "para";
titleItem.text = "```json\n" + stringify(titleItem.data).replace(/\n*$/, "") + "\n```";
delete titleItem.data;
break;
case "para":
titleItem.text = titleItem.text.replace(/\n*$/, "");
break;
default:
titleItem = nextSection;
break;
}
}
} else if (titleItem) {
itemType = section._type;
switch (itemType) {
case "code":
section._type = "delete";
titleItem.text += "\n\n```js\n" + section.code.replace(/\n*$/, "") + "\n```";
break;
case "template":
section._type = "delete";
titleItem.text += "\n\n```jsr\n" + section.markup.replace(/\n*$/, "") + "\n```";
break;
case "data":
section._type = "delete";
titleItem.text += "\n\n```json\n" + stringify(section.data).replace(/\n*$/, "") + "\n```";
break;
case "para":
section._type = "delete";
titleItem.text += "\n\n" + section.text.replace(/\n*$/, "");
break;
default:
titleItem = nextSection;
break;
}
}
});
len = sections.length;
while (len--) {
if (sections[len]._type === "delete") {
sections.splice(len, 1);
}
}
}
function compileSections(sections, sectionsSearch, scriptsToCompile) {
var searchSection, text;
sections.forEach(function(section, i) {
sectionsSearch.push(searchSection = {
_type: section._type,
title: section.title
}) ;
switch (section._type) {
case "sample":
text = section.title ? section.title + "\n" : "";
+ (section.markup ? section.markup + "\n" : "")
+ (section.html ? section.html + "\n" : "")
+ (section.data ? section.data + "\n" : "")
+ (section.code ? section.code + "\n" : "");
if (section.url) {
searchSection.url = section.url;
scriptsToCompile[section.url] = scriptsToCompile[section.url] || [];
scriptsToCompile[section.url].push(searchSection);
}
for (var ct in section.codetabs) {
scriptsToCompile[section.codetabs[ct].url] = scriptsToCompile[section.codetabs[ct].url] || [];
scriptsToCompile[section.codetabs[ct].url].push(searchSection);
}
text += section.html ? section.html + "\n": "";
text += section.code ? section.code + "\n": "";
testDiv.innerHTML = text;
searchSection.text = testDiv.textContent || testDiv.innerText;
compileSubSections(section.sections, searchSection);
break;
case "code":
testDiv.innerHTML =
(section.title ? section.title + "\n" : "")
+ (section.code ? section.code + "\n" : "");
searchSection.text = testDiv.textContent || testDiv.innerText;
break;
case "template":
testDiv.innerHTML =
(section.title ? section.title + "\n" : "")
+ (section.markup ? section.markup + "\n" : "");
searchSection.text = testDiv.textContent || testDiv.innerText;
break;
case "para":
testDiv.innerHTML =
(section.title ? section.title + "\n" : "")
+ md.render(section.text);
searchSection.text = testDiv.textContent || testDiv.innerText;
break;
case "api":
case "tag":
testDiv.innerHTML =
(section.title ? section.title + "\n" : "")
+ (section.description ? section.description + "\n" : "");
searchSection.text = testDiv.textContent || testDiv.innerText;
compileSubSections(section.signatures, searchSection);
break;
case "data":
testDiv.innerHTML =
(section.title ? section.title + "\n" : "");
searchSection.text = testDiv.textContent || testDiv.innerText;
break;
case "links":
testDiv.innerHTML =
(section.title ? section.title + "\n" : ""); // To do - iterate over labels
searchSection.text = testDiv.textContent || testDiv.innerText;
break;
}
});
}
function compileSubSections(sections, searchSection) {
var searchSection;
sections.forEach(function(section, i) {
switch (section._type) {
case "code":
testDiv.innerHTML =
(section.title ? section.title + "\n" : "");
searchSection.text += (testDiv.textContent || testDiv.innerText) + "\n";
testDiv.innerHTML =
(section.code ? section.code + "\n" : "");
searchSection.text += (testDiv.textContent || testDiv.innerText) + "\n";
break;
case "template":
testDiv.innerHTML =
(section.title ? section.title + "\n" : "");
searchSection.text += (testDiv.textContent || testDiv.innerText) + "\n";
testDiv.innerHTML =
(section.markup ? section.markup + "\n" : "");
searchSection.text += (testDiv.textContent || testDiv.innerText) + "\n";
break;
case "para":
testDiv.innerHTML =
(section.title ? section.title + "\n" : "")
+ md.render(section.text);
searchSection.text += (testDiv.textContent || testDiv.innerText) + "\n";
break;
case "signature":
testDiv.innerHTML =
(section.description ? section.description + "\n" : "");
searchSection.text += (testDiv.textContent || testDiv.innerText) + "\n";
testDiv.innerHTML =
(section.example ? section.example + "\n" : "");
searchSection.text += (testDiv.textContent || testDiv.innerText) + "\n";
break;
}
});
}
function compile(categoryName) {
var loadedPromise = new $.Deferred();
loadedPromise.nm = categoryName;
$.getScript("documentation/contents-" + categoryName + ".js")
.done(function() {
var topicName, sectionsSearch,
scriptsToCompile = {},
topics = content[categoryName],
topicsSearch = content.find[categoryName] = {};
for (topicName in topics) {
topic = topics[topicName]
topicsSearch[topicName] = {
jsr: topic.jsr,
jsv: topic.jsv,
sections: sectionsSearch = []
};
compileSections(topics[topicName].sections, sectionsSearch, scriptsToCompile);
}
compileScripts(scriptsToCompile, loadedPromise);
});
return loadedPromise.promise();
}
function compileScripts(scriptsToCompile, loadedPromise) {
function testDone(thisUrl) {
if (thisUrl) {
scriptCount--;
console.log("Cnt: " + scriptCount + " url: " + thisUrl);
}
if (!scriptCount) {
console.log("ResDeep " + loadedPromise.nm);
loadedPromise.resolve();
}
}
var url,
scriptCount = 0;
for (url in scriptsToCompile) {
scriptCount++;
(function() {
function addScriptContent(text) {
var l = scriptSections.length;
while (l--) {
scriptSections[l].text += text;
}
}
var thisUrl = url,
scriptSections = scriptsToCompile[thisUrl];
if (thisUrl.slice(-3) === ".js" || thisUrl.slice(-4) === ".txt") {
$.ajax({
url: thisUrl,
dataType: "text"
})
.done(function(text) {
addScriptContent(text + "\n");
testDone(thisUrl);
})
.fail(function() {
testDone(thisUrl);
});
} else {
$.ajax({
url: thisUrl + ".js",
dataType: "text"
})
.done(function(text) {
addScriptContent(text + "\n");
$.ajax({
url: thisUrl + ".html",
dataType: "html"
})
.done(function(text2) {
addScriptContent(/<body>\s*([\S\s]*?)\s*<!--<scrip/.exec(text2)[1] + "\n");
testDone(thisUrl);
})
.fail(function() {
testDone(thisUrl);
});
})
.fail(function() {
testDone(thisUrl);
});
}
})();
}
testDone();
}
var content = $.views.documentation.content;
content.allowEdit = localStorage.getItem("JsViewsDocTopics/allowEdit") === "true";
content.useStorage = localStorage.getItem("JsViewsDocTopics/useStorage") === "true";
$.link(true, "body", $.views.documentation.content);
$.observe(content, "allowEdit", "useStorage", function(ev, eventArgs) {
// save setting in local storage, so it will persist when we navigate to index.html
localStorage.setItem("JsViewsDocTopics/" + eventArgs.path, eventArgs.value);
})
$("#save").on("click", function() {
var categories = content.categories,
l = categories.length;
while (l-- > 1) {
save(categories[l].name);
categories[l].loadedfind = categories[l].loadingfind = undefined;
}
localStorage.setItem("JsViewsDocCategories", stringify(categories));
});
$("#normalize").on("click", function() {
var categories = content.categories,
l = categories.length;
while (l-- > 1) {
normalize(categories[l].name);
}
});
$("#compile").on("click", function() {
var categories = content.categories,
l = categories.length,
m = l-1,
compiledFindResult = {};
while (l-- > 1) {
//console.log("GO " + l + " Cat: " + name)
compile(categories[l].name).then(function() {
var name = categories[m].name;
compiledFindResult[name] = "var content = $.views.documentation.content;\n\ncontent.find." + name
+ ' = content.useStorage && $.parseJSON(localStorage.getItem("JsViewsDocTopics/find/'+ name + '")) ||\n'
+ stringify(content.find[name]);
m--;
//console.log("M " + m + " Cat: " + categories[m].name)
if (!m) {
debugger; // done.
// Take compiledFindResult properties, and copy from text visualizer into find-xxx.js files each top-level category
// If compiled content is undefined, make sure categories was not saved after doing search, and try unchecking Use Storage
}
});
}
});
</script>
</body>
</html>