mirror of
https://github.com/zadam/trilium.git
synced 2025-03-01 14:22:32 +01: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";
|
||||
|
||||
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");
|
||||
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");
|
||||
|
||||
$resetSearchButton.click(resetSearch);
|
||||
function toggleSearch() {
|
||||
if ($searchBox.is(":hidden")) {
|
||||
$searchBox.show();
|
||||
$searchInput.focus();
|
||||
}
|
||||
else {
|
||||
resetSearch();
|
||||
|
||||
function toggleSearch() {
|
||||
if ($searchBox.is(":hidden")) {
|
||||
$searchBox.show();
|
||||
$searchInput.focus();
|
||||
}
|
||||
else {
|
||||
resetSearch();
|
||||
$searchBox.hide();
|
||||
}
|
||||
}
|
||||
|
||||
$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() {
|
||||
$searchInput.val("");
|
||||
// Pass a string to perform case insensitive matching
|
||||
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() {
|
||||
return $tree.fancytree('getTree');
|
||||
if (e && e.which === $.ui.keyCode.ENTER) {
|
||||
doSearch();
|
||||
}
|
||||
}).focus();
|
||||
|
||||
async function doSearch() {
|
||||
const searchText = $searchInput.val();
|
||||
$doSearchButton.click(doSearch);
|
||||
$resetSearchButton.click(resetSearch);
|
||||
|
||||
const noteIds = await server.get('search/' + encodeURIComponent(searchText));
|
||||
$saveSearchButton.click(saveSearch);
|
||||
|
||||
for (const noteId of noteIds) {
|
||||
await noteTree.expandToNote(noteId, {noAnimation: true, noEvents: true});
|
||||
}
|
||||
|
||||
// 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
|
||||
};
|
||||
})();
|
||||
export default {
|
||||
toggleSearch
|
||||
};
|
@ -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 -->
|
||||
|
Loading…
x
Reference in New Issue
Block a user