| 
									
										
										
										
											2017-08-15 22:32:30 -04:00
										 |  |  | $(function() { | 
					
						
							|  |  |  |     $(window).resize(function() { | 
					
						
							| 
									
										
										
										
											2017-08-27 14:44:12 -04:00
										 |  |  |         const fancyTree = $('ul.fancytree-container'); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         if (fancyTree.length) { | 
					
						
							|  |  |  |             fancyTree.height($(window).height() - fancyTree.offset().top - 10); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         const noteEditable = $('div.note-editable'); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         if (noteEditable.length) { | 
					
						
							|  |  |  |             noteEditable.height($(window).height() - noteEditable.offset().top); | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2017-08-15 22:32:30 -04:00
										 |  |  |     }); | 
					
						
							|  |  |  |     $(window).resize(); | 
					
						
							| 
									
										
										
										
											2017-08-21 22:04:08 -04:00
										 |  |  | }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | jQuery.hotkeys.options.filterInputAcceptingElements = true; | 
					
						
							|  |  |  | jQuery.hotkeys.options.filterContentEditable = true; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-08-29 21:07:02 -04:00
										 |  |  | $(document).bind('keydown', 'alt+h', function() { | 
					
						
							| 
									
										
										
										
											2017-08-21 22:04:08 -04:00
										 |  |  |     const toggle = $(".hide-toggle"); | 
					
						
							| 
									
										
										
										
											2017-08-29 21:07:02 -04:00
										 |  |  |     const hidden = toggle.css('display') === 'none'; | 
					
						
							| 
									
										
										
										
											2017-08-21 22:04:08 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-08-29 21:07:02 -04:00
										 |  |  |     toggle.css('display', hidden ? 'block' : 'none'); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     $("#noteDetailWrapper").css("width", hidden ? "750px" : "100%"); | 
					
						
							| 
									
										
										
										
											2017-08-22 22:40:54 -04:00
										 |  |  | }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-08-24 22:48:00 -04:00
										 |  |  | $(document).bind('keydown', 'alt+q', function() { | 
					
						
							| 
									
										
										
										
											2017-08-22 22:40:54 -04:00
										 |  |  |     $("#recentNotesDialog").dialog({ | 
					
						
							| 
									
										
										
										
											2017-09-03 15:08:17 -04:00
										 |  |  |         modal: true, | 
					
						
							|  |  |  |         width: 500 | 
					
						
							| 
									
										
										
										
											2017-08-22 22:40:54 -04:00
										 |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     let recentNotesSelectBox = $('#recentNotesSelectBox'); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     recentNotesSelectBox.find('option').remove(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     // remove the current note
 | 
					
						
							| 
									
										
										
										
											2017-08-27 10:30:32 -04:00
										 |  |  |     let recNotes = recentNotes.filter(note => note !== globalNote.detail.note_id); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     $.each(recNotes, function(key, valueNoteId) { | 
					
						
							| 
									
										
										
										
											2017-09-03 15:08:17 -04:00
										 |  |  |         let noteTitle = getFullName(valueNoteId); | 
					
						
							| 
									
										
										
										
											2017-08-27 10:30:32 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  |         if (!noteTitle) { | 
					
						
							|  |  |  |             return; | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2017-08-22 22:40:54 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  |         let option = $("<option></option>") | 
					
						
							| 
									
										
										
										
											2017-08-27 10:30:32 -04:00
										 |  |  |                 .attr("value", valueNoteId) | 
					
						
							|  |  |  |                 .text(noteTitle); | 
					
						
							| 
									
										
										
										
											2017-08-22 22:40:54 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  |         // select the first one (most recent one) by default
 | 
					
						
							|  |  |  |         if (key === 0) { | 
					
						
							|  |  |  |             option.attr("selected", "selected"); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         recentNotesSelectBox.append(option); | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  | }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-08-23 18:47:37 -04:00
										 |  |  | function setActiveNoteBasedOnRecentNotes() { | 
					
						
							|  |  |  |     let noteId = $("#recentNotesSelectBox option:selected").val(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-09-03 15:08:17 -04:00
										 |  |  |     getNodeByKey(noteId).setActive(); | 
					
						
							| 
									
										
										
										
											2017-08-23 18:47:37 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  |     $("#recentNotesDialog").dialog('close'); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-08-22 22:40:54 -04:00
										 |  |  | $('#recentNotesSelectBox').keydown(function(e) { | 
					
						
							|  |  |  |     let key = e.which; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (key === 13)// the enter key code
 | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2017-08-23 18:47:37 -04:00
										 |  |  |         setActiveNoteBasedOnRecentNotes(); | 
					
						
							| 
									
										
										
										
											2017-08-22 22:40:54 -04:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2017-08-23 18:47:37 -04:00
										 |  |  | }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | $('#recentNotesSelectBox').dblclick(function(e) { | 
					
						
							|  |  |  |     setActiveNoteBasedOnRecentNotes(); | 
					
						
							| 
									
										
										
										
											2017-08-27 14:57:03 -04:00
										 |  |  | }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // when click on link popup, in case of internal link, just go the the referenced note instead of default behavior
 | 
					
						
							|  |  |  | // of opening the link in new window/tab
 | 
					
						
							|  |  |  | $(document).on('click', 'div.popover-content a', function(e) { | 
					
						
							|  |  |  |     const targetUrl = $(e.target).attr("href"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     const noteIdMatch = /app#([A-Za-z0-9]{22})/.exec(targetUrl); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (noteIdMatch !== null) { | 
					
						
							|  |  |  |         const noteId = noteIdMatch[1]; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-09-03 15:08:17 -04:00
										 |  |  |         getNodeByKey(noteId).setActive(); | 
					
						
							| 
									
										
										
										
											2017-08-27 14:57:03 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  |         e.preventDefault(); | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2017-08-27 23:45:01 -04:00
										 |  |  | }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-09-03 15:08:17 -04:00
										 |  |  | function getNodeIdFromLabel(label) { | 
					
						
							|  |  |  |     const noteIdMatch = / \(([A-Za-z0-9]{22})\)/.exec(label); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (noteIdMatch !== null) { | 
					
						
							|  |  |  |         return noteIdMatch[1]; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     return null; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-09-03 21:34:30 -04:00
										 |  |  | function getAutocompleteItems() { | 
					
						
							|  |  |  |     const autocompleteItems = []; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     for (const noteId of globalAllNoteIds) { | 
					
						
							|  |  |  |         const fullName = getFullName(noteId); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         autocompleteItems.push({ | 
					
						
							|  |  |  |             value: fullName + " (" + noteId + ")", | 
					
						
							|  |  |  |             label: fullName | 
					
						
							|  |  |  |         }); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     return autocompleteItems; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-08-27 23:45:01 -04:00
										 |  |  | $(document).bind('keydown', 'alt+l', function() { | 
					
						
							| 
									
										
										
										
											2017-08-28 21:59:47 -04:00
										 |  |  |     $("#noteAutocomplete").val(''); | 
					
						
							|  |  |  |     $("#linkTitle").val(''); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-08-28 21:50:20 -04:00
										 |  |  |     const noteDetail = $('#noteDetail'); | 
					
						
							|  |  |  |     noteDetail.summernote('editor.saveRange'); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-08-27 23:45:01 -04:00
										 |  |  |     $("#insertLinkDialog").dialog({ | 
					
						
							| 
									
										
										
										
											2017-09-03 15:08:17 -04:00
										 |  |  |         modal: true, | 
					
						
							|  |  |  |         width: 500 | 
					
						
							| 
									
										
										
										
											2017-08-27 23:45:01 -04:00
										 |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-09-03 19:15:50 -04:00
										 |  |  |     function setDefaultLinkTitle(noteId) { | 
					
						
							|  |  |  |         const note = getNodeByKey(noteId); | 
					
						
							|  |  |  |         if (!note) { | 
					
						
							|  |  |  |             return; | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2017-08-27 23:45:01 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-09-03 19:15:50 -04:00
										 |  |  |         let noteTitle = note.title; | 
					
						
							| 
									
										
										
										
											2017-08-27 23:45:01 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-09-03 19:15:50 -04:00
										 |  |  |         if (noteTitle.endsWith(" (clone)")) { | 
					
						
							|  |  |  |             noteTitle = noteTitle.substr(0, noteTitle.length - 8); | 
					
						
							| 
									
										
										
										
											2017-08-27 23:45:01 -04:00
										 |  |  |         } | 
					
						
							| 
									
										
										
										
											2017-09-03 19:15:50 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  |         $("#linkTitle").val(noteTitle); | 
					
						
							| 
									
										
										
										
											2017-09-03 15:08:17 -04:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     $("#noteAutocomplete").autocomplete({ | 
					
						
							| 
									
										
										
										
											2017-09-03 21:34:30 -04:00
										 |  |  |         source: getAutocompleteItems(), | 
					
						
							| 
									
										
										
										
											2017-09-03 15:08:17 -04:00
										 |  |  |         minLength: 0, | 
					
						
							| 
									
										
										
										
											2017-09-03 19:15:50 -04:00
										 |  |  |         change: function () { | 
					
						
							|  |  |  |             const val = $("#noteAutocomplete").val(); | 
					
						
							|  |  |  |             const noteId = getNodeIdFromLabel(val); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             if (noteId) { | 
					
						
							|  |  |  |                 setDefaultLinkTitle(noteId); | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |         }, | 
					
						
							|  |  |  |         // this is called when user goes through autocomplete list with keyboard
 | 
					
						
							|  |  |  |         // at this point the item isn't selected yet so we use supplied ui.item to see where the cursor is
 | 
					
						
							|  |  |  |         focus: function (event, ui) { | 
					
						
							|  |  |  |             const noteId = getNodeIdFromLabel(ui.item.value); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             setDefaultLinkTitle(noteId); | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2017-08-27 23:45:01 -04:00
										 |  |  |     }); | 
					
						
							|  |  |  | }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-09-03 21:34:30 -04:00
										 |  |  | $("#insertLinkForm").submit(function() { | 
					
						
							| 
									
										
										
										
											2017-08-27 23:45:01 -04:00
										 |  |  |     let val = $("#noteAutocomplete").val(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-09-03 15:08:17 -04:00
										 |  |  |     const noteId = getNodeIdFromLabel(val); | 
					
						
							| 
									
										
										
										
											2017-08-27 23:45:01 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-09-03 15:08:17 -04:00
										 |  |  |     if (noteId) { | 
					
						
							| 
									
										
										
										
											2017-08-27 23:45:01 -04:00
										 |  |  |         const linkTitle = $("#linkTitle").val(); | 
					
						
							|  |  |  |         const noteDetail = $('#noteDetail'); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-08-28 21:50:20 -04:00
										 |  |  |         $("#insertLinkDialog").dialog("close"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         noteDetail.summernote('editor.restoreRange'); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-08-27 23:45:01 -04:00
										 |  |  |         noteDetail.summernote('createLink', { | 
					
						
							| 
									
										
										
										
											2017-08-28 22:01:02 -04:00
										 |  |  |             text: linkTitle, | 
					
						
							| 
									
										
										
										
											2017-08-27 23:45:01 -04:00
										 |  |  |             url: 'app#' + noteId, | 
					
						
							|  |  |  |             isNewWindow: true | 
					
						
							|  |  |  |         }); | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2017-09-03 19:43:03 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  |     return false; | 
					
						
							| 
									
										
										
										
											2017-08-28 23:10:04 -04:00
										 |  |  | }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | $(document).bind('keydown', 'alt+s', function() { | 
					
						
							|  |  |  |     $("input[name=search]").focus(); | 
					
						
							| 
									
										
										
										
											2017-08-29 23:27:28 -04:00
										 |  |  | }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | $(document).bind('keydown', 'alt+t', function() { | 
					
						
							|  |  |  |     const date = new Date(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     const dateString = date.getDate() + ". " + (date.getMonth() + 1) + ". " + date.getFullYear() + " " + | 
					
						
							|  |  |  |         date.getHours() + ":" + date.getMinutes(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     $('#noteDetail').summernote('insertText', dateString); | 
					
						
							| 
									
										
										
										
											2017-09-03 21:34:30 -04:00
										 |  |  | }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | $(document).bind('keydown', 'alt+j', function() { | 
					
						
							|  |  |  |     $("#jumpToNoteAutocomplete").val(''); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     $("#jumpToNoteDialog").dialog({ | 
					
						
							|  |  |  |         modal: true, | 
					
						
							|  |  |  |         width: 500 | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     $("#jumpToNoteAutocomplete").autocomplete({ | 
					
						
							|  |  |  |         source: getAutocompleteItems(), | 
					
						
							|  |  |  |         minLength: 0 | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  | }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | $("#jumpToNoteForm").submit(function() { | 
					
						
							|  |  |  |     const val = $("#jumpToNoteAutocomplete").val(); | 
					
						
							|  |  |  |     const noteId = getNodeIdFromLabel(val); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (noteId) { | 
					
						
							|  |  |  |         getNodeByKey(noteId).setActive(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         $("#jumpToNoteDialog").dialog('close'); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     return false; | 
					
						
							| 
									
										
										
										
											2017-09-04 16:03:07 -04:00
										 |  |  | }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | $(window).on('beforeunload', function(){ | 
					
						
							|  |  |  |     // asynchronously send the request and don't wait for result
 | 
					
						
							|  |  |  |     saveNoteIfChanged(); | 
					
						
							| 
									
										
										
										
											2017-08-15 22:32:30 -04:00
										 |  |  | }); |