mirror of
				https://github.com/TriliumNext/Notes.git
				synced 2025-10-31 21:11:30 +08:00 
			
		
		
		
	moved search into separate file
This commit is contained in:
		
							parent
							
								
									5b2c18dab7
								
							
						
					
					
						commit
						c72e5ef93b
					
				| @ -305,8 +305,6 @@ const noteTree = (function() { | |||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     function initFancyTree(noteTree) { |     function initFancyTree(noteTree) { | ||||||
|         console.log(noteTree); |  | ||||||
| 
 |  | ||||||
|         const keybindings = { |         const keybindings = { | ||||||
|             "insert": node => { |             "insert": node => { | ||||||
|                 const parentNoteId = node.data.note_pid; |                 const parentNoteId = node.data.note_pid; | ||||||
| @ -493,30 +491,6 @@ const noteTree = (function() { | |||||||
|         } |         } | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     function showSearch() { |  | ||||||
|         $("#search-box").show(); |  | ||||||
| 
 |  | ||||||
|         $("input[name=search]").focus(); |  | ||||||
|     } |  | ||||||
| 
 |  | ||||||
|     function toggleSearch() { |  | ||||||
|         if ($("#search-box:hidden").length) { |  | ||||||
|             showSearch(); |  | ||||||
|         } |  | ||||||
|         else { |  | ||||||
|             resetSearch(); |  | ||||||
| 
 |  | ||||||
|             $("#search-box").hide(); |  | ||||||
|         } |  | ||||||
|     } |  | ||||||
| 
 |  | ||||||
|     function resetSearch() { |  | ||||||
|         $("input[name=search]").val(""); |  | ||||||
| 
 |  | ||||||
|         const tree = getTree(); |  | ||||||
|         tree.clearFilter(); |  | ||||||
|     } |  | ||||||
| 
 |  | ||||||
|     function setCurrentNoteTreeBasedOnProtectedStatus() { |     function setCurrentNoteTreeBasedOnProtectedStatus() { | ||||||
|         getCurrentClones().map(node => node.toggleClass("protected", !!node.data.is_protected)); |         getCurrentClones().map(node => node.toggleClass("protected", !!node.data.is_protected)); | ||||||
|     } |     } | ||||||
| @ -627,36 +601,11 @@ const noteTree = (function() { | |||||||
|         showMessage("Created!"); |         showMessage("Created!"); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     $("button#reset-search-button").click(resetSearch); |  | ||||||
| 
 |  | ||||||
|     $("input[name=search]").keyup(e => { |  | ||||||
|         const searchString = $("input[name=search]").val(); |  | ||||||
| 
 |  | ||||||
|         if (e && e.which === $.ui.keyCode.ESCAPE || $.trim(searchString) === "") { |  | ||||||
|             $("button#reset-search-button").click(); |  | ||||||
|             return; |  | ||||||
|         } |  | ||||||
| 
 |  | ||||||
|         if (e && e.which === $.ui.keyCode.ENTER) { |  | ||||||
|             $.get(baseApiUrl + 'notes?search=' + searchString).then(resp => { |  | ||||||
|                 console.log("search: ", resp); |  | ||||||
| 
 |  | ||||||
|                 // Pass a string to perform case insensitive matching
 |  | ||||||
|                 getTree().filterBranches(node => { |  | ||||||
|                     return resp.includes(node.data.note_id); |  | ||||||
|                 }); |  | ||||||
|             }); |  | ||||||
|         } |  | ||||||
|     }).focus(); |  | ||||||
| 
 |  | ||||||
|     $(document).bind('keydown', 'alt+s', showSearch); |  | ||||||
| 
 |  | ||||||
|     return { |     return { | ||||||
|         getTreeLoadTime, |         getTreeLoadTime, | ||||||
|         reload, |         reload, | ||||||
|         collapseTree, |         collapseTree, | ||||||
|         scrollToCurrentNote, |         scrollToCurrentNote, | ||||||
|         toggleSearch, |  | ||||||
|         setCurrentNoteTreeBasedOnProtectedStatus, |         setCurrentNoteTreeBasedOnProtectedStatus, | ||||||
|         getCurrentNode, |         getCurrentNode, | ||||||
|         activateNode, |         activateNode, | ||||||
|  | |||||||
							
								
								
									
										60
									
								
								public/javascripts/search_tree.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										60
									
								
								public/javascripts/search_tree.js
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,60 @@ | |||||||
|  | "use strict"; | ||||||
|  | 
 | ||||||
|  | const searchTree = (function() { | ||||||
|  |     const treeEl = $("#tree"); | ||||||
|  |     const searchInputEl = $("input[name='search-text']"); | ||||||
|  |     const resetSearchButton = $("button#reset-search-button"); | ||||||
|  |     const searchBoxEl = $("#search-box"); | ||||||
|  | 
 | ||||||
|  |     resetSearchButton.click(resetSearch); | ||||||
|  | 
 | ||||||
|  |     function showSearch() { | ||||||
|  |         searchBoxEl.show(); | ||||||
|  |         searchInputEl.focus(); | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     function toggleSearch() { | ||||||
|  |         if (searchBoxEl.is(":hidden")) { | ||||||
|  |             showSearch(); | ||||||
|  |         } | ||||||
|  |         else { | ||||||
|  |             resetSearch(); | ||||||
|  | 
 | ||||||
|  |             searchBoxEl.hide(); | ||||||
|  |         } | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     function resetSearch() { | ||||||
|  |         searchInputEl.val(""); | ||||||
|  | 
 | ||||||
|  |         getTree().clearFilter(); | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     function getTree() { | ||||||
|  |         return treeEl.fancytree('getTree'); | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     searchInputEl.keyup(e => { | ||||||
|  |         const searchText = searchInputEl.val(); | ||||||
|  | 
 | ||||||
|  |         if (e && e.which === $.ui.keyCode.ESCAPE || $.trim(searchText) === "") { | ||||||
|  |             resetSearchButton.click(); | ||||||
|  |             return; | ||||||
|  |         } | ||||||
|  | 
 | ||||||
|  |         if (e && e.which === $.ui.keyCode.ENTER) { | ||||||
|  |             $.get(baseApiUrl + 'notes?search=' + searchText).then(resp => { | ||||||
|  |                 // Pass a string to perform case insensitive matching
 | ||||||
|  |                 getTree().filterBranches(node => { | ||||||
|  |                     return resp.includes(node.data.note_id); | ||||||
|  |                 }); | ||||||
|  |             }); | ||||||
|  |         } | ||||||
|  |     }).focus(); | ||||||
|  | 
 | ||||||
|  |     $(document).bind('keydown', 'alt+s', showSearch); | ||||||
|  | 
 | ||||||
|  |     return { | ||||||
|  |         toggleSearch | ||||||
|  |     }; | ||||||
|  | })(); | ||||||
| @ -49,14 +49,14 @@ | |||||||
|           <img src="images/icons/crosshair.png" alt="Collapse tree"/> |           <img src="images/icons/crosshair.png" alt="Collapse tree"/> | ||||||
|         </a> |         </a> | ||||||
| 
 | 
 | ||||||
|         <a onclick="noteTree.toggleSearch()" title="Search in notes" class="icon-action"> |         <a onclick="searchTree.toggleSearch()" title="Search in notes" class="icon-action"> | ||||||
|           <img src="images/icons/search.png" alt="Search in notes"/> |           <img src="images/icons/search.png" alt="Search in notes"/> | ||||||
|         </a> |         </a> | ||||||
| 
 | 
 | ||||||
|         <div id="search-box" style="display: none; padding: 10px; margin-top: 10px;"> |         <div id="search-box" style="display: none; padding: 10px; margin-top: 10px;"> | ||||||
|           <p> |           <p> | ||||||
|             <label>Search:</label> |             <label>Search:</label> | ||||||
|             <input name="search" autocomplete="off"> |             <input name="search-text" autocomplete="off"> | ||||||
|             <button id="reset-search-button">×</button> |             <button id="reset-search-button">×</button> | ||||||
|             <span id="matches"></span> |             <span id="matches"></span> | ||||||
|           </p> |           </p> | ||||||
| @ -300,6 +300,7 @@ | |||||||
|     <script src="javascripts/tree_utils.js"></script> |     <script src="javascripts/tree_utils.js"></script> | ||||||
|     <script src="javascripts/drag_and_drop.js"></script> |     <script src="javascripts/drag_and_drop.js"></script> | ||||||
|     <script src="javascripts/context_menu.js"></script> |     <script src="javascripts/context_menu.js"></script> | ||||||
|  |     <script src="javascripts/search_tree.js"></script> | ||||||
| 
 | 
 | ||||||
|     <!-- Note detail --> |     <!-- Note detail --> | ||||||
|     <script src="javascripts/note_editor.js"></script> |     <script src="javascripts/note_editor.js"></script> | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user
	 azivner
						azivner