Skip to content

Commit

Permalink
fix(libCachedCode): ES module
Browse files Browse the repository at this point in the history
  • Loading branch information
bhsd-harry committed Jan 13, 2024
1 parent 08a4081 commit 070f7d5
Showing 1 changed file with 18 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,24 @@
const $textarea = $("#wpTextbox1");
const isAdvanced = ["loading", "loaded", "executing", "ready"].includes(mw.loader.getState("ext.wikiEditor"));
const lang = mw.config.get("wgNamespaceNumber") === 274 ? "html" : "mediawiki";
const init = async () => {
await import("https://testingcf.jsdelivr.net/npm/@bhsd/[email protected]/mw/dist/base.min.js");
cm = await CodeMirror.fromTextArea($textarea[0], lang);
cm.defaultLint(true);
cm.prefer([
"highlightSpecialChars",
"highlightActiveLine",
"highlightWhitespace",
"bracketMatching",
"closeBrackets",
]);
};
const init = () => new Promise((resolve) => {
const script = document.createElement("script");
script.addEventListener("load", async () => {
cm = await CodeMirror.fromTextArea($textarea[0], lang);
cm.defaultLint(true);
cm.prefer([
"highlightSpecialChars",
"highlightActiveLine",
"highlightWhitespace",
"bracketMatching",
"closeBrackets",
]);
resolve();
});
script.type = "module";
script.src = "https://testingcf.jsdelivr.net/npm/@bhsd/[email protected]/mw/dist/base.min.js";
document.head.appendChild(script);
});
if (!isAdvanced) {
init();
return;
Expand Down

0 comments on commit 070f7d5

Please sign in to comment.