-
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(wikieditor-highlight): default addons
- Loading branch information
1 parent
2d8b60c
commit 08a4081
Showing
1 changed file
with
15 additions
and
15 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 |
---|---|---|
@@ -1,10 +1,10 @@ | ||
"use strict"; | ||
// 本页面大部分内容均直接或间接修改自[[MW:Extension:CodeMirror]] | ||
(async () => { | ||
await $.ready; | ||
if (!["edit", "submit"].includes(mw.config.get("wgAction")) || mw.config.get("wgPageContentModel") !== "wikitext") { | ||
return; | ||
} | ||
await $.ready; | ||
|
||
const localObjectStorage = new LocalObjectStorage("wikieditor-highlight"); | ||
let cm, state = localObjectStorage.getItem("wikieditor-codemirror", false); | ||
|
@@ -15,32 +15,32 @@ | |
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", | ||
]); | ||
}; | ||
if (state === null || !isAdvanced) { | ||
state = true; | ||
} | ||
if (!isAdvanced) { | ||
init(); | ||
return; | ||
} else if (state === null || !isAdvanced) { | ||
state = true; | ||
} | ||
const btn = new OO.ui.ButtonWidget({ | ||
classes: ["tool"], icon: "highlight", framed: false, title: "代码高亮开关", | ||
}).on("click", async () => { | ||
if (!cm) { | ||
if (cm) { | ||
cm.toggle(); | ||
} else { | ||
await init(); | ||
} | ||
// eslint-disable-next-line no-use-before-define | ||
update(); | ||
}); | ||
const shared = () => { | ||
btn.$element.toggleClass("tool-active"); | ||
cm.toggle(); | ||
}; | ||
const update = () => { | ||
state = !state; | ||
localObjectStorage.setItem("wikieditor-codemirror", state); | ||
shared(); | ||
}; | ||
}); | ||
const group = $("#wikiEditor-section-main > .group-insert")[0]; | ||
$textarea.on("wikiEditor-toolbar-doneInitialSections", () => { | ||
btn.$element.appendTo("#wikiEditor-section-main > .group-insert"); | ||
|
@@ -51,6 +51,6 @@ | |
if (state) { | ||
await mw.loader.using("ext.wikiEditor"); | ||
await init(); | ||
shared(); | ||
btn.$element.addClass("tool-active"); | ||
} | ||
})(); |