Skip to content

Commit 636e510

Browse files
committed
✨ 一括読み込み機能追加
1 parent 584e74a commit 636e510

File tree

2 files changed

+59
-1
lines changed

2 files changed

+59
-1
lines changed

README.md

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,17 @@
1-
# dynamicEnum
1+
# JavaLibraryScript
2+
3+
index.jsで一括読み込み
4+
5+
(jasc.js対応)
6+
7+
```url
8+
https://cdn.jsdelivr.net/gh/hi2ma-bu4/JavaLibraryScript/index.js
9+
```
10+
11+
## DynamicEnum
212

313
JavaのenumをJavaScriptにそれっぽく似せて作ったやつ
14+
15+
## Interface
16+
17+
JavaのInterfaceをJavaScriptにそれっぽく似せて作ったやつ

index.js

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
(function (w) {
2+
const loadList = [
3+
// それぞれのライブラリをロード
4+
"dynamicEnum.js",
5+
"interface.js",
6+
];
7+
8+
const eventName = "javaLibraryScriptLoad";
9+
let loadJasc = false;
10+
if (typeof jasc !== "undefined" && typeof Jasc?.develop !== "undefined") {
11+
loadJasc = true;
12+
Jasc.develop.createEvent(eventName);
13+
}
14+
15+
const url = document.currentScript.src;
16+
const path = url.substring(0, url.lastIndexOf("/"));
17+
18+
const proList = [];
19+
loadList.forEach((file) => {
20+
proList.push(
21+
new Promise((resolve, reject) => {
22+
const script = document.createElement("script");
23+
script.addEventListener("load", resolve);
24+
script.addEventListener("error", reject);
25+
script.src = path + "/" + file;
26+
document.head.appendChild(script);
27+
})
28+
);
29+
});
30+
31+
const loadPro = Promise.all(proList);
32+
33+
loadPro.then(() => {
34+
if (loadJasc) {
35+
jasc.on("DOMContentLoaded", () => {
36+
jasc._dispatchEvent(eventName, loadList.length);
37+
});
38+
}
39+
});
40+
41+
w.javaLibraryScript = function () {
42+
return loadPro;
43+
};
44+
})(this);

0 commit comments

Comments
 (0)