2018-12-29 17:04:59 +08:00
|
|
|
import cloning from './services/cloning.js';
|
|
|
|
import contextMenu from './services/tree_context_menu.js';
|
|
|
|
import link from './services/link.js';
|
2019-08-27 02:21:43 +08:00
|
|
|
import ws from './services/ws.js';
|
2018-12-29 17:04:59 +08:00
|
|
|
import noteDetailService from './services/note_detail.js';
|
|
|
|
import noteType from './services/note_type.js';
|
2019-03-14 04:53:09 +08:00
|
|
|
import protectedSessionService from './services/protected_session.js';
|
|
|
|
import protectedSessionHolder from './services/protected_session_holder.js';
|
2018-12-29 17:04:59 +08: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 treeUtils from './services/tree_utils.js';
|
|
|
|
import utils from './services/utils.js';
|
|
|
|
import server from './services/server.js';
|
|
|
|
import entrypoints from './services/entrypoints.js';
|
|
|
|
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';
|
|
|
|
import noteTypeService from './services/note_type.js';
|
|
|
|
import linkService from './services/link.js';
|
|
|
|
import noteAutocompleteService from './services/note_autocomplete.js';
|
2019-01-10 05:08:24 +08:00
|
|
|
import macInit from './services/mac_init.js';
|
2019-01-28 00:01:37 +08:00
|
|
|
import cssLoader from './services/css_loader.js';
|
2019-04-14 18:18:52 +08:00
|
|
|
import dateNoteService from './services/date_notes.js';
|
2019-07-21 16:17:08 +08:00
|
|
|
import sidebarService from './services/sidebar.js';
|
2019-10-14 16:31:58 +08:00
|
|
|
import importService from './services/import.js';
|
2019-11-22 04:12:07 +08:00
|
|
|
import keyboardActionService from "./services/keyboard_actions.js";
|
2019-12-23 23:48:34 +08:00
|
|
|
import splitService from "./services/split.js";
|
2019-12-24 19:10:32 +08:00
|
|
|
import optionService from "./services/options.js";
|
2019-12-31 02:32:45 +08:00
|
|
|
import noteContentRenderer from "./services/note_content_renderer.js";
|
2020-01-12 16:57:28 +08:00
|
|
|
import appContext from "./services/app_context.js";
|
2018-03-24 23:18:46 +08:00
|
|
|
|
2019-05-23 02:53:59 +08:00
|
|
|
window.glob.isDesktop = utils.isDesktop;
|
|
|
|
window.glob.isMobile = utils.isMobile;
|
|
|
|
|
2018-03-26 08:18:08 +08:00
|
|
|
// required for CKEditor image upload plugin
|
2019-03-21 05:28:54 +08:00
|
|
|
window.glob.getActiveNode = treeService.getActiveNode;
|
2018-03-26 08:18:08 +08:00
|
|
|
window.glob.getHeaders = server.getHeaders;
|
2019-08-21 03:40:47 +08:00
|
|
|
window.glob.showAddLinkDialog = () => import('./dialogs/add_link.js').then(d => d.showDialog());
|
2019-12-30 06:46:40 +08:00
|
|
|
window.glob.showIncludeNoteDialog = cb => import('./dialogs/include_note.js').then(d => d.showDialog(cb));
|
2019-12-31 02:32:45 +08: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-12 01:45:55 +08:00
|
|
|
// this is required by CKEditor when uploading images
|
|
|
|
window.glob.noteChanged = noteDetailService.noteChanged;
|
2018-11-08 18:08:16 +08:00
|
|
|
window.glob.refreshTree = treeService.reload;
|
2018-03-26 08:18:08 +08:00
|
|
|
|
|
|
|
// required for ESLint plugin
|
2019-10-20 18:29:34 +08:00
|
|
|
window.glob.getActiveTabNote = noteDetailService.getActiveTabNote;
|
2018-03-28 10:42:46 +08:00
|
|
|
window.glob.requireLibrary = libraryLoader.requireLibrary;
|
|
|
|
window.glob.ESLINT = libraryLoader.ESLINT;
|
2018-03-26 08:18:08 +08:00
|
|
|
|
2019-03-14 04:53:09 +08:00
|
|
|
protectedSessionHolder.setProtectedSessionId(null);
|
|
|
|
|
2018-03-27 10:29:14 +08:00
|
|
|
window.onerror = function (msg, url, lineNo, columnNo, error) {
|
|
|
|
const string = msg.toLowerCase();
|
2018-03-26 07:49:33 +08:00
|
|
|
|
2018-03-27 10:29:14 +08:00
|
|
|
let message = "Uncaught error: ";
|
2018-03-26 07:49:33 +08:00
|
|
|
|
2018-07-09 05:13:56 +08: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-27 10:29:14 +08:00
|
|
|
message += 'No details available';
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
message += [
|
|
|
|
'Message: ' + msg,
|
|
|
|
'URL: ' + url,
|
|
|
|
'Line: ' + lineNo,
|
|
|
|
'Column: ' + columnNo,
|
|
|
|
'Error object: ' + JSON.stringify(error)
|
|
|
|
].join(' - ');
|
|
|
|
}
|
2018-03-26 07:49:33 +08:00
|
|
|
|
2019-08-27 02:21:43 +08:00
|
|
|
ws.logError(message);
|
2018-03-26 07:49:33 +08:00
|
|
|
|
2018-03-27 10:29:14 +08:00
|
|
|
return false;
|
|
|
|
};
|
2018-03-26 07:49:33 +08:00
|
|
|
|
2019-01-28 00:01:37 +08:00
|
|
|
for (const appCssNoteId of window.appCssNoteIds) {
|
2019-12-04 05:13:02 +08:00
|
|
|
cssLoader.requireCss(`api/notes/download/${appCssNoteId}`);
|
2019-01-28 00:01:37 +08:00
|
|
|
}
|
|
|
|
|
2018-08-15 16:14:14 +08: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');
|
|
|
|
});
|
|
|
|
|
2018-03-27 10:29:14 +08:00
|
|
|
$("#logout-button").toggle(!utils.isElectron());
|
2018-03-26 07:49:33 +08:00
|
|
|
|
2019-11-10 00:39:48 +08:00
|
|
|
$("#logout-button").on('click', () => {
|
2019-03-25 05:41:53 +08:00
|
|
|
const $logoutForm = $('<form action="logout" method="POST">')
|
|
|
|
.append($(`<input type="hidden" name="_csrf" value="${glob.csrfToken}"/>`));
|
2019-02-10 02:17:16 +08:00
|
|
|
|
|
|
|
$("body").append($logoutForm);
|
2019-11-10 00:45:22 +08:00
|
|
|
$logoutForm.trigger('submit');
|
2019-02-10 02:17:16 +08:00
|
|
|
});
|
|
|
|
|
2019-02-10 19:19:48 +08:00
|
|
|
$("body").on("click", "a.external", function () {
|
|
|
|
window.open($(this).attr("href"), '_blank');
|
|
|
|
});
|
|
|
|
|
2018-03-27 10:29:14 +08:00
|
|
|
if (utils.isElectron()) {
|
2019-11-22 04:12:07 +08:00
|
|
|
require('electron').ipcRenderer.on('globalShortcut', async function(event, actionName) {
|
|
|
|
keyboardActionService.triggerAction(actionName);
|
2018-03-27 10:29:14 +08:00
|
|
|
});
|
|
|
|
}
|
2018-03-26 10:37:02 +08:00
|
|
|
|
2019-05-06 00:24:59 +08:00
|
|
|
const $noteTabContainer = $("#note-tab-container");
|
|
|
|
|
|
|
|
$noteTabContainer.on("click", ".export-note-button", function () {
|
2018-11-19 16:54:33 +08:00
|
|
|
if ($(this).hasClass("disabled")) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-09-03 01:56:52 +08:00
|
|
|
import('./dialogs/export.js').then(d => d.showDialog(treeService.getActiveNode(), 'single'));
|
2018-11-19 16:54:33 +08:00
|
|
|
});
|
2018-09-03 15:40:22 +08:00
|
|
|
|
2019-09-03 01:56:52 +08:00
|
|
|
$noteTabContainer.on("click", ".import-files-button",
|
|
|
|
() => import('./dialogs/import.js').then(d => d.showDialog(treeService.getActiveNode())));
|
2019-05-06 00:24:59 +08:00
|
|
|
|
2019-11-25 05:15:33 +08:00
|
|
|
async function printActiveNote() {
|
2019-06-30 04:57:47 +08:00
|
|
|
if ($(this).hasClass("disabled")) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
const $tabContext = noteDetailService.getActiveTabContext();
|
|
|
|
if (!$tabContext) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
await libraryLoader.requireLibrary(libraryLoader.PRINT_THIS);
|
|
|
|
|
|
|
|
$tabContext.$tabContent.find('.note-detail-component:visible').printThis({
|
|
|
|
header: $("<h2>").text($tabContext.note && $tabContext.note.title).prop('outerHTML') ,
|
|
|
|
importCSS: false,
|
2019-12-25 17:59:45 +08:00
|
|
|
loadCSS: [
|
|
|
|
"libraries/codemirror/codemirror.css",
|
2019-12-25 18:34:45 +08:00
|
|
|
"libraries/ckeditor/ckeditor-content.css"
|
2019-12-25 17:59:45 +08:00
|
|
|
],
|
2019-06-30 04:57:47 +08:00
|
|
|
debug: true
|
|
|
|
});
|
2019-11-25 05:15:33 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
keyboardActionService.setGlobalActionHandler("PrintActiveNote", printActiveNote);
|
|
|
|
|
|
|
|
$noteTabContainer.on("click", ".print-note-button", printActiveNote);
|
2019-06-30 04:57:47 +08:00
|
|
|
|
2019-02-24 18:36:01 +08:00
|
|
|
$('[data-toggle="tooltip"]').tooltip({
|
|
|
|
html: true
|
|
|
|
});
|
|
|
|
|
2019-09-03 03:23:55 +08:00
|
|
|
// for CKEditor integration (button on block toolbar)
|
|
|
|
window.glob.importMarkdownInline = async () => {
|
|
|
|
const dialog = await import("./dialogs/markdown_import.js");
|
|
|
|
|
|
|
|
dialog.importMarkdownInline();
|
|
|
|
};
|
|
|
|
|
2019-01-10 05:08:24 +08:00
|
|
|
macInit.init();
|
|
|
|
|
2019-01-26 05:18:34 +08:00
|
|
|
searchNotesService.init(); // should be in front of treeService since that one manipulates address bar hash
|
|
|
|
|
2020-01-12 04:19:56 +08:00
|
|
|
appContext.showWidgets();
|
2018-03-27 10:29:14 +08:00
|
|
|
|
|
|
|
entrypoints.registerEntrypoints();
|
|
|
|
|
2018-12-23 03:57:09 +08:00
|
|
|
noteTooltipService.setupGlobalTooltip();
|
2018-03-27 10:29:14 +08:00
|
|
|
|
2019-05-01 04:31:12 +08:00
|
|
|
noteAutocompleteService.init();
|
2019-10-07 03:35:26 +08:00
|
|
|
|
|
|
|
if (utils.isElectron()) {
|
|
|
|
import("./services/spell_check.js").then(spellCheckService => spellCheckService.initSpellCheck());
|
2019-12-23 20:34:54 +08:00
|
|
|
}
|
|
|
|
|
2019-12-24 19:10:32 +08:00
|
|
|
optionService.waitForOptions().then(options => {
|
|
|
|
if (utils.isElectron() && !options.is('nativeTitleBarVisible')) {
|
|
|
|
$("#title-bar-buttons").show();
|
|
|
|
|
|
|
|
$("#minimize-btn").on('click', () => {
|
|
|
|
$("#minimize-btn").trigger('blur');
|
|
|
|
const {remote} = require('electron');
|
|
|
|
remote.BrowserWindow.getFocusedWindow().minimize();
|
|
|
|
});
|
|
|
|
|
|
|
|
$("#maximize-btn").on('click', () => {
|
|
|
|
$("#maximize-btn").trigger('blur');
|
|
|
|
const {remote} = require('electron');
|
|
|
|
const focusedWindow = remote.BrowserWindow.getFocusedWindow();
|
|
|
|
|
|
|
|
if (focusedWindow.isMaximized()) {
|
|
|
|
focusedWindow.unmaximize();
|
|
|
|
} else {
|
|
|
|
focusedWindow.maximize();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
$("#close-btn").on('click', () => {
|
|
|
|
$("#close-btn").trigger('blur');
|
|
|
|
const {remote} = require('electron');
|
|
|
|
remote.BrowserWindow.getFocusedWindow().close();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|