-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Expand file tree
/
Copy pathabcLoader.js
More file actions
42 lines (33 loc) · 1.02 KB
/
abcLoader.js
File metadata and controls
42 lines (33 loc) · 1.02 KB
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
function ensureABCJS() {
if (typeof window !== "undefined" && window.ABCJS) {
return Promise.resolve();
}
if (typeof window === "undefined") {
return Promise.resolve();
}
return new Promise((resolve, reject) => {
const existing = document.querySelector('script[src="lib/abc.min.js"]');
if (existing) {
if (existing.hasAttribute("data-loaded")) {
resolve();
} else {
existing.addEventListener("load", resolve);
}
return;
}
const script = document.createElement("script");
script.src = "lib/abc.min.js";
script.onload = () => {
script.setAttribute("data-loaded", "true");
resolve();
};
script.onerror = reject;
document.head.appendChild(script);
});
}
if (typeof window !== "undefined") {
window.ensureABCJS = ensureABCJS;
}
if (typeof module !== "undefined" && module.exports) {
module.exports = ensureABCJS;
}