| 
									
										
										
										
											2017-08-15 22:32:30 -04:00
										 |  |  | $(function() { | 
					
						
							|  |  |  |     $(window).resize(function() { | 
					
						
							| 
									
										
										
										
											2017-09-09 12:06:15 -04:00
										 |  |  |         // dynamically setting height of tree and note content to match window's height
 | 
					
						
							| 
									
										
										
										
											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
										 |  |  | }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-09-09 12:06:15 -04:00
										 |  |  | // hot keys are active also inside inputs and content editables
 | 
					
						
							| 
									
										
										
										
											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-28 23:10:04 -04:00
										 |  |  | $(document).bind('keydown', 'alt+s', function() { | 
					
						
							|  |  |  |     $("input[name=search]").focus(); | 
					
						
							| 
									
										
										
										
											2017-08-29 23:27:28 -04:00
										 |  |  | }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-09-09 12:06:15 -04:00
										 |  |  | // hide (toggle) everything except for the note content for distraction free writing
 | 
					
						
							| 
									
										
										
										
											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
										 |  |  | }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-09-04 16:03:07 -04:00
										 |  |  | $(window).on('beforeunload', function(){ | 
					
						
							| 
									
										
										
										
											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-09-04 16:03:07 -04:00
										 |  |  |     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
 | 
					
						
							|  |  |  | $.ui.autocomplete.filter = function (array, terms) { | 
					
						
							|  |  |  |     const options = { | 
					
						
							|  |  |  |         shouldSort: true, | 
					
						
							|  |  |  |         threshold: 0.6, | 
					
						
							|  |  |  |         location: 0, | 
					
						
							|  |  |  |         distance: 100, | 
					
						
							|  |  |  |         maxPatternLength: 32, | 
					
						
							|  |  |  |         minMatchCharLength: 1, | 
					
						
							|  |  |  |         keys: [ | 
					
						
							|  |  |  |             "value" | 
					
						
							|  |  |  |         ] | 
					
						
							|  |  |  |     }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     const fuse = new Fuse(array, options); // "list" is the item array
 | 
					
						
							|  |  |  |     return fuse.search(terms); | 
					
						
							|  |  |  | }; |