generated from halo-dev/plugin-starter
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d48f8aa
commit ed5f59c
Showing
10 changed files
with
101 additions
and
69 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
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
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
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
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
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
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
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
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 |
---|---|---|
@@ -0,0 +1,20 @@ | ||
if (!window.vditorPjax) { | ||
window.vditorPjax = true | ||
// 当网页已经准备就绪则直接执行渲染任务 | ||
if (document.readyState === "complete") { | ||
vditorRender.render() | ||
} else { | ||
window.addEventListener('load', () => vditorRender.render()) | ||
} | ||
// 兼容 PJAX | ||
$(document).on('pjax:complete', function() { | ||
vditorRender.render() | ||
console.log("[Vditor Render] PJAX END") | ||
}) | ||
// 兼容 Jquery-Pjax | ||
$(document).on('pjax:end', function() { | ||
vditorRender.render() | ||
console.log("[Vditor Render] PJAX END") | ||
}) | ||
console.log("[Vditor Render] PJAX Injected") | ||
} |
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,54 +1,67 @@ | ||
const THEME_PREFIX="/plugins/vditor-mde/assets/static/themes" | ||
const CDN = "https://cdn.jsdelivr.net/npm/vditor@3.9.9" | ||
(function (win) { | ||
if (win.vditorRender) return; | ||
|
||
/** 拓展处理 ({dark}) => void */ | ||
let functionList = [] | ||
let darkMode = false | ||
const THEME_PREFIX="/plugins/vditor-mde/assets/static/themes" | ||
const CDN = "https://cdn.jsdelivr.net/npm/vditor@3.9.9" | ||
|
||
/** | ||
* 处理渲染 | ||
* @param func | ||
*/ | ||
function addExternal(func) { | ||
functionList.push(func) | ||
} | ||
/** 拓展处理 ({dark}) => void */ | ||
let functionList = [] | ||
let darkMode = false | ||
|
||
/** | ||
* 设置暗色模式 | ||
* @param {Boolean} dark | ||
*/ | ||
function setDarkMode(dark = false) { | ||
darkMode = dark | ||
} | ||
/** | ||
* 处理渲染 | ||
* @param func | ||
*/ | ||
function addExternal(func) { | ||
functionList.push(func) | ||
} | ||
|
||
/** | ||
* 渲染 | ||
* @param dark | ||
*/ | ||
function render(dark) { | ||
Vditor.setContentTheme(dark?"dark":"light", THEME_PREFIX) | ||
const root = document.getElementById("vditor-render").parentElement | ||
root.classList.add("vditor-reset") | ||
// Render | ||
const renderTheme = dark?"dark":"classic" | ||
Vditor.mathRender(root, {cdn: CDN}) | ||
Vditor.mindmapRender(root, CDN, renderTheme) | ||
Vditor.mermaidRender(root, CDN, renderTheme) | ||
Vditor.chartRender(root, CDN, renderTheme) | ||
Vditor.abcRender(root, CDN) | ||
Vditor.graphvizRender(root, CDN) | ||
Vditor.flowchartRender(root, CDN) | ||
// Run External Plugin | ||
functionList.forEach(func => { | ||
func({ | ||
dark | ||
/** | ||
* 设置暗色模式 | ||
* @param {Boolean} dark | ||
*/ | ||
function setDarkMode(dark = false) { | ||
darkMode = dark | ||
} | ||
|
||
/** | ||
* 渲染 | ||
* @param elId 搜寻位置 | ||
*/ | ||
function vditorRender(elId="vditor-article-sign") { | ||
Vditor.setContentTheme(darkMode?"dark":"light", THEME_PREFIX) | ||
let root = document.getElementById(elId) | ||
if (!root) { | ||
console.log("[Vditor Render] Can't Found Article Root Element!"); | ||
return | ||
} | ||
root = root.parentElement | ||
root.classList.add("vditor-reset") | ||
// Render | ||
const renderTheme = darkMode?"dark":"classic" | ||
Vditor.mathRender(root, {cdn: CDN}) | ||
Vditor.mindmapRender(root, CDN, renderTheme) | ||
Vditor.mermaidRender(root, CDN, renderTheme) | ||
Vditor.chartRender(root, CDN, renderTheme) | ||
Vditor.abcRender(root, CDN) | ||
Vditor.graphvizRender(root, CDN) | ||
Vditor.flowchartRender(root, CDN) | ||
// Run External Plugin | ||
functionList.forEach(func => { | ||
func({ | ||
darkMode | ||
}) | ||
}) | ||
}) | ||
} | ||
} | ||
|
||
/** | ||
* 页面加载完成时处理任务 | ||
*/ | ||
function initRender() { | ||
window.addEventListener("load", () => render(darkMode)) | ||
} | ||
win.vditorRender = { | ||
THEME_PREFIX, | ||
CDN, | ||
functionList, | ||
darkMode, | ||
addExternal, | ||
setDarkMode, | ||
vditorRender, | ||
render: vditorRender | ||
} | ||
})(window) |