| 
									
										
										
										
											2018-12-29 10:04:59 +01:00
										 |  |  | 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-25 22:28:15 +01:00
										 |  |  | import importDialog from './dialogs/import.js'; | 
					
						
							| 
									
										
										
										
											2018-03-24 11:18:46 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-12-29 10:04:59 +01: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'; | 
					
						
							| 
									
										
										
										
											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 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-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'; | 
					
						
							| 
									
										
										
										
											2018-03-24 11:18:46 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-03-25 20:18:08 -04:00
										 |  |  | // required for CKEditor image upload plugin
 | 
					
						
							| 
									
										
										
										
											2019-03-20 22:28:54 +01:00
										 |  |  | window.glob.getActiveNode = treeService.getActiveNode; | 
					
						
							| 
									
										
										
										
											2018-03-25 20:18:08 -04:00
										 |  |  | window.glob.getHeaders = server.getHeaders; | 
					
						
							| 
									
										
										
										
											2018-05-26 10:04:40 -04:00
										 |  |  | window.glob.showAddLinkDialog = addLinkDialog.showDialog; | 
					
						
							| 
									
										
										
										
											2018-08-11 19:45:55 +02:00
										 |  |  | // this is required by CKEditor when uploading images
 | 
					
						
							|  |  |  | window.glob.noteChanged = noteDetailService.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
 | 
					
						
							| 
									
										
										
										
											2019-03-14 20:21:27 +01:00
										 |  |  | window.glob.getActiveNote = noteDetailService.getActiveNote; | 
					
						
							| 
									
										
										
										
											2018-03-27 22:42:46 -04:00
										 |  |  | window.glob.requireLibrary = libraryLoader.requireLibrary; | 
					
						
							|  |  |  | window.glob.ESLINT = libraryLoader.ESLINT; | 
					
						
							| 
									
										
										
										
											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
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-03-26 22:29:14 -04:00
										 |  |  |     messagingService.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-01-27 22:34:41 +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'); | 
					
						
							|  |  |  | }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-03-26 22:29:14 -04:00
										 |  |  | $("#logout-button").toggle(!utils.isElectron()); | 
					
						
							| 
									
										
										
										
											2018-03-25 19:49:33 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-02-09 19:17:16 +01:00
										 |  |  | $("#logout-button").click(() => { | 
					
						
							| 
									
										
										
										
											2019-03-24 22:41:53 +01:00
										 |  |  |     const $logoutForm = $('<form action="logout" method="POST">') | 
					
						
							|  |  |  |                             .append($(`<input type="hidden" name="_csrf" value="${glob.csrfToken}"/>`)); | 
					
						
							| 
									
										
										
										
											2019-02-09 19:17:16 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |     $("body").append($logoutForm); | 
					
						
							|  |  |  |     $logoutForm.submit(); | 
					
						
							|  |  |  | }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-12-15 20:29:08 +01:00
										 |  |  | $("#tree").on("click", ".unhoist-button", hoistedNoteService.unhoist); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-03-30 00:12:32 +01:00
										 |  |  | $("#tree").on("click", ".refresh-search-button", searchNotesService.refreshSearch); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											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-04-14 12:18:52 +02:00
										 |  |  |     require('electron').ipcRenderer.on('create-day-sub-note', async function(event) { | 
					
						
							|  |  |  |         const todayNote = await dateNoteService.getTodayNote(); | 
					
						
							|  |  |  |         const node = await treeService.expandToNote(todayNote.noteId); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         await treeService.createNote(node, todayNote.noteId, 'into', { | 
					
						
							|  |  |  |             type: "text", | 
					
						
							|  |  |  |             isProtected: node.data.isProtected | 
					
						
							|  |  |  |         }); | 
					
						
							| 
									
										
										
										
											2018-03-26 22:29:14 -04:00
										 |  |  |     }); | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2018-03-25 22:37:02 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-11-24 14:44:56 +01:00
										 |  |  | $("#export-note-button").click(function () { | 
					
						
							| 
									
										
										
										
											2018-11-19 09:54:33 +01:00
										 |  |  |     if ($(this).hasClass("disabled")) { | 
					
						
							|  |  |  |         return; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-11-24 14:44:56 +01:00
										 |  |  |     exportDialog.showDialog('single'); | 
					
						
							| 
									
										
										
										
											2018-11-19 09:54:33 +01:00
										 |  |  | }); | 
					
						
							| 
									
										
										
										
											2018-09-03 09:40:22 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-02-24 11:36:01 +01:00
										 |  |  | $('[data-toggle="tooltip"]').tooltip({ | 
					
						
							|  |  |  |     html: true | 
					
						
							|  |  |  | }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-02-25 22:28:15 +01:00
										 |  |  | $("#import-files-button").click(importDialog.showDialog); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											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
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-03-26 22:29:14 -04:00
										 |  |  | treeService.showTree(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | entrypoints.registerEntrypoints(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-12-22 20:57:09 +01:00
										 |  |  | noteTooltipService.setupGlobalTooltip(); | 
					
						
							| 
									
										
										
										
											2018-03-26 22:29:14 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-12-02 14:04:53 +01:00
										 |  |  | bundle.executeStartupBundles(); | 
					
						
							| 
									
										
										
										
											2018-12-24 10:10:36 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | noteTypeService.init(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | linkService.init(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | noteAutocompleteService.init(); |