mirror of
https://github.com/zadam/trilium.git
synced 2024-11-18 05:35:56 +08:00
65 lines
No EOL
1.7 KiB
JavaScript
65 lines
No EOL
1.7 KiB
JavaScript
const CKEDITOR = {"js": ["libraries/ckeditor/ckeditor.js"]};
|
|
|
|
const CODE_MIRROR = {
|
|
js: [
|
|
"libraries/codemirror/codemirror.js",
|
|
"libraries/codemirror/addon/mode/loadmode.js",
|
|
"libraries/codemirror/addon/fold/xml-fold.js",
|
|
"libraries/codemirror/addon/edit/matchbrackets.js",
|
|
"libraries/codemirror/addon/edit/matchtags.js",
|
|
"libraries/codemirror/addon/search/match-highlighter.js",
|
|
"libraries/codemirror/mode/meta.js",
|
|
"libraries/codemirror/addon/lint/lint.js",
|
|
"libraries/codemirror/addon/lint/eslint.js"
|
|
],
|
|
css: [
|
|
"libraries/codemirror/codemirror.css",
|
|
"libraries/codemirror/addon/lint/lint.css"
|
|
]
|
|
};
|
|
|
|
const ESLINT = {js: ["libraries/eslint.js"]};
|
|
|
|
async function requireLibrary(library) {
|
|
if (library.css) {
|
|
library.css.map(cssUrl => requireCss(cssUrl));
|
|
}
|
|
|
|
if (library.js) {
|
|
for (const scriptUrl of library.js) {
|
|
await requireScript(scriptUrl);
|
|
}
|
|
}
|
|
}
|
|
|
|
// we save the promises in case of the same script being required concurrently multiple times
|
|
const loadedScriptPromises = {};
|
|
|
|
async function requireScript(url) {
|
|
if (!loadedScriptPromises[url]) {
|
|
loadedScriptPromises[url] = $.ajax({
|
|
url: url,
|
|
dataType: "script",
|
|
cache: true
|
|
});
|
|
}
|
|
|
|
await loadedScriptPromises[url];
|
|
}
|
|
|
|
async function requireCss(url) {
|
|
const css = Array
|
|
.from(document.querySelectorAll('link'))
|
|
.map(scr => scr.href);
|
|
|
|
if (!css.includes(url)) {
|
|
$('head').append($('<link rel="stylesheet" type="text/css" />').attr('href', url));
|
|
}
|
|
}
|
|
|
|
export default {
|
|
requireLibrary,
|
|
CKEDITOR,
|
|
CODE_MIRROR,
|
|
ESLINT
|
|
} |