trilium/src/public/javascripts/desktop.js

167 lines
5.8 KiB
JavaScript
Raw Normal View History

import addLinkDialog from './dialogs/add_link.js';
import jumpToNoteDialog from './dialogs/jump_to_note.js';
import attributesDialog from './dialogs/attributes.js';
import noteRevisionsDialog from './dialogs/note_revisions.js';
import noteSourceDialog from './dialogs/note_source.js';
import recentChangesDialog from './dialogs/recent_changes.js';
import optionsDialog from './dialogs/options.js';
import sqlConsoleDialog from './dialogs/sql_console.js';
import markdownImportDialog from './dialogs/markdown_import.js';
import exportDialog from './dialogs/export.js';
2019-02-26 05:28:15 +08:00
import importDialog from './dialogs/import.js';
import protectedSessionDialog from './dialogs/protected_session.js';
2019-06-02 21:35:57 +08:00
import linkMapDialog from './dialogs/link_map.js';
2018-03-24 23:18:46 +08:00
import cloning from './services/cloning.js';
import contextMenu from './services/tree_context_menu.js';
import dragAndDropSetup from './services/drag_and_drop.js';
import link from './services/link.js';
import messagingService from './services/messaging.js';
import noteDetailService from './services/note_detail.js';
import noteType from './services/note_type.js';
import protectedSessionService from './services/protected_session.js';
import protectedSessionHolder from './services/protected_session_holder.js';
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';
import macInit from './services/mac_init.js';
import cssLoader from './services/css_loader.js';
import dateNoteService from './services/date_notes.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
window.glob.getActiveNode = treeService.getActiveNode;
2018-03-26 08:18:08 +08:00
window.glob.getHeaders = server.getHeaders;
2018-05-26 22:04:40 +08:00
window.glob.showAddLinkDialog = addLinkDialog.showDialog;
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
window.glob.getActiveNote = noteDetailService.getActiveNote;
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
protectedSessionHolder.setProtectedSessionId(null);
window.onerror = function (msg, url, lineNo, columnNo, error) {
const string = msg.toLowerCase();
let message = "Uncaught error: ";
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")) {
message += 'No details available';
}
else {
message += [
'Message: ' + msg,
'URL: ' + url,
'Line: ' + lineNo,
'Column: ' + columnNo,
'Error object: ' + JSON.stringify(error)
].join(' - ');
}
messagingService.logError(message);
return false;
};
for (const appCssNoteId of window.appCssNoteIds) {
cssLoader.requireCss(`/api/notes/download/${appCssNoteId}`);
}
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');
});
$("#logout-button").toggle(!utils.isElectron());
2019-02-10 02:17:16 +08:00
$("#logout-button").click(() => {
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);
$logoutForm.submit();
});
2018-12-16 03:29:08 +08:00
$("#tree").on("click", ".unhoist-button", hoistedNoteService.unhoist);
$("#tree").on("click", ".refresh-search-button", searchNotesService.refreshSearch);
2019-02-10 19:19:48 +08:00
$("body").on("click", "a.external", function () {
window.open($(this).attr("href"), '_blank');
});
if (utils.isElectron()) {
require('electron').ipcRenderer.on('create-day-sub-note', async function(event) {
const todayNote = await dateNoteService.getTodayNote();
2019-05-20 00:21:29 +08:00
const notePath = await treeService.getSomeNotePath(todayNote);
const node = await treeService.expandToNote(notePath);
await noteDetailService.openEmptyTab(false);
await treeService.createNote(node, todayNote.noteId, 'into', {
type: "text",
isProtected: node.data.isProtected
});
});
}
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 () {
if ($(this).hasClass("disabled")) {
return;
}
2018-11-24 21:44:56 +08:00
exportDialog.showDialog('single');
});
2018-09-03 15:40:22 +08:00
2019-05-06 00:24:59 +08:00
$noteTabContainer.on("click", ".import-files-button", importDialog.showDialog);
$('[data-toggle="tooltip"]').tooltip({
html: true
});
macInit.init();
searchNotesService.init(); // should be in front of treeService since that one manipulates address bar hash
treeService.showTree();
entrypoints.registerEntrypoints();
noteTooltipService.setupGlobalTooltip();
linkService.init();
2019-05-01 04:31:12 +08:00
noteAutocompleteService.init();