From 2c70fd213588e8ea6fad0c032d4a56df183526a6 Mon Sep 17 00:00:00 2001 From: Mingsong Hu <mingsonghu@Mingsongs-MBP.gateway> Date: Fri, 22 Jan 2021 14:47:53 +1100 Subject: [PATCH] New feature:Support multiple words search --- js/Plugin/jstree/hm.jstree.js | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/js/Plugin/jstree/hm.jstree.js b/js/Plugin/jstree/hm.jstree.js index 9a82c5a..2c78763 100644 --- a/js/Plugin/jstree/hm.jstree.js +++ b/js/Plugin/jstree/hm.jstree.js @@ -54,7 +54,24 @@ "multiple": false, }, search: { - show_only_matches: true + show_only_matches: true, + "search_callback": function(str, node) { + //search for any of the words entered + var word, words = []; + var searchFor = str.toLowerCase().replace(/^\s+/g, '').replace(/\s+$/g, ''); + if (searchFor.indexOf(' ') >= 0) { + words = searchFor.split(' '); + } else { + words = [searchFor]; + } + for (var i = 0; i < words.length; i++) { + word = words[i]; + if ((node.text || "").toLowerCase().indexOf(word) >= 0) { + return true; + } + } + return false; + } }, plugins: ["search", "dnd"] }); -- GitLab