-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(MediaWiki:Gadget-wikieditor-highlight.js): 添加高亮设置开关
- Loading branch information
1 parent
0c5222b
commit 02efa0b
Showing
1 changed file
with
10 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,13 +12,7 @@ | |
const isAdvanced = ["loading", "loaded", "executing", "ready"].includes(mw.loader.getState("ext.wikiEditor")); | ||
const init = async () => { | ||
if (!window.CodeMirror6) { | ||
await new Promise((resolve) => { | ||
const script = document.createElement("script"); | ||
script.addEventListener("load", resolve); | ||
script.type = "module"; | ||
script.src = "https://testingcf.jsdelivr.net/npm/@bhsd/codemirror-mediawiki@latest/dist/mw.min.js"; | ||
document.head.append(script); | ||
}); | ||
await libCachedCode.injectCachedCode("https://testingcf.jsdelivr.net/npm/@bhsd/codemirror-mediawiki@latest/dist/wiki.min.js", "js"); | ||
} | ||
cm = await window.CodeMirror6.fromTextArea($textarea[0]); | ||
$(".group-codeeditor-main").hide(); | ||
|
@@ -33,13 +27,20 @@ | |
if (cm) { | ||
cm.toggle(); | ||
$(".group-codeeditor-main").toggle(); | ||
btn2.$element.toggle(); | ||
Check failure on line 30 in src/gadgets/wikieditor-highlight/MediaWiki:Gadget-wikieditor-highlight.js GitHub Actions / linter_testESLint Annotation
|
||
} else { | ||
await init(); | ||
btn.$element.after(btn2.$element); | ||
Check failure on line 33 in src/gadgets/wikieditor-highlight/MediaWiki:Gadget-wikieditor-highlight.js GitHub Actions / linter_testESLint Annotation
|
||
} | ||
btn.$element.toggleClass("tool-active"); | ||
state = !state; | ||
localObjectStorage.setItem("wikieditor-codemirror", state); | ||
}); | ||
const btn2 = new OO.ui.ButtonWidget({ | ||
classes: ["tool"], icon: "settings", framed: false, title: "代码高亮设置", | ||
}).on("click", async () => { | ||
Check failure on line 41 in src/gadgets/wikieditor-highlight/MediaWiki:Gadget-wikieditor-highlight.js GitHub Actions / linter_testESLint Annotation
|
||
$("#cm-settings").trigger("click"); | ||
}); | ||
$textarea.on("wikiEditor-toolbar-doneInitialSections", () => { | ||
btn.$element.appendTo("#wikiEditor-section-main > .group-insert"); | ||
}); | ||
|
@@ -51,8 +52,9 @@ | |
state = false; | ||
} | ||
if (state) { | ||
await mw.loader.using("ext.wikiEditor"); | ||
await mw.loader.using(["ext.wikiEditor", "oojs-ui.styles.icons-interactions"]); | ||
await init(); | ||
btn.$element.addClass("tool-active"); | ||
btn.$element.after(btn2.$element); | ||
} | ||
})(); |