2018-12-29 10:04:59 +01:00
|
|
|
import cloning from './services/cloning.js';
|
|
|
|
import contextMenu from './services/tree_context_menu.js';
|
|
|
|
import link from './services/link.js';
|
2019-08-26 20:21:43 +02:00
|
|
|
import ws from './services/ws.js';
|
2020-01-12 19:05:09 +01:00
|
|
|
import noteType from './widgets/note_type.js';
|
2019-03-13 21:53:09 +01:00
|
|
|
import protectedSessionService from './services/protected_session.js';
|
|
|
|
import protectedSessionHolder from './services/protected_session_holder.js';
|
2018-12-29 10:04:59 +01:00
|
|
|
import searchNotesService from './services/search_notes.js';
|
|
|
|
import FrontendScriptApi from './services/frontend_script_api.js';
|
|
|
|
import ScriptContext from './services/script_context.js';
|
|
|
|
import sync from './services/sync.js';
|
|
|
|
import treeService from './services/tree.js';
|
|
|
|
import treeChanges from './services/branches.js';
|
|
|
|
import utils from './services/utils.js';
|
|
|
|
import server from './services/server.js';
|
2020-01-21 22:54:16 +01:00
|
|
|
import Entrypoints from './services/entrypoints.js';
|
2018-12-29 10:04:59 +01:00
|
|
|
import noteTooltipService from './services/note_tooltip.js';
|
|
|
|
import bundle from "./services/bundle.js";
|
|
|
|
import treeCache from "./services/tree_cache.js";
|
|
|
|
import libraryLoader from "./services/library_loader.js";
|
|
|
|
import hoistedNoteService from './services/hoisted_note.js';
|
2020-01-12 19:05:09 +01:00
|
|
|
import noteTypeService from './widgets/note_type.js';
|
2018-12-29 10:04:59 +01:00
|
|
|
import linkService from './services/link.js';
|
|
|
|
import noteAutocompleteService from './services/note_autocomplete.js';
|
2019-01-09 22:08:24 +01:00
|
|
|
import macInit from './services/mac_init.js';
|
2019-01-27 17:01:37 +01:00
|
|
|
import cssLoader from './services/css_loader.js';
|
2019-04-14 12:18:52 +02:00
|
|
|
import dateNoteService from './services/date_notes.js';
|
2019-10-14 10:31:58 +02:00
|
|
|
import importService from './services/import.js';
|
2019-11-21 21:12:07 +01:00
|
|
|
import keyboardActionService from "./services/keyboard_actions.js";
|
2019-12-23 16:48:34 +01:00
|
|
|
import splitService from "./services/split.js";
|
2020-02-05 22:08:45 +01:00
|
|
|
import options from "./services/options.js";
|
2019-12-30 19:32:45 +01:00
|
|
|
import noteContentRenderer from "./services/note_content_renderer.js";
|
2020-01-12 09:57:28 +01:00
|
|
|
import appContext from "./services/app_context.js";
|
2018-03-24 11:18:46 -04:00
|
|
|
|
2020-02-08 10:40:58 +01:00
|
|
|
window.glob.PROFILING_LOG = false;
|
|
|
|
|
2019-05-22 20:53:59 +02:00
|
|
|
window.glob.isDesktop = utils.isDesktop;
|
|
|
|
window.glob.isMobile = utils.isMobile;
|
|
|
|
|
2018-03-25 20:18:08 -04:00
|
|
|
// required for CKEditor image upload plugin
|
2020-02-07 20:56:49 +01:00
|
|
|
// FIXME
|
2020-01-12 11:15:23 +01:00
|
|
|
window.glob.getActiveNode = () => appContext.getMainNoteTree().getActiveNode();
|
2018-03-25 20:18:08 -04:00
|
|
|
window.glob.getHeaders = server.getHeaders;
|
2019-08-20 21:40:47 +02:00
|
|
|
window.glob.showAddLinkDialog = () => import('./dialogs/add_link.js').then(d => d.showDialog());
|
2019-12-29 23:46:40 +01:00
|
|
|
window.glob.showIncludeNoteDialog = cb => import('./dialogs/include_note.js').then(d => d.showDialog(cb));
|
2019-12-30 19:32:45 +01:00
|
|
|
window.glob.loadIncludedNote = async (noteId, el) => {
|
|
|
|
const note = await treeCache.getNote(noteId);
|
|
|
|
|
|
|
|
if (note) {
|
|
|
|
$(el).empty().append($("<h3>").append(await linkService.createNoteLink(note.noteId, {
|
|
|
|
showTooltip: false
|
|
|
|
})));
|
|
|
|
|
|
|
|
const {renderedContent} = await noteContentRenderer.getRenderedContent(note);
|
|
|
|
|
|
|
|
$(el).append(renderedContent);
|
|
|
|
}
|
|
|
|
};
|
2018-08-11 19:45:55 +02:00
|
|
|
// this is required by CKEditor when uploading images
|
2020-02-02 10:41:43 +01:00
|
|
|
window.glob.noteChanged = () => {
|
2020-02-07 21:08:55 +01:00
|
|
|
const activeTabContext = appContext.tabManager.getActiveTabContext();
|
2020-02-02 10:41:43 +01:00
|
|
|
|
|
|
|
if (activeTabContext) {
|
|
|
|
activeTabContext.noteChanged();
|
|
|
|
}
|
|
|
|
};
|
2018-11-08 11:08:16 +01:00
|
|
|
window.glob.refreshTree = treeService.reload;
|
2018-03-25 20:18:08 -04:00
|
|
|
|
|
|
|
// required for ESLint plugin
|
2020-02-07 21:08:55 +01:00
|
|
|
window.glob.getActiveTabNote = () => appContext.tabManager.getActiveTabNote();
|
2018-03-27 22:42:46 -04:00
|
|
|
window.glob.requireLibrary = libraryLoader.requireLibrary;
|
|
|
|
window.glob.ESLINT = libraryLoader.ESLINT;
|
2020-02-09 21:13:05 +01:00
|
|
|
window.glob.appContext = appContext; // for debugging
|
2018-03-25 20:18:08 -04:00
|
|
|
|
2019-03-13 21:53:09 +01:00
|
|
|
protectedSessionHolder.setProtectedSessionId(null);
|
|
|
|
|
2018-03-26 22:29:14 -04:00
|
|
|
window.onerror = function (msg, url, lineNo, columnNo, error) {
|
|
|
|
const string = msg.toLowerCase();
|
2018-03-25 19:49:33 -04:00
|
|
|
|
2018-03-26 22:29:14 -04:00
|
|
|
let message = "Uncaught error: ";
|
2018-03-25 19:49:33 -04:00
|
|
|
|
2018-07-08 23:13:56 +02:00
|
|
|
if (string.includes("Cannot read property 'defaultView' of undefined")) {
|
|
|
|
// ignore this specific error which is very common but we don't know where it comes from
|
|
|
|
// and it seems to be harmless
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else if (string.includes("script error")) {
|
2018-03-26 22:29:14 -04:00
|
|
|
message += 'No details available';
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
message += [
|
|
|
|
'Message: ' + msg,
|
|
|
|
'URL: ' + url,
|
|
|
|
'Line: ' + lineNo,
|
|
|
|
'Column: ' + columnNo,
|
|
|
|
'Error object: ' + JSON.stringify(error)
|
|
|
|
].join(' - ');
|
|
|
|
}
|
2018-03-25 19:49:33 -04:00
|
|
|
|
2019-08-26 20:21:43 +02:00
|
|
|
ws.logError(message);
|
2018-03-25 19:49:33 -04:00
|
|
|
|
2018-03-26 22:29:14 -04:00
|
|
|
return false;
|
|
|
|
};
|
2018-03-25 19:49:33 -04:00
|
|
|
|
2019-01-27 17:01:37 +01:00
|
|
|
for (const appCssNoteId of window.appCssNoteIds) {
|
2019-12-03 22:13:02 +01:00
|
|
|
cssLoader.requireCss(`api/notes/download/${appCssNoteId}`);
|
2019-01-27 17:01:37 +01:00
|
|
|
}
|
|
|
|
|
2018-08-15 10:14:14 +02:00
|
|
|
const wikiBaseUrl = "https://github.com/zadam/trilium/wiki/";
|
|
|
|
|
|
|
|
$(document).on("click", "button[data-help-page]", e => {
|
|
|
|
const $button = $(e.target);
|
|
|
|
|
|
|
|
window.open(wikiBaseUrl + $button.attr("data-help-page"), '_blank');
|
|
|
|
});
|
|
|
|
|
2019-02-10 12:19:48 +01:00
|
|
|
$("body").on("click", "a.external", function () {
|
|
|
|
window.open($(this).attr("href"), '_blank');
|
|
|
|
});
|
|
|
|
|
2018-03-26 22:29:14 -04:00
|
|
|
if (utils.isElectron()) {
|
2019-11-21 21:12:07 +01:00
|
|
|
require('electron').ipcRenderer.on('globalShortcut', async function(event, actionName) {
|
|
|
|
keyboardActionService.triggerAction(actionName);
|
2018-03-26 22:29:14 -04:00
|
|
|
});
|
|
|
|
}
|
2018-03-25 22:37:02 -04:00
|
|
|
|
2019-02-24 11:36:01 +01:00
|
|
|
$('[data-toggle="tooltip"]').tooltip({
|
|
|
|
html: true
|
|
|
|
});
|
|
|
|
|
2019-09-02 21:23:55 +02:00
|
|
|
// for CKEditor integration (button on block toolbar)
|
|
|
|
window.glob.importMarkdownInline = async () => {
|
|
|
|
const dialog = await import("./dialogs/markdown_import.js");
|
|
|
|
|
|
|
|
dialog.importMarkdownInline();
|
|
|
|
};
|
|
|
|
|
2019-01-09 22:08:24 +01:00
|
|
|
macInit.init();
|
|
|
|
|
2019-01-25 22:18:34 +01:00
|
|
|
searchNotesService.init(); // should be in front of treeService since that one manipulates address bar hash
|
|
|
|
|
2020-02-02 22:04:28 +01:00
|
|
|
appContext.start();
|
2018-03-26 22:29:14 -04:00
|
|
|
|
2018-12-22 20:57:09 +01:00
|
|
|
noteTooltipService.setupGlobalTooltip();
|
2018-03-26 22:29:14 -04:00
|
|
|
|
2020-02-05 22:08:45 +01:00
|
|
|
noteAutocompleteService.init();
|