| 
									
										
										
										
											2017-11-04 19:38:50 -04:00
										 |  |  | "use strict"; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-09-09 12:06:15 -04:00
										 |  |  | // hot keys are active also inside inputs and content editables
 | 
					
						
							| 
									
										
										
										
											2017-12-18 23:41:13 -05:00
										 |  |  | jQuery.hotkeys.options.filterInputAcceptingElements = false; | 
					
						
							|  |  |  | jQuery.hotkeys.options.filterContentEditable = false; | 
					
						
							|  |  |  | jQuery.hotkeys.options.filterTextInputs = false; | 
					
						
							| 
									
										
										
										
											2017-08-21 22:04:08 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-12-18 23:41:13 -05:00
										 |  |  | $(document).bind('keydown', 'alt+m', e => { | 
					
						
							| 
									
										
										
										
											2018-01-02 20:52:36 -05:00
										 |  |  |     $(".hide-toggle").toggleClass("suppressed"); | 
					
						
							| 
									
										
										
										
											2017-12-18 23:41:13 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  |     e.preventDefault(); | 
					
						
							| 
									
										
										
										
											2017-09-23 10:18:08 -04:00
										 |  |  | }); | 
					
						
							| 
									
										
										
										
											2017-08-22 22:40:54 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-09-09 12:06:15 -04:00
										 |  |  | // hide (toggle) everything except for the note content for distraction free writing
 | 
					
						
							| 
									
										
										
										
											2017-12-18 23:41:13 -05:00
										 |  |  | $(document).bind('keydown', 'alt+t', e => { | 
					
						
							| 
									
										
										
										
											2017-08-29 23:27:28 -04:00
										 |  |  |     const date = new Date(); | 
					
						
							| 
									
										
										
										
											2017-09-26 23:23:03 -04:00
										 |  |  |     const dateString = formatDateTime(date); | 
					
						
							| 
									
										
										
										
											2017-08-29 23:27:28 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-12-09 14:17:03 -05:00
										 |  |  |     link.addTextToEditor(dateString); | 
					
						
							| 
									
										
										
										
											2017-12-18 23:41:13 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  |     e.preventDefault(); | 
					
						
							| 
									
										
										
										
											2017-09-03 21:34:30 -04:00
										 |  |  | }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-16 19:43:34 -05:00
										 |  |  | $(document).bind('keydown', 'f5', () => { | 
					
						
							| 
									
										
										
										
											2017-11-29 23:30:35 -05:00
										 |  |  |     reloadApp(); | 
					
						
							| 
									
										
										
										
											2017-11-20 23:10:04 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  |     return false; | 
					
						
							|  |  |  | }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | $(document).bind('keydown', 'ctrl+r', () => { | 
					
						
							| 
									
										
										
										
											2017-11-29 23:30:35 -05:00
										 |  |  |     reloadApp(); | 
					
						
							| 
									
										
										
										
											2017-11-16 19:43:34 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  |     return false; | 
					
						
							|  |  |  | }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | $(document).bind('keydown', 'ctrl+shift+i', () => { | 
					
						
							|  |  |  |     if (isElectron()) { | 
					
						
							| 
									
										
										
										
											2017-11-20 23:10:04 -05:00
										 |  |  |         require('electron').remote.getCurrentWindow().toggleDevTools(); | 
					
						
							| 
									
										
										
										
											2017-11-16 19:43:34 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  |         return false; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-12-12 21:40:55 -05:00
										 |  |  | $(document).bind('keydown', 'ctrl+f', () => { | 
					
						
							|  |  |  |     if (isElectron()) { | 
					
						
							|  |  |  |         const searchInPage = require('electron-in-page-search').default; | 
					
						
							|  |  |  |         const remote = require('electron').remote; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-12-26 22:24:47 -05:00
										 |  |  |         const inPageSearch = searchInPage(remote.getCurrentWebContents()); | 
					
						
							| 
									
										
										
										
											2017-12-12 21:40:55 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  |         inPageSearch.openSearchWindow(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         return false; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-12-28 20:38:57 -05:00
										 |  |  | $(document).bind('keydown', "ctrl+shift+left", () => { | 
					
						
							|  |  |  |     const node = noteTree.getCurrentNode(); | 
					
						
							|  |  |  |     node.navigate($.ui.keyCode.LEFT, true); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     $("#note-detail").focus(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     return false; | 
					
						
							|  |  |  | }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | $(document).bind('keydown', "ctrl+shift+right", () => { | 
					
						
							|  |  |  |     const node = noteTree.getCurrentNode(); | 
					
						
							|  |  |  |     node.navigate($.ui.keyCode.RIGHT, true); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     $("#note-detail").focus(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     return false; | 
					
						
							|  |  |  | }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | $(document).bind('keydown', "ctrl+shift+up", () => { | 
					
						
							|  |  |  |     const node = noteTree.getCurrentNode(); | 
					
						
							|  |  |  |     node.navigate($.ui.keyCode.UP, true); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     $("#note-detail").focus(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     return false; | 
					
						
							|  |  |  | }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | $(document).bind('keydown', "ctrl+shift+down", () => { | 
					
						
							|  |  |  |     const node = noteTree.getCurrentNode(); | 
					
						
							|  |  |  |     node.navigate($.ui.keyCode.DOWN, true); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     $("#note-detail").focus(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     return false; | 
					
						
							|  |  |  | }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-01-06 22:53:37 -05:00
										 |  |  | $("#note-title").bind('keydown', 'return', () => $("#note-detail").focus()); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-10-09 18:53:11 -04:00
										 |  |  | $(window).on('beforeunload', () => { | 
					
						
							| 
									
										
										
										
											2017-09-09 12:06:15 -04:00
										 |  |  |     // this makes sure that when user e.g. reloads the page or navigates away from the page, the note's content is saved
 | 
					
						
							|  |  |  |     // this sends the request asynchronously and doesn't wait for result
 | 
					
						
							| 
									
										
										
										
											2017-11-04 17:54:27 -04:00
										 |  |  |     noteEditor.saveNoteIfChanged(); | 
					
						
							| 
									
										
										
										
											2017-09-10 11:50:17 -04:00
										 |  |  | }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // Overrides the default autocomplete filter function to search for matched on atleast 1 word in each of the input term's words
 | 
					
						
							| 
									
										
										
										
											2017-10-09 18:53:11 -04:00
										 |  |  | $.ui.autocomplete.filter = (array, terms) => { | 
					
						
							| 
									
										
										
										
											2017-09-18 20:07:56 -04:00
										 |  |  |     if (!terms) { | 
					
						
							|  |  |  |         return []; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     const startDate = new Date(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     const results = []; | 
					
						
							|  |  |  |     const tokens = terms.toLowerCase().split(" "); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     for (const item of array) { | 
					
						
							|  |  |  |         let found = true; | 
					
						
							| 
									
										
										
										
											2017-11-19 19:39:39 -05:00
										 |  |  |         const lcLabel = item.label.toLowerCase(); | 
					
						
							| 
									
										
										
										
											2017-09-18 20:07:56 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  |         for (const token of tokens) { | 
					
						
							| 
									
										
										
										
											2017-11-19 19:39:39 -05:00
										 |  |  |             if (lcLabel.indexOf(token) === -1) { | 
					
						
							| 
									
										
										
										
											2017-09-18 20:07:56 -04:00
										 |  |  |                 found = false; | 
					
						
							|  |  |  |                 break; | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         if (found) { | 
					
						
							|  |  |  |             results.push(item); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     console.log("Search took " + (new Date().getTime() - startDate.getTime()) + "ms"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     return results; | 
					
						
							| 
									
										
										
										
											2017-10-11 20:37:27 -04:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | $(document).tooltip({ | 
					
						
							| 
									
										
										
										
											2017-12-02 13:54:16 -05:00
										 |  |  |     items: "#note-detail a", | 
					
						
							| 
									
										
										
										
											2017-10-11 20:37:27 -04:00
										 |  |  |     content: function(callback) { | 
					
						
							| 
									
										
										
										
											2017-12-17 17:37:19 -05:00
										 |  |  |         const notePath = link.getNotePathFromLink($(this).attr("href")); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         if (notePath !== null) { | 
					
						
							|  |  |  |             const noteId = treeUtils.getNoteIdFromNotePath(notePath); | 
					
						
							| 
									
										
										
										
											2017-10-11 20:37:27 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-04 17:54:27 -04:00
										 |  |  |             noteEditor.loadNote(noteId).then(note => callback(note.detail.note_text)); | 
					
						
							| 
									
										
										
										
											2017-10-11 20:37:27 -04:00
										 |  |  |         } | 
					
						
							|  |  |  |     }, | 
					
						
							|  |  |  |     close: function(event, ui) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         ui.tooltip.hover(function() | 
					
						
							|  |  |  |         { | 
					
						
							|  |  |  |             $(this).stop(true).fadeTo(400, 1); | 
					
						
							|  |  |  |         }, | 
					
						
							|  |  |  |         function() | 
					
						
							|  |  |  |         { | 
					
						
							|  |  |  |             $(this).fadeOut('400', function() | 
					
						
							|  |  |  |             { | 
					
						
							|  |  |  |                 $(this).remove(); | 
					
						
							|  |  |  |             }); | 
					
						
							|  |  |  |         }); | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2017-10-20 23:43:20 -04:00
										 |  |  | }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-12-01 22:28:22 -05:00
										 |  |  | window.onerror = function (msg, url, lineNo, columnNo, error) { | 
					
						
							|  |  |  |     const string = msg.toLowerCase(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     let message = "Uncaught error: "; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (string.indexOf("script error") > -1){ | 
					
						
							|  |  |  |         message += 'No details available'; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     else { | 
					
						
							|  |  |  |         message += [ | 
					
						
							|  |  |  |             'Message: ' + msg, | 
					
						
							|  |  |  |             'URL: ' + url, | 
					
						
							|  |  |  |             'Line: ' + lineNo, | 
					
						
							|  |  |  |             'Column: ' + columnNo, | 
					
						
							|  |  |  |             'Error object: ' + JSON.stringify(error) | 
					
						
							|  |  |  |         ].join(' - '); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     messaging.logError(message); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     return false; | 
					
						
							| 
									
										
										
										
											2017-12-26 22:19:42 -05:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | $("#logout-button").toggle(!isElectron()); |