@web-atoms/web-controls 2.4.7 → 2.4.9
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/index.js +88 -0
- package/package.json +1 -1
package/index.js
ADDED
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
(function () {
|
|
2
|
+
|
|
3
|
+
let script = document.currentScript;
|
|
4
|
+
let src = script.src;
|
|
5
|
+
let index = src.lastIndexOf("/");
|
|
6
|
+
src = src.substring(0, index);
|
|
7
|
+
|
|
8
|
+
function loadScript(url) {
|
|
9
|
+
return new Promise((resolve, reject) => {
|
|
10
|
+
var script = document.createElement("script");
|
|
11
|
+
script.type = "text/javascript";
|
|
12
|
+
script.src = url;
|
|
13
|
+
var s = script;
|
|
14
|
+
s.onerror = function (e) {
|
|
15
|
+
alert(`Script ${url} failed to load`);
|
|
16
|
+
console.error(`${url} failed to load ${e.stack || e}`);
|
|
17
|
+
reject(e);
|
|
18
|
+
};
|
|
19
|
+
s.onload = s.onreadystatechange = function () {
|
|
20
|
+
if ((s.readyState && s.readyState !== "complete" && s.readyState !== "loaded")) {
|
|
21
|
+
console.error("error loading " + url);
|
|
22
|
+
reject(`error loading ${url}`);
|
|
23
|
+
return;
|
|
24
|
+
}
|
|
25
|
+
s.onload = s.onreadystatechange = null;
|
|
26
|
+
resolve();
|
|
27
|
+
s.remove();
|
|
28
|
+
};
|
|
29
|
+
document.body.appendChild(s);
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
function loadPackage() {
|
|
34
|
+
|
|
35
|
+
let package = script.getAttribute("data-package");
|
|
36
|
+
let packageRoot = script.getAttribute("data-package-root");
|
|
37
|
+
if (!packageRoot) {
|
|
38
|
+
packageRoot = src;
|
|
39
|
+
}
|
|
40
|
+
if (!package) {
|
|
41
|
+
fetch(src + "/package.json").then((x) => x.json().then((json) => {
|
|
42
|
+
script.setAttribute("data-package", json.name);
|
|
43
|
+
loadPackage();
|
|
44
|
+
}));
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
const view = script.getAttribute("data-view");
|
|
49
|
+
|
|
50
|
+
const packed = JSON.parse(script.getAttribute("data-packed") ?? "true");
|
|
51
|
+
const min = JSON.parse(script.getAttribute("data-min") ?? "true");
|
|
52
|
+
|
|
53
|
+
const viewUrl = `${packageRoot}/${view}${packed ? ".pack" : ""}${min ? ".min" : ""}.js`;
|
|
54
|
+
const viewName = `${package}/${view}`;
|
|
55
|
+
|
|
56
|
+
loadScript(viewUrl).then(() => {
|
|
57
|
+
function empty () {
|
|
58
|
+
return function () {
|
|
59
|
+
return null
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
AmdLoader.moduleProgress = empty;
|
|
64
|
+
function done () {
|
|
65
|
+
const we = document.getElementById("webAtomsLoader");
|
|
66
|
+
if (we) {
|
|
67
|
+
we.remove();
|
|
68
|
+
}
|
|
69
|
+
};
|
|
70
|
+
UMD.setupRoot(package, packageRoot);
|
|
71
|
+
UMD.lang = "en-US";
|
|
72
|
+
const map = script.getAttribute("data-map");
|
|
73
|
+
if (map) {
|
|
74
|
+
try {
|
|
75
|
+
for (const [key, value] of JSON.parse(map)) {
|
|
76
|
+
UMD.map(key, value);
|
|
77
|
+
}
|
|
78
|
+
} catch (error) {
|
|
79
|
+
console.error(error);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
UMD.loadView(viewName, 0).then(done);
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
loadPackage();
|
|
88
|
+
})();
|