Build your personal knowledge base with Trilium Notes
TypeScript electronelectron-appknowledge-baseknowledge-graphknowledge-managementknowledge-management-graphlocal-firstnote-managmentnote-takernote-takingnotebooknotesnotes-apppersonal-knowledge-basepersonal-wikiscriptableself-hostedself-hostingwiki
first POC of ES6 module
azivnere3e2dc9fffe2
diff --git a/src/public/javascripts/bootstrap.js b/src/public/javascripts/bootstrap.jsnew file mode 100644index 0000000000..d858b0f12d--- /dev/null+++ b/src/public/javascripts/bootstrap.js@@ -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();+ });+}\ No newline at end of filediff --git a/src/public/javascripts/search_tree.js b/src/public/javascripts/search_tree.jsindex 0b8a3ce93b..d345c26090 100644--- a/src/public/javascripts/search_tree.js+++ b/src/public/javascripts/search_tree.js@@ -1,83 +1,73 @@"use strict";-const searchTree = (function() {- const $tree = $("#tree");- const $searchInput = $("input[name='search-text']");- const $resetSearchButton = $("#reset-search-button");- const $doSearchButton = $("#do-search-button");- const $saveSearchButton = $("#save-search-button");- const $searchBox = $("#search-box");- const $toggleSearchButton = $("#toggle-search-button");-- $resetSearchButton.click(resetSearch);-- function toggleSearch() {- if ($searchBox.is(":hidden")) {- $searchBox.show();- $searchInput.focus();- }- else {- resetSearch();-- $searchBox.hide();- }+const $tree = $("#tree");+const $searchInput = $("input[name='search-text']");+const $resetSearchButton = $("#reset-search-button");+const $doSearchButton = $("#do-search-button");+const $saveSearchButton = $("#save-search-button");+const $searchBox = $("#search-box");++function toggleSearch() {+ if ($searchBox.is(":hidden")) {+ $searchBox.show();+ $searchInput.focus();}+ else {+ resetSearch();- function resetSearch() {- $searchInput.val("");-- getTree().clearFilter();+ $searchBox.hide();}+}- function getTree() {- return $tree.fancytree('getTree');- }+function resetSearch() {+ $searchInput.val("");- async function doSearch() {- const searchText = $searchInput.val();+ getTree().clearFilter();+}- const noteIds = await server.get('search/' + encodeURIComponent(searchText));+function getTree() {+ return $tree.fancytree('getTree');+}- for (const noteId of noteIds) {- await noteTree.expandToNote(noteId, {noAnimation: true, noEvents: true});- }+async function doSearch() {+ const searchText = $searchInput.val();- // Pass a string to perform case insensitive matching- getTree().filterBranches(node => noteIds.includes(node.data.noteId));- }+ const noteIds = await server.get('search/' + encodeURIComponent(searchText));- $searchInput.keyup(e => {- const searchText = $searchInput.val();+ for (const noteId of noteIds) {+ await noteTree.expandToNote(noteId, {noAnimation: true, noEvents: true});+ }- if (e && e.which === $.ui.keyCode.ESCAPE || $.trim(searchText) === "") {- $resetSearchButton.click();- return;- }+ // Pass a string to perform case insensitive matching+ getTree().filterBranches(node => noteIds.includes(node.data.noteId));+}- if (e && e.which === $.ui.keyCode.ENTER) {- doSearch();- }- }).focus();+async function saveSearch() {+ const {noteId} = await server.post('search/' + encodeURIComponent($searchInput.val()));- $doSearchButton.click(doSearch);+ await noteTree.reload();- $saveSearchButton.click(async () => {- const {noteId} = await server.post('search/' + encodeURIComponent($searchInput.val()));+ await noteTree.activateNode(noteId);+}- await noteTree.reload();+$searchInput.keyup(e => {+ const searchText = $searchInput.val();- await noteTree.activateNode(noteId);- });+ if (e && e.which === $.ui.keyCode.ESCAPE || $.trim(searchText) === "") {+ $resetSearchButton.click();+ return;+ }- $(document).bind('keydown', 'ctrl+s', e => {- toggleSearch();+ if (e && e.which === $.ui.keyCode.ENTER) {+ doSearch();+ }+}).focus();- e.preventDefault();- });+$doSearchButton.click(doSearch);+$resetSearchButton.click(resetSearch);- $toggleSearchButton.click(toggleSearch);+$saveSearchButton.click(saveSearch);- return {- toggleSearch- };-})();\ No newline at end of file+export default {+ toggleSearch+};\ No newline at end of filediff --git a/src/views/index.ejs b/src/views/index.ejsindex ac3726777b..e59d299309 100644--- a/src/views/index.ejs+++ b/src/views/index.ejs@@ -519,6 +519,8 @@<link href="stylesheets/style.css" rel="stylesheet">+ <script src="javascripts/bootstrap.js" type="module"></script>+<script src="javascripts/utils.js"></script><script src="javascripts/init.js"></script><script src="javascripts/server.js"></script>@@ -530,7 +532,6 @@<script src="javascripts/tree_utils.js"></script><script src="javascripts/drag_and_drop.js"></script><script src="javascripts/context_menu.js"></script>- <script src="javascripts/search_tree.js"></script><script src="javascripts/export.js"></script><!-- Note detail -->