mirror of
				https://github.com/TriliumNext/Notes.git
				synced 2025-10-31 21:11:30 +08:00 
			
		
		
		
	first POC of ES6 module
This commit is contained in:
		
							parent
							
								
									1612e9093d
								
							
						
					
					
						commit
						e3e2dc9fff
					
				
							
								
								
									
										14
									
								
								src/public/javascripts/bootstrap.js
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										14
									
								
								src/public/javascripts/bootstrap.js
									
									
									
									
										vendored
									
									
										Normal file
									
								
							| @ -0,0 +1,14 @@ | |||||||
|  | import searchTree from './search_tree.js'; | ||||||
|  | 
 | ||||||
|  | const $toggleSearchButton = $("#toggle-search-button"); | ||||||
|  | 
 | ||||||
|  | $toggleSearchButton.click(searchTree.toggleSearch); | ||||||
|  | bindShortcut('ctrl+s', searchTree.toggleSearch); | ||||||
|  | 
 | ||||||
|  | function bindShortcut(keyboardShortcut, handler) { | ||||||
|  |     $(document).bind('keydown', keyboardShortcut, e => { | ||||||
|  |         handler(); | ||||||
|  | 
 | ||||||
|  |         e.preventDefault(); | ||||||
|  |     }); | ||||||
|  | } | ||||||
| @ -1,83 +1,73 @@ | |||||||
| "use strict"; | "use strict"; | ||||||
| 
 | 
 | ||||||
| const searchTree = (function() { | const $tree = $("#tree"); | ||||||
|     const $tree = $("#tree"); | const $searchInput = $("input[name='search-text']"); | ||||||
|     const $searchInput = $("input[name='search-text']"); | const $resetSearchButton = $("#reset-search-button"); | ||||||
|     const $resetSearchButton = $("#reset-search-button"); | const $doSearchButton = $("#do-search-button"); | ||||||
|     const $doSearchButton = $("#do-search-button"); | const $saveSearchButton = $("#save-search-button"); | ||||||
|     const $saveSearchButton = $("#save-search-button"); | const $searchBox = $("#search-box"); | ||||||
|     const $searchBox = $("#search-box"); |  | ||||||
|     const $toggleSearchButton = $("#toggle-search-button"); |  | ||||||
| 
 | 
 | ||||||
|     $resetSearchButton.click(resetSearch); | function toggleSearch() { | ||||||
|  |     if ($searchBox.is(":hidden")) { | ||||||
|  |         $searchBox.show(); | ||||||
|  |         $searchInput.focus(); | ||||||
|  |     } | ||||||
|  |     else { | ||||||
|  |         resetSearch(); | ||||||
| 
 | 
 | ||||||
|     function toggleSearch() { |         $searchBox.hide(); | ||||||
|         if ($searchBox.is(":hidden")) { |     } | ||||||
|             $searchBox.show(); | } | ||||||
|             $searchInput.focus(); |  | ||||||
|         } |  | ||||||
|         else { |  | ||||||
|             resetSearch(); |  | ||||||
| 
 | 
 | ||||||
|             $searchBox.hide(); | function resetSearch() { | ||||||
|         } |     $searchInput.val(""); | ||||||
|  | 
 | ||||||
|  |     getTree().clearFilter(); | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | function getTree() { | ||||||
|  |     return $tree.fancytree('getTree'); | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | async function doSearch() { | ||||||
|  |     const searchText = $searchInput.val(); | ||||||
|  | 
 | ||||||
|  |     const noteIds = await server.get('search/' + encodeURIComponent(searchText)); | ||||||
|  | 
 | ||||||
|  |     for (const noteId of noteIds) { | ||||||
|  |         await noteTree.expandToNote(noteId, {noAnimation: true, noEvents: true}); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     function resetSearch() { |     // Pass a string to perform case insensitive matching
 | ||||||
|         $searchInput.val(""); |     getTree().filterBranches(node => noteIds.includes(node.data.noteId)); | ||||||
|  | } | ||||||
| 
 | 
 | ||||||
|         getTree().clearFilter(); | async function saveSearch() { | ||||||
|  |     const {noteId} = await server.post('search/' + encodeURIComponent($searchInput.val())); | ||||||
|  | 
 | ||||||
|  |     await noteTree.reload(); | ||||||
|  | 
 | ||||||
|  |     await noteTree.activateNode(noteId); | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | $searchInput.keyup(e => { | ||||||
|  |     const searchText = $searchInput.val(); | ||||||
|  | 
 | ||||||
|  |     if (e && e.which === $.ui.keyCode.ESCAPE || $.trim(searchText) === "") { | ||||||
|  |         $resetSearchButton.click(); | ||||||
|  |         return; | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     function getTree() { |     if (e && e.which === $.ui.keyCode.ENTER) { | ||||||
|         return $tree.fancytree('getTree'); |         doSearch(); | ||||||
|     } |     } | ||||||
|  | }).focus(); | ||||||
| 
 | 
 | ||||||
|     async function doSearch() { | $doSearchButton.click(doSearch); | ||||||
|         const searchText = $searchInput.val(); | $resetSearchButton.click(resetSearch); | ||||||
| 
 | 
 | ||||||
|         const noteIds = await server.get('search/' + encodeURIComponent(searchText)); | $saveSearchButton.click(saveSearch); | ||||||
| 
 | 
 | ||||||
|         for (const noteId of noteIds) { | export default { | ||||||
|             await noteTree.expandToNote(noteId, {noAnimation: true, noEvents: true}); |     toggleSearch | ||||||
|         } | }; | ||||||
| 
 |  | ||||||
|         // Pass a string to perform case insensitive matching
 |  | ||||||
|         getTree().filterBranches(node => noteIds.includes(node.data.noteId)); |  | ||||||
|     } |  | ||||||
| 
 |  | ||||||
|     $searchInput.keyup(e => { |  | ||||||
|         const searchText = $searchInput.val(); |  | ||||||
| 
 |  | ||||||
|         if (e && e.which === $.ui.keyCode.ESCAPE || $.trim(searchText) === "") { |  | ||||||
|             $resetSearchButton.click(); |  | ||||||
|             return; |  | ||||||
|         } |  | ||||||
| 
 |  | ||||||
|         if (e && e.which === $.ui.keyCode.ENTER) { |  | ||||||
|             doSearch(); |  | ||||||
|         } |  | ||||||
|     }).focus(); |  | ||||||
| 
 |  | ||||||
|     $doSearchButton.click(doSearch); |  | ||||||
| 
 |  | ||||||
|     $saveSearchButton.click(async () => { |  | ||||||
|         const {noteId} = await server.post('search/' + encodeURIComponent($searchInput.val())); |  | ||||||
| 
 |  | ||||||
|         await noteTree.reload(); |  | ||||||
| 
 |  | ||||||
|         await noteTree.activateNode(noteId); |  | ||||||
|     }); |  | ||||||
| 
 |  | ||||||
|     $(document).bind('keydown', 'ctrl+s', e => { |  | ||||||
|         toggleSearch(); |  | ||||||
| 
 |  | ||||||
|         e.preventDefault(); |  | ||||||
|     }); |  | ||||||
| 
 |  | ||||||
|     $toggleSearchButton.click(toggleSearch); |  | ||||||
| 
 |  | ||||||
|     return { |  | ||||||
|         toggleSearch |  | ||||||
|     }; |  | ||||||
| })(); |  | ||||||
| @ -519,6 +519,8 @@ | |||||||
| 
 | 
 | ||||||
|     <link href="stylesheets/style.css" rel="stylesheet"> |     <link href="stylesheets/style.css" rel="stylesheet"> | ||||||
| 
 | 
 | ||||||
|  |     <script src="javascripts/bootstrap.js" type="module"></script> | ||||||
|  | 
 | ||||||
|     <script src="javascripts/utils.js"></script> |     <script src="javascripts/utils.js"></script> | ||||||
|     <script src="javascripts/init.js"></script> |     <script src="javascripts/init.js"></script> | ||||||
|     <script src="javascripts/server.js"></script> |     <script src="javascripts/server.js"></script> | ||||||
| @ -530,7 +532,6 @@ | |||||||
|     <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> |  | ||||||
|     <script src="javascripts/export.js"></script> |     <script src="javascripts/export.js"></script> | ||||||
| 
 | 
 | ||||||
|     <!-- Note detail --> |     <!-- Note detail --> | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user
	 azivner
						azivner