| 
									
										
										
										
											2018-03-25 19:49:33 -04:00
										 |  |  | import addLinkDialog from '../dialogs/add_link.js'; | 
					
						
							|  |  |  | import jumpToNoteDialog from '../dialogs/jump_to_note.js'; | 
					
						
							| 
									
										
										
										
											2018-08-03 11:11:57 +02:00
										 |  |  | import attributesDialog from '../dialogs/attributes.js'; | 
					
						
							| 
									
										
										
										
											2018-03-25 20:52:38 -04:00
										 |  |  | import noteRevisionsDialog from '../dialogs/note_revisions.js'; | 
					
						
							| 
									
										
										
										
											2018-03-25 19:49:33 -04:00
										 |  |  | import noteSourceDialog from '../dialogs/note_source.js'; | 
					
						
							|  |  |  | import recentChangesDialog from '../dialogs/recent_changes.js'; | 
					
						
							| 
									
										
										
										
											2018-04-01 17:41:28 -04:00
										 |  |  | import optionsDialog from '../dialogs/options.js'; | 
					
						
							| 
									
										
										
										
											2018-03-25 19:49:33 -04:00
										 |  |  | import sqlConsoleDialog from '../dialogs/sql_console.js'; | 
					
						
							| 
									
										
										
										
											2018-11-08 19:42:57 +01:00
										 |  |  | import markdownImportDialog from '../dialogs/markdown_import.js'; | 
					
						
							| 
									
										
										
										
											2018-11-24 14:44:56 +01:00
										 |  |  | import exportDialog from '../dialogs/export.js'; | 
					
						
							| 
									
										
										
										
											2018-03-24 11:18:46 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-03-25 11:09:17 -04:00
										 |  |  | import cloning from './cloning.js'; | 
					
						
							| 
									
										
										
										
											2018-09-02 23:02:01 +02:00
										 |  |  | import contextMenu from './tree_context_menu.js'; | 
					
						
							| 
									
										
										
										
											2018-03-25 11:09:17 -04:00
										 |  |  | import dragAndDropSetup from './drag_and_drop.js'; | 
					
						
							|  |  |  | import exportService from './export.js'; | 
					
						
							|  |  |  | import link from './link.js'; | 
					
						
							| 
									
										
										
										
											2018-03-27 00:22:02 -04:00
										 |  |  | import messagingService from './messaging.js'; | 
					
						
							| 
									
										
										
										
											2018-03-25 20:18:08 -04:00
										 |  |  | import noteDetailService from './note_detail.js'; | 
					
						
							| 
									
										
										
										
											2018-03-25 11:09:17 -04:00
										 |  |  | import noteType from './note_type.js'; | 
					
						
							|  |  |  | import protected_session from './protected_session.js'; | 
					
						
							| 
									
										
										
										
											2018-06-04 19:48:02 -04:00
										 |  |  | import searchNotesService from './search_notes.js'; | 
					
						
							| 
									
										
										
										
											2018-08-23 12:55:45 +02:00
										 |  |  | import FrontendScriptApi from './frontend_script_api.js'; | 
					
						
							| 
									
										
										
										
											2018-03-25 11:09:17 -04:00
										 |  |  | import ScriptContext from './script_context.js'; | 
					
						
							|  |  |  | import sync from './sync.js'; | 
					
						
							| 
									
										
										
										
											2018-03-25 19:49:33 -04:00
										 |  |  | import treeService from './tree.js'; | 
					
						
							| 
									
										
										
										
											2018-04-01 20:33:10 -04:00
										 |  |  | import treeChanges from './branches.js'; | 
					
						
							| 
									
										
										
										
											2018-03-25 11:09:17 -04:00
										 |  |  | import treeUtils from './tree_utils.js'; | 
					
						
							|  |  |  | import utils from './utils.js'; | 
					
						
							| 
									
										
										
										
											2018-03-25 20:18:08 -04:00
										 |  |  | import server from './server.js'; | 
					
						
							| 
									
										
										
										
											2018-03-26 22:29:14 -04:00
										 |  |  | import entrypoints from './entrypoints.js'; | 
					
						
							|  |  |  | import tooltip from './tooltip.js'; | 
					
						
							|  |  |  | import bundle from "./bundle.js"; | 
					
						
							|  |  |  | import treeCache from "./tree_cache.js"; | 
					
						
							| 
									
										
										
										
											2018-03-27 22:42:46 -04:00
										 |  |  | import libraryLoader from "./library_loader.js"; | 
					
						
							| 
									
										
										
										
											2018-03-24 11:18:46 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-03-25 20:18:08 -04:00
										 |  |  | // required for CKEditor image upload plugin
 | 
					
						
							|  |  |  | window.glob.getCurrentNode = treeService.getCurrentNode; | 
					
						
							|  |  |  | 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
 | 
					
						
							|  |  |  | window.glob.getCurrentNote = noteDetailService.getCurrentNote; | 
					
						
							| 
									
										
										
										
											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
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											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
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											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
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-03-26 22:29:14 -04:00
										 |  |  | if (utils.isElectron()) { | 
					
						
							|  |  |  |     require('electron').ipcRenderer.on('create-day-sub-note', async function(event, parentNoteId) { | 
					
						
							|  |  |  |         // this might occur when day note had to be created
 | 
					
						
							|  |  |  |         if (!await treeCache.getNote(parentNoteId)) { | 
					
						
							|  |  |  |             await treeService.reload(); | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2018-03-25 19:49:33 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-08-23 12:55:45 +02:00
										 |  |  |         await treeService.activateNote(parentNoteId); | 
					
						
							| 
									
										
										
										
											2018-03-24 11:18:46 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-10-15 23:45:37 +02:00
										 |  |  |         setTimeout(async () => { | 
					
						
							|  |  |  |             const parentNode = treeService.getCurrentNode(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             const {note} = await treeService.createNote(parentNode, parentNode.data.noteId, 'into', parentNode.data.isProtected); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             await treeService.activateNote(note.noteId); | 
					
						
							| 
									
										
										
										
											2018-03-24 11:18:46 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-03-26 22:29:14 -04:00
										 |  |  |         }, 500); | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											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
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-03-26 22:29:14 -04:00
										 |  |  | treeService.showTree(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | entrypoints.registerEntrypoints(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | tooltip.setupTooltip(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-04-04 23:51:47 -04:00
										 |  |  | bundle.executeStartupBundles(); |