mirror of
https://github.com/zadam/trilium.git
synced 2025-01-18 04:59:56 +08:00
split out library loader
This commit is contained in:
parent
9bb188b519
commit
b10b0048f3
11 changed files with 109 additions and 97 deletions
|
@ -1,4 +1,3 @@
|
|||
import treeService from '../services/tree.js';
|
||||
import cloningService from '../services/cloning.js';
|
||||
import linkService from '../services/link.js';
|
||||
import noteDetailService from '../services/note_detail.js';
|
||||
|
|
|
@ -30,14 +30,18 @@ async function showDialog() {
|
|||
$noteTitle.html(noteTitle);
|
||||
}
|
||||
|
||||
$form.submit(() => {
|
||||
async function savePrefix() {
|
||||
const prefix = $treePrefixInput.val();
|
||||
|
||||
server.put('tree/' + branchId + '/set-prefix', {
|
||||
prefix: prefix
|
||||
}).then(() => treeService.setPrefix(branchId, prefix));
|
||||
await server.put('tree/' + branchId + '/set-prefix', { prefix: prefix });
|
||||
|
||||
await treeService.setPrefix(branchId, prefix);
|
||||
|
||||
$dialog.dialog("close");
|
||||
}
|
||||
|
||||
$form.submit(() => {
|
||||
savePrefix();
|
||||
|
||||
return false;
|
||||
});
|
||||
|
|
|
@ -29,7 +29,7 @@ function formatNode(node, level) {
|
|||
const indentAfter = new Array(level - 1).join(' ');
|
||||
let textNode;
|
||||
|
||||
for (let i = 0; i < node.children.length; i++) {
|
||||
for (const i = 0; i < node.children.length; i++) {
|
||||
textNode = document.createTextNode('\n' + indentBefore);
|
||||
node.insertBefore(textNode, node.children[i]);
|
||||
|
||||
|
|
|
@ -27,6 +27,21 @@ function addRecentNote(branchId, notePath) {
|
|||
}, 1500);
|
||||
}
|
||||
|
||||
async function getNoteTitle(notePath) {
|
||||
let noteTitle;
|
||||
|
||||
try {
|
||||
noteTitle = await treeUtils.getNotePathTitle(notePath);
|
||||
}
|
||||
catch (e) {
|
||||
noteTitle = "[error - can't find note title]";
|
||||
|
||||
messagingService.logError("Could not find title for notePath=" + notePath + ", stack=" + e.stack);
|
||||
}
|
||||
|
||||
return noteTitle;
|
||||
}
|
||||
|
||||
async function showDialog() {
|
||||
glob.activeDialog = $dialog;
|
||||
|
||||
|
@ -44,19 +59,8 @@ async function showDialog() {
|
|||
const items = [];
|
||||
|
||||
for (const notePath of recNotes) {
|
||||
let noteTitle;
|
||||
|
||||
try {
|
||||
noteTitle = await treeUtils.getNotePathTitle(notePath);
|
||||
}
|
||||
catch (e) {
|
||||
noteTitle = "[error - can't find note title]";
|
||||
|
||||
messagingService.logError("Could not find title for notePath=" + notePath + ", stack=" + e.stack);
|
||||
}
|
||||
|
||||
items.push({
|
||||
label: noteTitle,
|
||||
label: await getNoteTitle(notePath),
|
||||
value: notePath
|
||||
});
|
||||
}
|
||||
|
|
|
@ -8,10 +8,10 @@ import infoService from "../services/info.js";
|
|||
const $dialog = $("#settings-dialog");
|
||||
const $tabs = $("#settings-tabs");
|
||||
|
||||
const settingModules = [];
|
||||
const tabHandlers = [];
|
||||
|
||||
function addModule(module) {
|
||||
settingModules.push(module);
|
||||
function addTabHandler(handler) {
|
||||
tabHandlers.push(handler);
|
||||
}
|
||||
|
||||
async function showDialog() {
|
||||
|
@ -26,9 +26,9 @@ async function showDialog() {
|
|||
|
||||
$tabs.tabs();
|
||||
|
||||
for (const module of settingModules) {
|
||||
if (module.settingsLoaded) {
|
||||
module.settingsLoaded(settings);
|
||||
for (const handler of tabHandlers) {
|
||||
if (handler.settingsLoaded) {
|
||||
handler.settingsLoaded(settings);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -47,7 +47,7 @@ export default {
|
|||
saveSettings
|
||||
};
|
||||
|
||||
addModule((function() {
|
||||
addTabHandler((function() {
|
||||
const $form = $("#change-password-form");
|
||||
const $oldPassword = $("#old-password");
|
||||
const $newPassword1 = $("#new-password1");
|
||||
|
@ -93,7 +93,7 @@ addModule((function() {
|
|||
};
|
||||
})());
|
||||
|
||||
addModule((function() {
|
||||
addTabHandler((function() {
|
||||
const $form = $("#protected-session-timeout-form");
|
||||
const $protectedSessionTimeout = $("#protected-session-timeout-in-seconds");
|
||||
const settingName = 'protected_session_timeout';
|
||||
|
@ -117,7 +117,7 @@ addModule((function() {
|
|||
};
|
||||
})());
|
||||
|
||||
addModule((function () {
|
||||
addTabHandler((function () {
|
||||
const $form = $("#note-revision-snapshot-time-interval-form");
|
||||
const $timeInterval = $("#note-revision-snapshot-time-interval-in-seconds");
|
||||
const settingName = 'note_revision_snapshot_time_interval';
|
||||
|
@ -137,7 +137,7 @@ addModule((function () {
|
|||
};
|
||||
})());
|
||||
|
||||
addModule((async function () {
|
||||
addTabHandler((async function () {
|
||||
const $appVersion = $("#app-version");
|
||||
const $dbVersion = $("#db-version");
|
||||
const $buildDate = $("#build-date");
|
||||
|
@ -154,7 +154,7 @@ addModule((async function () {
|
|||
return {};
|
||||
})());
|
||||
|
||||
addModule((async function () {
|
||||
addTabHandler((async function () {
|
||||
const $forceFullSyncButton = $("#force-full-sync-button");
|
||||
const $fillSyncRowsButton = $("#fill-sync-rows-button");
|
||||
const $anonymizeButton = $("#anonymize-button");
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
import utils from '../services/utils.js';
|
||||
import libraryLoader from '../services/library_loader.js';
|
||||
import server from '../services/server.js';
|
||||
import infoService from "../services/info.js";
|
||||
|
||||
|
@ -25,7 +26,7 @@ function showDialog() {
|
|||
|
||||
async function initEditor() {
|
||||
if (!codeEditor) {
|
||||
await utils.requireLibrary(utils.CODE_MIRROR);
|
||||
await libraryLoader.requireLibrary(libraryLoader.CODE_MIRROR);
|
||||
|
||||
CodeMirror.keyMap.default["Shift-Tab"] = "indentLess";
|
||||
CodeMirror.keyMap.default["Tab"] = "indentMore";
|
||||
|
|
5
src/public/javascripts/services/bootstrap.js
vendored
5
src/public/javascripts/services/bootstrap.js
vendored
|
@ -30,6 +30,7 @@ import entrypoints from './entrypoints.js';
|
|||
import tooltip from './tooltip.js';
|
||||
import bundle from "./bundle.js";
|
||||
import treeCache from "./tree_cache.js";
|
||||
import libraryLoader from "./library_loader.js";
|
||||
|
||||
// required for CKEditor image upload plugin
|
||||
window.glob.getCurrentNode = treeService.getCurrentNode;
|
||||
|
@ -37,8 +38,8 @@ window.glob.getHeaders = server.getHeaders;
|
|||
|
||||
// required for ESLint plugin
|
||||
window.glob.getCurrentNote = noteDetailService.getCurrentNote;
|
||||
window.glob.requireLibrary = utils.requireLibrary;
|
||||
window.glob.ESLINT = utils.ESLINT;
|
||||
window.glob.requireLibrary = libraryLoader.requireLibrary;
|
||||
window.glob.ESLINT = libraryLoader.ESLINT;
|
||||
|
||||
window.onerror = function (msg, url, lineNo, columnNo, error) {
|
||||
const string = msg.toLowerCase();
|
||||
|
|
64
src/public/javascripts/services/library_loader.js
Normal file
64
src/public/javascripts/services/library_loader.js
Normal file
|
@ -0,0 +1,64 @@
|
|||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const dynamicallyLoadedScripts = [];
|
||||
|
||||
async function requireScript(url) {
|
||||
if (!dynamicallyLoadedScripts.includes(url)) {
|
||||
dynamicallyLoadedScripts.push(url);
|
||||
|
||||
return await $.ajax({
|
||||
url: url,
|
||||
dataType: "script",
|
||||
cache: true
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
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
|
||||
}
|
|
@ -1,4 +1,5 @@
|
|||
import utils from "./utils.js";
|
||||
import libraryLoader from "./library_loader.js";
|
||||
import bundleService from "./bundle.js";
|
||||
import infoService from "./info.js";
|
||||
import server from "./server.js";
|
||||
|
@ -11,7 +12,7 @@ const $executeScriptButton = $("#execute-script-button");
|
|||
|
||||
async function show() {
|
||||
if (!codeEditor) {
|
||||
await utils.requireLibrary(utils.CODE_MIRROR);
|
||||
await libraryLoader.requireLibrary(libraryLoader.CODE_MIRROR);
|
||||
|
||||
CodeMirror.keyMap.default["Shift-Tab"] = "indentLess";
|
||||
CodeMirror.keyMap.default["Tab"] = "indentMore";
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import utils from "./utils.js";
|
||||
import libraryLoader from "./library_loader.js";
|
||||
import noteDetailService from './note_detail.js';
|
||||
|
||||
const $noteDetailText = $('#note-detail-text');
|
||||
|
@ -7,7 +7,7 @@ let textEditor = null;
|
|||
|
||||
async function show() {
|
||||
if (!textEditor) {
|
||||
await utils.requireLibrary(utils.CKEDITOR);
|
||||
await libraryLoader.requireLibrary(libraryLoader.CKEDITOR);
|
||||
|
||||
textEditor = await BalloonEditor.create($noteDetailText[0], {});
|
||||
|
||||
|
|
|
@ -89,64 +89,6 @@ function formatLabel(attr) {
|
|||
return str;
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const dynamicallyLoadedScripts = [];
|
||||
|
||||
async function requireScript(url) {
|
||||
if (!dynamicallyLoadedScripts.includes(url)) {
|
||||
dynamicallyLoadedScripts.push(url);
|
||||
|
||||
return await $.ajax({
|
||||
url: url,
|
||||
dataType: "script",
|
||||
cache: true
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
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));
|
||||
}
|
||||
}
|
||||
|
||||
function getHost() {
|
||||
const url = new URL(window.location.href);
|
||||
return url.protocol + "//" + url.hostname + ":" + url.port;
|
||||
|
@ -212,10 +154,6 @@ export default {
|
|||
stopWatch,
|
||||
formatValueWithWhitespace,
|
||||
formatLabel,
|
||||
requireLibrary,
|
||||
CKEDITOR,
|
||||
CODE_MIRROR,
|
||||
ESLINT,
|
||||
getHost,
|
||||
download,
|
||||
toObject,
|
||||
|
|
Loading…
Reference in a new issue