nexusframework 0.3.0-beta.73 → 0.3.0-beta.74
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE.md +55 -55
- package/README.md +12 -12
- package/about/index.json +5 -5
- package/about/index.nhp +4 -4
- package/icon.png +0 -0
- package/index.d.ts +0 -2
- package/index.js +0 -0
- package/index.js.map +1 -1
- package/index.ts +101 -101
- package/indexOfSkeleton.nhp +133 -133
- package/legacySkeleton.nhp +22 -22
- package/loader/overlay.css +1 -1
- package/loader/overlay.html +25 -25
- package/loader/overlay.scss +152 -152
- package/package.json +102 -90
- package/scripts/es5/compat.js +100 -100
- package/scripts/es5/compat.min.js +1 -1
- package/scripts/es5/loader.js +0 -0
- package/scripts/es5/loader.js.map +0 -0
- package/scripts/es5/loader.min.js +1 -1
- package/scripts/es5/loader.min.js.map +0 -0
- package/scripts/es5/nexusframeworkclient.js +1224 -1224
- package/scripts/es5/nexusframeworkclient.js.map +0 -0
- package/scripts/es5/nexusframeworkclient.min.js +1 -1
- package/scripts/es5/nexusframeworkclient.min.js.map +0 -0
- package/scripts/es6/compat.js +64 -64
- package/scripts/es6/compat.min.js +1 -1
- package/scripts/es6/loader.js +0 -0
- package/scripts/es6/loader.js.map +0 -0
- package/scripts/es6/loader.min.js +1 -1
- package/scripts/es6/loader.min.js.map +0 -0
- package/scripts/es6/nexusframeworkclient.js +1146 -1146
- package/scripts/es6/nexusframeworkclient.js.map +0 -0
- package/scripts/es6/nexusframeworkclient.min.js +1 -1
- package/scripts/es6/nexusframeworkclient.min.js.map +0 -0
- package/scripts/index.d.ts +259 -259
- package/scripts/src/compat.ts +62 -62
- package/scripts/src/loader.ts +385 -385
- package/scripts/src/nexusframeworkclient.ts +1163 -1163
- package/scripts/tsconfig.json +11 -11
- package/src/cli.d.ts +1 -0
- package/src/cli.js +102 -102
- package/src/cli.js.map +1 -1
- package/src/cli.ts +101 -101
- package/src/compileScripts.d.ts +0 -0
- package/src/compileScripts.js +0 -0
- package/src/compileScripts.js.map +1 -1
- package/src/compileScripts.ts +153 -153
- package/src/nexusframework.d.ts +5 -5
- package/src/nexusframework.js +44 -37
- package/src/nexusframework.js.map +1 -1
- package/src/nexusframework.ts +3631 -3622
- package/templates/basic/package.json +3 -3
- package/templates/basic/www/skeleton.nhp +1 -1
- package/templates/bootstrap/package.json +2 -2
- package/templates/bootstrap/www/skeleton.nhp +1 -1
- package/templates/bootstrap-material-design/package.json +2 -2
- package/templates/bootstrap-material-design/www/skeleton.nhp +1 -1
- package/tsconfig.json +25 -22
- package/types.d.ts +612 -612
package/scripts/src/loader.ts
CHANGED
|
@@ -1,385 +1,385 @@
|
|
|
1
|
-
/// <reference path="../index.d.ts" />
|
|
2
|
-
(function(w) {
|
|
3
|
-
const d = window.document;
|
|
4
|
-
const r = d.createElement("a");
|
|
5
|
-
const protocol = location.href.match(/^\w+:/)[0];
|
|
6
|
-
const resolveUrl = function(url: string) {
|
|
7
|
-
r.setAttribute("href", url);
|
|
8
|
-
var href = r.href;
|
|
9
|
-
if (/^\/\//.test(href))
|
|
10
|
-
href = protocol + href;
|
|
11
|
-
return href;
|
|
12
|
-
}
|
|
13
|
-
const rmClass = function(elements: HTMLCollection, visibleClass: string) {
|
|
14
|
-
var element: Element;
|
|
15
|
-
const classRegex = new RegExp("(^|\\s+)" + (visibleClass as string).replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, "\\$&") + "(\\s+|$)", "g");
|
|
16
|
-
for(var i=0; i<elements.length; i++) {
|
|
17
|
-
element = elements[i];
|
|
18
|
-
element.className = element.className.replace(classRegex, function(match, p1) {
|
|
19
|
-
return /^\s.+\s$/.test(match) ? " " : "";
|
|
20
|
-
});
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
const addClass = function(elements: HTMLCollection, visibleClass: boolean | string) {
|
|
24
|
-
var element: Element;
|
|
25
|
-
const classRegex = new RegExp("(^|\\s+)" + (visibleClass as string).replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, "\\$&") + "(\\s+|$)", "g");
|
|
26
|
-
for(var i=0; i<elements.length; i++) {
|
|
27
|
-
element = elements[i];
|
|
28
|
-
if (!classRegex.test(element.className))
|
|
29
|
-
element.className = (element.className ? element.className + " " : "") + visibleClass;
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
var errorShowed = false;
|
|
34
|
-
const errorFade = "loader-error-visible";
|
|
35
|
-
const errorContainerArray: HTMLElement | HTMLCollection = errorFade ? d.getElementsByClassName("loader-error-container") : undefined;
|
|
36
|
-
const errorMessageArray: HTMLElement | HTMLCollection = d.getElementsByClassName("loader-error-message");
|
|
37
|
-
const showError = function(err: Error): HTMLElement | HTMLCollection{
|
|
38
|
-
const messageAndStack = "" + (err.stack || err);
|
|
39
|
-
console.warn(messageAndStack);
|
|
40
|
-
if(errorShowed)
|
|
41
|
-
return errorContainerArray;
|
|
42
|
-
errorShowed = true;
|
|
43
|
-
if (errorMessageArray.length) {
|
|
44
|
-
const replacements: {[index: string]: string} = {
|
|
45
|
-
'&': '&',
|
|
46
|
-
'<': '<',
|
|
47
|
-
'>': '>',
|
|
48
|
-
'"': '"',
|
|
49
|
-
"'": ''',
|
|
50
|
-
'`': '`',
|
|
51
|
-
'/': '/',
|
|
52
|
-
'=': '=',
|
|
53
|
-
' ': " ",
|
|
54
|
-
'\n': "<br />"
|
|
55
|
-
};
|
|
56
|
-
const html = messageAndStack.replace(/([&<>"'`=\/\n]| )/g, function (s) {
|
|
57
|
-
return replacements[s];
|
|
58
|
-
});
|
|
59
|
-
for(var i=0; i<errorMessageArray.length; i++)
|
|
60
|
-
errorMessageArray[i].innerHTML = html;
|
|
61
|
-
|
|
62
|
-
if(w.ga)
|
|
63
|
-
try {
|
|
64
|
-
w.ga('send', 'exception', {
|
|
65
|
-
'exDescription': messageAndStack,
|
|
66
|
-
'exFatal': true
|
|
67
|
-
});
|
|
68
|
-
} catch(e) {
|
|
69
|
-
console.warn(e);
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
if(errorFade && errorContainerArray.length)
|
|
73
|
-
addClass(errorContainerArray, errorFade);
|
|
74
|
-
}
|
|
75
|
-
return errorContainerArray;
|
|
76
|
-
};
|
|
77
|
-
try {
|
|
78
|
-
var resetProgress: Function, incrementProgress: Function;
|
|
79
|
-
var progressBar = d.getElementsByClassName("loader-progress-bar");
|
|
80
|
-
var progressBarContainer = d.getElementsByClassName("loader-progress-container");
|
|
81
|
-
if(progressBar.length) {
|
|
82
|
-
let totalScripts = 0, loadedScripts = 0;
|
|
83
|
-
incrementProgress = function(oncomplete?) {
|
|
84
|
-
var prog: number | string;
|
|
85
|
-
if(++loadedScripts >= totalScripts) {
|
|
86
|
-
if (oncomplete)
|
|
87
|
-
oncomplete();
|
|
88
|
-
else if (progressBarContainer)
|
|
89
|
-
rmClass(progressBarContainer, "loader-progress-visible");
|
|
90
|
-
document.body.style.overflow = "auto";
|
|
91
|
-
prog = 1;
|
|
92
|
-
} else
|
|
93
|
-
prog = 1-Math.pow(5, 1-(loadedScripts / totalScripts))/5;
|
|
94
|
-
prog = (prog*100) + "%";
|
|
95
|
-
for (var i = 0; i < progressBar.length; i++)
|
|
96
|
-
progressBar[i]['style'] && (progressBar[i]['style'].width = prog);
|
|
97
|
-
};
|
|
98
|
-
resetProgress = function(by = 1) {
|
|
99
|
-
totalScripts = by;
|
|
100
|
-
loadedScripts = 0;
|
|
101
|
-
}
|
|
102
|
-
} else if(progressBarContainer.length) {
|
|
103
|
-
let totalScripts = 0, loadedScripts = 0;
|
|
104
|
-
incrementProgress = function(oncomplete?) {
|
|
105
|
-
if(++loadedScripts >= totalScripts) {
|
|
106
|
-
if (oncomplete)
|
|
107
|
-
oncomplete();
|
|
108
|
-
else
|
|
109
|
-
rmClass(progressBarContainer, "loader-progress-visible");
|
|
110
|
-
}
|
|
111
|
-
};
|
|
112
|
-
resetProgress = function(by = 1) {
|
|
113
|
-
totalScripts = by;
|
|
114
|
-
loadedScripts = 0;
|
|
115
|
-
}
|
|
116
|
-
} else {
|
|
117
|
-
let totalScripts = 0, loadedScripts = 0;
|
|
118
|
-
incrementProgress = function(oncomplete?) {
|
|
119
|
-
if(++loadedScripts >= totalScripts && oncomplete)
|
|
120
|
-
oncomplete();
|
|
121
|
-
};
|
|
122
|
-
resetProgress = function(by = 1) {
|
|
123
|
-
totalScripts = by;
|
|
124
|
-
loadedScripts = 0;
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
|
-
if (progressBarContainer)
|
|
128
|
-
addClass(progressBarContainer, "loader-progress-visible");
|
|
129
|
-
document.body.style.overflow = "hidden";
|
|
130
|
-
/**
|
|
131
|
-
* https://stackoverflow.com/questions/3728798/running-javascript-downloaded-with-xmlhttprequest/35247060#answer-31275143
|
|
132
|
-
*/
|
|
133
|
-
const base64 = function(data: string) {
|
|
134
|
-
try {
|
|
135
|
-
return btoa(data);
|
|
136
|
-
} catch (e) {
|
|
137
|
-
// script file may contain characters that not included in Latin1
|
|
138
|
-
var symbols = data.split('');
|
|
139
|
-
for (var i = 0, l = symbols.length; i < l; i++) {
|
|
140
|
-
var symbol = symbols[i];
|
|
141
|
-
// here we are trying to find these symbols in catch branch
|
|
142
|
-
try {
|
|
143
|
-
btoa(symbol);
|
|
144
|
-
} catch (e) {
|
|
145
|
-
var code = symbol.charCodeAt(0).toString(16);
|
|
146
|
-
while (code.length < 4) {
|
|
147
|
-
code = '0' + code;
|
|
148
|
-
}
|
|
149
|
-
// replace original symbol to unicode character
|
|
150
|
-
symbols[i] = '\\u' + code;
|
|
151
|
-
}
|
|
152
|
-
}
|
|
153
|
-
// create new base64 string from string with replaced characters
|
|
154
|
-
return btoa(symbols.join(''));
|
|
155
|
-
}
|
|
156
|
-
}
|
|
157
|
-
const padLeft = function(data: string, count = 8, using = "0") {
|
|
158
|
-
while (data.length < count)
|
|
159
|
-
data = using + data;
|
|
160
|
-
return data;
|
|
161
|
-
}
|
|
162
|
-
const stringHash = function(data: string) {
|
|
163
|
-
if (data.length === 0) return "00000000";
|
|
164
|
-
var hash = 0;
|
|
165
|
-
for (var i = 0; i < data.length; i++)
|
|
166
|
-
hash = (((hash << 5) - hash) + data.charCodeAt(i)) | 0;
|
|
167
|
-
return padLeft(hash.toString(16));
|
|
168
|
-
};
|
|
169
|
-
var initialVersions: string[];
|
|
170
|
-
const loadCallbacks: {[index: string]: Function[]} = {};
|
|
171
|
-
const resourceSources: {[index: string]: string} = {};
|
|
172
|
-
const NexusFrameworkLoaderImpl = {
|
|
173
|
-
load(data: NexusFrameworkLoaderData, oncomplete?: () => void) {
|
|
174
|
-
if (initialVersions) {
|
|
175
|
-
const versions = data[0];
|
|
176
|
-
const len = versions.length;
|
|
177
|
-
if (len !== initialVersions.length)
|
|
178
|
-
return location.reload(true);
|
|
179
|
-
for (var i=0; i<len; i++)
|
|
180
|
-
if (versions[i] !== initialVersions[i])
|
|
181
|
-
return location.reload(true);
|
|
182
|
-
} else
|
|
183
|
-
initialVersions = data[0];
|
|
184
|
-
const resources = data[1];
|
|
185
|
-
if (resources.length) {
|
|
186
|
-
resetProgress(resources.length);
|
|
187
|
-
resources.forEach(function(resource) {
|
|
188
|
-
NexusFrameworkLoaderImpl.loadResource(resource.type, resource.source, function(err) {
|
|
189
|
-
if(err) {
|
|
190
|
-
console.log(err);
|
|
191
|
-
NexusFrameworkLoaderImpl.showError(err);
|
|
192
|
-
} else
|
|
193
|
-
incrementProgress(oncomplete);
|
|
194
|
-
}, resource.dependencies, resource.inline || resource.integrity, resource.name);
|
|
195
|
-
});
|
|
196
|
-
} else if(oncomplete)
|
|
197
|
-
oncomplete();
|
|
198
|
-
else {
|
|
199
|
-
resetProgress();
|
|
200
|
-
incrementProgress(oncomplete);
|
|
201
|
-
}
|
|
202
|
-
},
|
|
203
|
-
requestedResources() {
|
|
204
|
-
return Object.keys(resourceSources);
|
|
205
|
-
},
|
|
206
|
-
resourceSource(key: string) {
|
|
207
|
-
return resourceSources[key];
|
|
208
|
-
},
|
|
209
|
-
loadResource(type: string, source: string, cb: (err?: Error) => void, deps: string[] = [], inlineOrIntegrity?: boolean | string, name?: string) {
|
|
210
|
-
try {
|
|
211
|
-
var processResource: (data: string) => void, callCallbacks: (err?: Error) => void;
|
|
212
|
-
var contentType: string;
|
|
213
|
-
if(type == "script") {
|
|
214
|
-
contentType = "text/javascript";
|
|
215
|
-
processResource = function(url) {
|
|
216
|
-
const scriptel = d.createElement('script');
|
|
217
|
-
scriptel.type = "text/javascript";
|
|
218
|
-
if (inlineOrIntegrity && inlineOrIntegrity !== true)
|
|
219
|
-
scriptel.integrity = inlineOrIntegrity;
|
|
220
|
-
scriptel.async = true;
|
|
221
|
-
scriptel.onload = function() {
|
|
222
|
-
callCallbacks();
|
|
223
|
-
};
|
|
224
|
-
scriptel.onerror = function() {
|
|
225
|
-
callCallbacks(new Error("Failed to load resource: " + source));
|
|
226
|
-
};
|
|
227
|
-
scriptel.src = url;
|
|
228
|
-
d.body.appendChild(scriptel);
|
|
229
|
-
}
|
|
230
|
-
} else if(type == "style") {
|
|
231
|
-
contentType = "text/css";
|
|
232
|
-
processResource = function(url) {
|
|
233
|
-
const linkel = d.createElement('link');
|
|
234
|
-
linkel.type = "text/css";
|
|
235
|
-
linkel.rel = "stylesheet";
|
|
236
|
-
if (inlineOrIntegrity && inlineOrIntegrity !== true)
|
|
237
|
-
linkel.integrity = inlineOrIntegrity;
|
|
238
|
-
linkel.onload = function() {
|
|
239
|
-
callCallbacks();
|
|
240
|
-
};
|
|
241
|
-
linkel.onerror = function() {
|
|
242
|
-
callCallbacks(new Error("Failed to load resource: " + source));
|
|
243
|
-
};
|
|
244
|
-
linkel.href = url;
|
|
245
|
-
d.body.appendChild(linkel);
|
|
246
|
-
}
|
|
247
|
-
} else
|
|
248
|
-
throw new Error("Unknown type: " + type);
|
|
249
|
-
|
|
250
|
-
var errored = false;
|
|
251
|
-
const onLoad = function(err?: Error) {
|
|
252
|
-
if(errored)
|
|
253
|
-
return;
|
|
254
|
-
if(err) {
|
|
255
|
-
errored = true;
|
|
256
|
-
cb(err);
|
|
257
|
-
} else
|
|
258
|
-
cb();
|
|
259
|
-
};
|
|
260
|
-
var url: string;
|
|
261
|
-
if (inlineOrIntegrity !== true)
|
|
262
|
-
url = source = resolveUrl(source);
|
|
263
|
-
if (!name) {
|
|
264
|
-
if(inlineOrIntegrity === true) {
|
|
265
|
-
name = "inline-" + stringHash(source);
|
|
266
|
-
} else {
|
|
267
|
-
name = source;
|
|
268
|
-
var index = name.lastIndexOf("/");
|
|
269
|
-
if(index > -1)
|
|
270
|
-
name = name.substring(index+1);
|
|
271
|
-
var match = name.match(/^(([a-z][a-z0-9]*[\-_\.]?)+)\.(css|js)(\?.*)?$/i);
|
|
272
|
-
if(match)
|
|
273
|
-
name = match[1];
|
|
274
|
-
else
|
|
275
|
-
name = name.replace(/\.(css|js)(\?.*)?$/i, "");
|
|
276
|
-
if(/\.min$/.test(name))
|
|
277
|
-
name = name.substring(0, name.length-4);
|
|
278
|
-
if(/\.slim$/.test(name))
|
|
279
|
-
name = name.substring(0, name.length-5);
|
|
280
|
-
if(/\.umd$/.test(name))
|
|
281
|
-
name = name.substring(0, name.length-4);
|
|
282
|
-
match = name.match(/^(.+)\-\d+([\.\-]\d)*$/);
|
|
283
|
-
if (match)
|
|
284
|
-
name = match[1];
|
|
285
|
-
}
|
|
286
|
-
}
|
|
287
|
-
const key = type + ":" + name;
|
|
288
|
-
|
|
289
|
-
var callbacks = loadCallbacks[key];
|
|
290
|
-
if(callbacks)
|
|
291
|
-
return callbacks.push(onLoad);
|
|
292
|
-
|
|
293
|
-
callCallbacks = function(err?: Error) {
|
|
294
|
-
callbacks.forEach(function(cb) {
|
|
295
|
-
cb(err);
|
|
296
|
-
});
|
|
297
|
-
if (inlineOrIntegrity === true && type === "script")
|
|
298
|
-
delete loadCallbacks[key];
|
|
299
|
-
else
|
|
300
|
-
loadCallbacks[key] = {push: function(cb: Function) {
|
|
301
|
-
cb(err);
|
|
302
|
-
}} as any;
|
|
303
|
-
}
|
|
304
|
-
|
|
305
|
-
callbacks = loadCallbacks[key] = [onLoad];
|
|
306
|
-
if(inlineOrIntegrity !== true && source.indexOf("/") == -1)
|
|
307
|
-
return callCallbacks(new Error(type[0].toUpperCase() + type.substring(1) + " `" + name + "` is required, but not included."));
|
|
308
|
-
|
|
309
|
-
if (deps.length) {
|
|
310
|
-
var toLoad = deps.length;
|
|
311
|
-
deps.forEach(function(dep) {
|
|
312
|
-
NexusFrameworkLoaderImpl.loadResource(type, dep, function(err?: Error) {
|
|
313
|
-
if(err)
|
|
314
|
-
callCallbacks(err);
|
|
315
|
-
else if(!--toLoad) {
|
|
316
|
-
resourceSources[key] = source;
|
|
317
|
-
if(inlineOrIntegrity === true)
|
|
318
|
-
processResource('data:'+contentType+';base64,' + base64(source));
|
|
319
|
-
else
|
|
320
|
-
processResource(source);
|
|
321
|
-
}
|
|
322
|
-
});
|
|
323
|
-
});
|
|
324
|
-
} else if(inlineOrIntegrity === true)
|
|
325
|
-
processResource('data:'+contentType+';base64,' + base64(source));
|
|
326
|
-
else
|
|
327
|
-
processResource(source);
|
|
328
|
-
} catch(e) {
|
|
329
|
-
console.warn(e);
|
|
330
|
-
cb(e);
|
|
331
|
-
}
|
|
332
|
-
}
|
|
333
|
-
} as NexusFrameworkLoader;
|
|
334
|
-
NexusFrameworkLoaderImpl.resetError = function() {
|
|
335
|
-
if(errorFade && errorContainerArray.length)
|
|
336
|
-
rmClass(errorContainerArray, errorFade);
|
|
337
|
-
errorShowed = false;
|
|
338
|
-
};
|
|
339
|
-
NexusFrameworkLoaderImpl.showError = function(err) {
|
|
340
|
-
errorShowed = false;
|
|
341
|
-
return showError(err);
|
|
342
|
-
};
|
|
343
|
-
var messageVisible: boolean, progressTimeout: number;
|
|
344
|
-
NexusFrameworkLoaderImpl.showProgress = function(cb?: () => void, title?: string, message?: string) {
|
|
345
|
-
if (progressBarContainer) {
|
|
346
|
-
addClass(progressBarContainer, "loader-progress-visible");
|
|
347
|
-
if (message) {
|
|
348
|
-
Array.prototype.forEach.call(progressBarContainer, function(container) {
|
|
349
|
-
const cont = container.querySelector(".loader-progress-message-container");
|
|
350
|
-
cont.querySelector("h5").innerHTML = title;
|
|
351
|
-
cont.querySelector("p").innerHTML = message;
|
|
352
|
-
});
|
|
353
|
-
addClass(progressBarContainer, "loader-progress-message-visible");
|
|
354
|
-
messageVisible = true;
|
|
355
|
-
} else if(messageVisible) {
|
|
356
|
-
rmClass(progressBarContainer, "loader-progress-message-visible");
|
|
357
|
-
messageVisible = undefined;
|
|
358
|
-
}
|
|
359
|
-
if (cb) {
|
|
360
|
-
try {clearTimeout(progressTimeout)}catch(e){}
|
|
361
|
-
progressTimeout = setTimeout(cb, 200) as any;
|
|
362
|
-
}
|
|
363
|
-
} else if (cb)
|
|
364
|
-
cb();
|
|
365
|
-
document.body.style.overflow = "hidden";
|
|
366
|
-
return progressBarContainer;
|
|
367
|
-
};
|
|
368
|
-
NexusFrameworkLoaderImpl.resetProgress = function() {
|
|
369
|
-
if (progressBarContainer) {
|
|
370
|
-
try {clearTimeout(progressTimeout)}catch(e){}
|
|
371
|
-
rmClass(progressBarContainer, "loader-progress-visible");
|
|
372
|
-
if (messageVisible) {
|
|
373
|
-
rmClass(progressBarContainer, "loader-progress-message-visible");
|
|
374
|
-
messageVisible = undefined;
|
|
375
|
-
}
|
|
376
|
-
}
|
|
377
|
-
document.body.style.overflow = "auto";
|
|
378
|
-
};
|
|
379
|
-
Object.defineProperty(w, "NexusFrameworkLoader", {
|
|
380
|
-
value: NexusFrameworkLoaderImpl
|
|
381
|
-
});
|
|
382
|
-
} catch(e) {
|
|
383
|
-
showError(e);
|
|
384
|
-
}
|
|
385
|
-
})(window);
|
|
1
|
+
/// <reference path="../index.d.ts" />
|
|
2
|
+
(function(w) {
|
|
3
|
+
const d = window.document;
|
|
4
|
+
const r = d.createElement("a");
|
|
5
|
+
const protocol = location.href.match(/^\w+:/)[0];
|
|
6
|
+
const resolveUrl = function(url: string) {
|
|
7
|
+
r.setAttribute("href", url);
|
|
8
|
+
var href = r.href;
|
|
9
|
+
if (/^\/\//.test(href))
|
|
10
|
+
href = protocol + href;
|
|
11
|
+
return href;
|
|
12
|
+
}
|
|
13
|
+
const rmClass = function(elements: HTMLCollection, visibleClass: string) {
|
|
14
|
+
var element: Element;
|
|
15
|
+
const classRegex = new RegExp("(^|\\s+)" + (visibleClass as string).replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, "\\$&") + "(\\s+|$)", "g");
|
|
16
|
+
for(var i=0; i<elements.length; i++) {
|
|
17
|
+
element = elements[i];
|
|
18
|
+
element.className = element.className.replace(classRegex, function(match, p1) {
|
|
19
|
+
return /^\s.+\s$/.test(match) ? " " : "";
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
const addClass = function(elements: HTMLCollection, visibleClass: boolean | string) {
|
|
24
|
+
var element: Element;
|
|
25
|
+
const classRegex = new RegExp("(^|\\s+)" + (visibleClass as string).replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, "\\$&") + "(\\s+|$)", "g");
|
|
26
|
+
for(var i=0; i<elements.length; i++) {
|
|
27
|
+
element = elements[i];
|
|
28
|
+
if (!classRegex.test(element.className))
|
|
29
|
+
element.className = (element.className ? element.className + " " : "") + visibleClass;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
var errorShowed = false;
|
|
34
|
+
const errorFade = "loader-error-visible";
|
|
35
|
+
const errorContainerArray: HTMLElement | HTMLCollection = errorFade ? d.getElementsByClassName("loader-error-container") : undefined;
|
|
36
|
+
const errorMessageArray: HTMLElement | HTMLCollection = d.getElementsByClassName("loader-error-message");
|
|
37
|
+
const showError = function(err: Error): HTMLElement | HTMLCollection{
|
|
38
|
+
const messageAndStack = "" + (err.stack || err);
|
|
39
|
+
console.warn(messageAndStack);
|
|
40
|
+
if(errorShowed)
|
|
41
|
+
return errorContainerArray;
|
|
42
|
+
errorShowed = true;
|
|
43
|
+
if (errorMessageArray.length) {
|
|
44
|
+
const replacements: {[index: string]: string} = {
|
|
45
|
+
'&': '&',
|
|
46
|
+
'<': '<',
|
|
47
|
+
'>': '>',
|
|
48
|
+
'"': '"',
|
|
49
|
+
"'": ''',
|
|
50
|
+
'`': '`',
|
|
51
|
+
'/': '/',
|
|
52
|
+
'=': '=',
|
|
53
|
+
' ': " ",
|
|
54
|
+
'\n': "<br />"
|
|
55
|
+
};
|
|
56
|
+
const html = messageAndStack.replace(/([&<>"'`=\/\n]| )/g, function (s) {
|
|
57
|
+
return replacements[s];
|
|
58
|
+
});
|
|
59
|
+
for(var i=0; i<errorMessageArray.length; i++)
|
|
60
|
+
errorMessageArray[i].innerHTML = html;
|
|
61
|
+
|
|
62
|
+
if(w.ga)
|
|
63
|
+
try {
|
|
64
|
+
w.ga('send', 'exception', {
|
|
65
|
+
'exDescription': messageAndStack,
|
|
66
|
+
'exFatal': true
|
|
67
|
+
});
|
|
68
|
+
} catch(e) {
|
|
69
|
+
console.warn(e);
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
if(errorFade && errorContainerArray.length)
|
|
73
|
+
addClass(errorContainerArray, errorFade);
|
|
74
|
+
}
|
|
75
|
+
return errorContainerArray;
|
|
76
|
+
};
|
|
77
|
+
try {
|
|
78
|
+
var resetProgress: Function, incrementProgress: Function;
|
|
79
|
+
var progressBar = d.getElementsByClassName("loader-progress-bar");
|
|
80
|
+
var progressBarContainer = d.getElementsByClassName("loader-progress-container");
|
|
81
|
+
if(progressBar.length) {
|
|
82
|
+
let totalScripts = 0, loadedScripts = 0;
|
|
83
|
+
incrementProgress = function(oncomplete?) {
|
|
84
|
+
var prog: number | string;
|
|
85
|
+
if(++loadedScripts >= totalScripts) {
|
|
86
|
+
if (oncomplete)
|
|
87
|
+
oncomplete();
|
|
88
|
+
else if (progressBarContainer)
|
|
89
|
+
rmClass(progressBarContainer, "loader-progress-visible");
|
|
90
|
+
document.body.style.overflow = "auto";
|
|
91
|
+
prog = 1;
|
|
92
|
+
} else
|
|
93
|
+
prog = 1-Math.pow(5, 1-(loadedScripts / totalScripts))/5;
|
|
94
|
+
prog = (prog*100) + "%";
|
|
95
|
+
for (var i = 0; i < progressBar.length; i++)
|
|
96
|
+
progressBar[i]['style'] && (progressBar[i]['style'].width = prog);
|
|
97
|
+
};
|
|
98
|
+
resetProgress = function(by = 1) {
|
|
99
|
+
totalScripts = by;
|
|
100
|
+
loadedScripts = 0;
|
|
101
|
+
}
|
|
102
|
+
} else if(progressBarContainer.length) {
|
|
103
|
+
let totalScripts = 0, loadedScripts = 0;
|
|
104
|
+
incrementProgress = function(oncomplete?) {
|
|
105
|
+
if(++loadedScripts >= totalScripts) {
|
|
106
|
+
if (oncomplete)
|
|
107
|
+
oncomplete();
|
|
108
|
+
else
|
|
109
|
+
rmClass(progressBarContainer, "loader-progress-visible");
|
|
110
|
+
}
|
|
111
|
+
};
|
|
112
|
+
resetProgress = function(by = 1) {
|
|
113
|
+
totalScripts = by;
|
|
114
|
+
loadedScripts = 0;
|
|
115
|
+
}
|
|
116
|
+
} else {
|
|
117
|
+
let totalScripts = 0, loadedScripts = 0;
|
|
118
|
+
incrementProgress = function(oncomplete?) {
|
|
119
|
+
if(++loadedScripts >= totalScripts && oncomplete)
|
|
120
|
+
oncomplete();
|
|
121
|
+
};
|
|
122
|
+
resetProgress = function(by = 1) {
|
|
123
|
+
totalScripts = by;
|
|
124
|
+
loadedScripts = 0;
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
if (progressBarContainer)
|
|
128
|
+
addClass(progressBarContainer, "loader-progress-visible");
|
|
129
|
+
document.body.style.overflow = "hidden";
|
|
130
|
+
/**
|
|
131
|
+
* https://stackoverflow.com/questions/3728798/running-javascript-downloaded-with-xmlhttprequest/35247060#answer-31275143
|
|
132
|
+
*/
|
|
133
|
+
const base64 = function(data: string) {
|
|
134
|
+
try {
|
|
135
|
+
return btoa(data);
|
|
136
|
+
} catch (e) {
|
|
137
|
+
// script file may contain characters that not included in Latin1
|
|
138
|
+
var symbols = data.split('');
|
|
139
|
+
for (var i = 0, l = symbols.length; i < l; i++) {
|
|
140
|
+
var symbol = symbols[i];
|
|
141
|
+
// here we are trying to find these symbols in catch branch
|
|
142
|
+
try {
|
|
143
|
+
btoa(symbol);
|
|
144
|
+
} catch (e) {
|
|
145
|
+
var code = symbol.charCodeAt(0).toString(16);
|
|
146
|
+
while (code.length < 4) {
|
|
147
|
+
code = '0' + code;
|
|
148
|
+
}
|
|
149
|
+
// replace original symbol to unicode character
|
|
150
|
+
symbols[i] = '\\u' + code;
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
// create new base64 string from string with replaced characters
|
|
154
|
+
return btoa(symbols.join(''));
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
const padLeft = function(data: string, count = 8, using = "0") {
|
|
158
|
+
while (data.length < count)
|
|
159
|
+
data = using + data;
|
|
160
|
+
return data;
|
|
161
|
+
}
|
|
162
|
+
const stringHash = function(data: string) {
|
|
163
|
+
if (data.length === 0) return "00000000";
|
|
164
|
+
var hash = 0;
|
|
165
|
+
for (var i = 0; i < data.length; i++)
|
|
166
|
+
hash = (((hash << 5) - hash) + data.charCodeAt(i)) | 0;
|
|
167
|
+
return padLeft(hash.toString(16));
|
|
168
|
+
};
|
|
169
|
+
var initialVersions: string[];
|
|
170
|
+
const loadCallbacks: {[index: string]: Function[]} = {};
|
|
171
|
+
const resourceSources: {[index: string]: string} = {};
|
|
172
|
+
const NexusFrameworkLoaderImpl = {
|
|
173
|
+
load(data: NexusFrameworkLoaderData, oncomplete?: () => void) {
|
|
174
|
+
if (initialVersions) {
|
|
175
|
+
const versions = data[0];
|
|
176
|
+
const len = versions.length;
|
|
177
|
+
if (len !== initialVersions.length)
|
|
178
|
+
return location.reload(true);
|
|
179
|
+
for (var i=0; i<len; i++)
|
|
180
|
+
if (versions[i] !== initialVersions[i])
|
|
181
|
+
return location.reload(true);
|
|
182
|
+
} else
|
|
183
|
+
initialVersions = data[0];
|
|
184
|
+
const resources = data[1];
|
|
185
|
+
if (resources.length) {
|
|
186
|
+
resetProgress(resources.length);
|
|
187
|
+
resources.forEach(function(resource) {
|
|
188
|
+
NexusFrameworkLoaderImpl.loadResource(resource.type, resource.source, function(err) {
|
|
189
|
+
if(err) {
|
|
190
|
+
console.log(err);
|
|
191
|
+
NexusFrameworkLoaderImpl.showError(err);
|
|
192
|
+
} else
|
|
193
|
+
incrementProgress(oncomplete);
|
|
194
|
+
}, resource.dependencies, resource.inline || resource.integrity, resource.name);
|
|
195
|
+
});
|
|
196
|
+
} else if(oncomplete)
|
|
197
|
+
oncomplete();
|
|
198
|
+
else {
|
|
199
|
+
resetProgress();
|
|
200
|
+
incrementProgress(oncomplete);
|
|
201
|
+
}
|
|
202
|
+
},
|
|
203
|
+
requestedResources() {
|
|
204
|
+
return Object.keys(resourceSources);
|
|
205
|
+
},
|
|
206
|
+
resourceSource(key: string) {
|
|
207
|
+
return resourceSources[key];
|
|
208
|
+
},
|
|
209
|
+
loadResource(type: string, source: string, cb: (err?: Error) => void, deps: string[] = [], inlineOrIntegrity?: boolean | string, name?: string) {
|
|
210
|
+
try {
|
|
211
|
+
var processResource: (data: string) => void, callCallbacks: (err?: Error) => void;
|
|
212
|
+
var contentType: string;
|
|
213
|
+
if(type == "script") {
|
|
214
|
+
contentType = "text/javascript";
|
|
215
|
+
processResource = function(url) {
|
|
216
|
+
const scriptel = d.createElement('script');
|
|
217
|
+
scriptel.type = "text/javascript";
|
|
218
|
+
if (inlineOrIntegrity && inlineOrIntegrity !== true)
|
|
219
|
+
scriptel.integrity = inlineOrIntegrity;
|
|
220
|
+
scriptel.async = true;
|
|
221
|
+
scriptel.onload = function() {
|
|
222
|
+
callCallbacks();
|
|
223
|
+
};
|
|
224
|
+
scriptel.onerror = function() {
|
|
225
|
+
callCallbacks(new Error("Failed to load resource: " + source));
|
|
226
|
+
};
|
|
227
|
+
scriptel.src = url;
|
|
228
|
+
d.body.appendChild(scriptel);
|
|
229
|
+
}
|
|
230
|
+
} else if(type == "style") {
|
|
231
|
+
contentType = "text/css";
|
|
232
|
+
processResource = function(url) {
|
|
233
|
+
const linkel = d.createElement('link');
|
|
234
|
+
linkel.type = "text/css";
|
|
235
|
+
linkel.rel = "stylesheet";
|
|
236
|
+
if (inlineOrIntegrity && inlineOrIntegrity !== true)
|
|
237
|
+
linkel.integrity = inlineOrIntegrity;
|
|
238
|
+
linkel.onload = function() {
|
|
239
|
+
callCallbacks();
|
|
240
|
+
};
|
|
241
|
+
linkel.onerror = function() {
|
|
242
|
+
callCallbacks(new Error("Failed to load resource: " + source));
|
|
243
|
+
};
|
|
244
|
+
linkel.href = url;
|
|
245
|
+
d.body.appendChild(linkel);
|
|
246
|
+
}
|
|
247
|
+
} else
|
|
248
|
+
throw new Error("Unknown type: " + type);
|
|
249
|
+
|
|
250
|
+
var errored = false;
|
|
251
|
+
const onLoad = function(err?: Error) {
|
|
252
|
+
if(errored)
|
|
253
|
+
return;
|
|
254
|
+
if(err) {
|
|
255
|
+
errored = true;
|
|
256
|
+
cb(err);
|
|
257
|
+
} else
|
|
258
|
+
cb();
|
|
259
|
+
};
|
|
260
|
+
var url: string;
|
|
261
|
+
if (inlineOrIntegrity !== true)
|
|
262
|
+
url = source = resolveUrl(source);
|
|
263
|
+
if (!name) {
|
|
264
|
+
if(inlineOrIntegrity === true) {
|
|
265
|
+
name = "inline-" + stringHash(source);
|
|
266
|
+
} else {
|
|
267
|
+
name = source;
|
|
268
|
+
var index = name.lastIndexOf("/");
|
|
269
|
+
if(index > -1)
|
|
270
|
+
name = name.substring(index+1);
|
|
271
|
+
var match = name.match(/^(([a-z][a-z0-9]*[\-_\.]?)+)\.(css|js)(\?.*)?$/i);
|
|
272
|
+
if(match)
|
|
273
|
+
name = match[1];
|
|
274
|
+
else
|
|
275
|
+
name = name.replace(/\.(css|js)(\?.*)?$/i, "");
|
|
276
|
+
if(/\.min$/.test(name))
|
|
277
|
+
name = name.substring(0, name.length-4);
|
|
278
|
+
if(/\.slim$/.test(name))
|
|
279
|
+
name = name.substring(0, name.length-5);
|
|
280
|
+
if(/\.umd$/.test(name))
|
|
281
|
+
name = name.substring(0, name.length-4);
|
|
282
|
+
match = name.match(/^(.+)\-\d+([\.\-]\d)*$/);
|
|
283
|
+
if (match)
|
|
284
|
+
name = match[1];
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
const key = type + ":" + name;
|
|
288
|
+
|
|
289
|
+
var callbacks = loadCallbacks[key];
|
|
290
|
+
if(callbacks)
|
|
291
|
+
return callbacks.push(onLoad);
|
|
292
|
+
|
|
293
|
+
callCallbacks = function(err?: Error) {
|
|
294
|
+
callbacks.forEach(function(cb) {
|
|
295
|
+
cb(err);
|
|
296
|
+
});
|
|
297
|
+
if (inlineOrIntegrity === true && type === "script")
|
|
298
|
+
delete loadCallbacks[key];
|
|
299
|
+
else
|
|
300
|
+
loadCallbacks[key] = {push: function(cb: Function) {
|
|
301
|
+
cb(err);
|
|
302
|
+
}} as any;
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
callbacks = loadCallbacks[key] = [onLoad];
|
|
306
|
+
if(inlineOrIntegrity !== true && source.indexOf("/") == -1)
|
|
307
|
+
return callCallbacks(new Error(type[0].toUpperCase() + type.substring(1) + " `" + name + "` is required, but not included."));
|
|
308
|
+
|
|
309
|
+
if (deps.length) {
|
|
310
|
+
var toLoad = deps.length;
|
|
311
|
+
deps.forEach(function(dep) {
|
|
312
|
+
NexusFrameworkLoaderImpl.loadResource(type, dep, function(err?: Error) {
|
|
313
|
+
if(err)
|
|
314
|
+
callCallbacks(err);
|
|
315
|
+
else if(!--toLoad) {
|
|
316
|
+
resourceSources[key] = source;
|
|
317
|
+
if(inlineOrIntegrity === true)
|
|
318
|
+
processResource('data:'+contentType+';base64,' + base64(source));
|
|
319
|
+
else
|
|
320
|
+
processResource(source);
|
|
321
|
+
}
|
|
322
|
+
});
|
|
323
|
+
});
|
|
324
|
+
} else if(inlineOrIntegrity === true)
|
|
325
|
+
processResource('data:'+contentType+';base64,' + base64(source));
|
|
326
|
+
else
|
|
327
|
+
processResource(source);
|
|
328
|
+
} catch(e) {
|
|
329
|
+
console.warn(e);
|
|
330
|
+
cb(e);
|
|
331
|
+
}
|
|
332
|
+
}
|
|
333
|
+
} as NexusFrameworkLoader;
|
|
334
|
+
NexusFrameworkLoaderImpl.resetError = function() {
|
|
335
|
+
if(errorFade && errorContainerArray.length)
|
|
336
|
+
rmClass(errorContainerArray, errorFade);
|
|
337
|
+
errorShowed = false;
|
|
338
|
+
};
|
|
339
|
+
NexusFrameworkLoaderImpl.showError = function(err) {
|
|
340
|
+
errorShowed = false;
|
|
341
|
+
return showError(err);
|
|
342
|
+
};
|
|
343
|
+
var messageVisible: boolean, progressTimeout: number;
|
|
344
|
+
NexusFrameworkLoaderImpl.showProgress = function(cb?: () => void, title?: string, message?: string) {
|
|
345
|
+
if (progressBarContainer) {
|
|
346
|
+
addClass(progressBarContainer, "loader-progress-visible");
|
|
347
|
+
if (message) {
|
|
348
|
+
Array.prototype.forEach.call(progressBarContainer, function(container) {
|
|
349
|
+
const cont = container.querySelector(".loader-progress-message-container");
|
|
350
|
+
cont.querySelector("h5").innerHTML = title;
|
|
351
|
+
cont.querySelector("p").innerHTML = message;
|
|
352
|
+
});
|
|
353
|
+
addClass(progressBarContainer, "loader-progress-message-visible");
|
|
354
|
+
messageVisible = true;
|
|
355
|
+
} else if(messageVisible) {
|
|
356
|
+
rmClass(progressBarContainer, "loader-progress-message-visible");
|
|
357
|
+
messageVisible = undefined;
|
|
358
|
+
}
|
|
359
|
+
if (cb) {
|
|
360
|
+
try {clearTimeout(progressTimeout)}catch(e){}
|
|
361
|
+
progressTimeout = setTimeout(cb, 200) as any;
|
|
362
|
+
}
|
|
363
|
+
} else if (cb)
|
|
364
|
+
cb();
|
|
365
|
+
document.body.style.overflow = "hidden";
|
|
366
|
+
return progressBarContainer;
|
|
367
|
+
};
|
|
368
|
+
NexusFrameworkLoaderImpl.resetProgress = function() {
|
|
369
|
+
if (progressBarContainer) {
|
|
370
|
+
try {clearTimeout(progressTimeout)}catch(e){}
|
|
371
|
+
rmClass(progressBarContainer, "loader-progress-visible");
|
|
372
|
+
if (messageVisible) {
|
|
373
|
+
rmClass(progressBarContainer, "loader-progress-message-visible");
|
|
374
|
+
messageVisible = undefined;
|
|
375
|
+
}
|
|
376
|
+
}
|
|
377
|
+
document.body.style.overflow = "auto";
|
|
378
|
+
};
|
|
379
|
+
Object.defineProperty(w, "NexusFrameworkLoader", {
|
|
380
|
+
value: NexusFrameworkLoaderImpl
|
|
381
|
+
});
|
|
382
|
+
} catch(e) {
|
|
383
|
+
showError(e);
|
|
384
|
+
}
|
|
385
|
+
})(window);
|