annotate vakata-jstree-3.3.5/src/jstree.search.js @ 4:804fe260ee6c draft default tip

planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
author mingchen0919
date Sun, 30 Dec 2018 14:04:22 -0500
parents c12e291895ff
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1 /**
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2 * ### Search plugin
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3 *
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4 * Adds search functionality to jsTree.
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
5 */
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
6 /*globals jQuery, define, exports, require, document */
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
7 (function (factory) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
8 "use strict";
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
9 if (typeof define === 'function' && define.amd) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
10 define('jstree.search', ['jquery','jstree'], factory);
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
11 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
12 else if(typeof exports === 'object') {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
13 factory(require('jquery'), require('jstree'));
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
14 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
15 else {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
16 factory(jQuery, jQuery.jstree);
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
17 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
18 }(function ($, jstree, undefined) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
19 "use strict";
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
20
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
21 if($.jstree.plugins.search) { return; }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
22
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
23 /**
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
24 * stores all defaults for the search plugin
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
25 * @name $.jstree.defaults.search
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
26 * @plugin search
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
27 */
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
28 $.jstree.defaults.search = {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
29 /**
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
30 * a jQuery-like AJAX config, which jstree uses if a server should be queried for results.
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
31 *
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
32 * A `str` (which is the search string) parameter will be added with the request, an optional `inside` parameter will be added if the search is limited to a node id. The expected result is a JSON array with nodes that need to be opened so that matching nodes will be revealed.
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
33 * Leave this setting as `false` to not query the server. You can also set this to a function, which will be invoked in the instance's scope and receive 3 parameters - the search string, the callback to call with the array of nodes to load, and the optional node ID to limit the search to
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
34 * @name $.jstree.defaults.search.ajax
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
35 * @plugin search
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
36 */
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
37 ajax : false,
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
38 /**
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
39 * Indicates if the search should be fuzzy or not (should `chnd3` match `child node 3`). Default is `false`.
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
40 * @name $.jstree.defaults.search.fuzzy
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
41 * @plugin search
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
42 */
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
43 fuzzy : false,
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
44 /**
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
45 * Indicates if the search should be case sensitive. Default is `false`.
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
46 * @name $.jstree.defaults.search.case_sensitive
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
47 * @plugin search
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
48 */
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
49 case_sensitive : false,
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
50 /**
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
51 * Indicates if the tree should be filtered (by default) to show only matching nodes (keep in mind this can be a heavy on large trees in old browsers).
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
52 * This setting can be changed at runtime when calling the search method. Default is `false`.
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
53 * @name $.jstree.defaults.search.show_only_matches
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
54 * @plugin search
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
55 */
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
56 show_only_matches : false,
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
57 /**
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
58 * Indicates if the children of matched element are shown (when show_only_matches is true)
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
59 * This setting can be changed at runtime when calling the search method. Default is `false`.
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
60 * @name $.jstree.defaults.search.show_only_matches_children
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
61 * @plugin search
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
62 */
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
63 show_only_matches_children : false,
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
64 /**
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
65 * Indicates if all nodes opened to reveal the search result, should be closed when the search is cleared or a new search is performed. Default is `true`.
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
66 * @name $.jstree.defaults.search.close_opened_onclear
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
67 * @plugin search
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
68 */
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
69 close_opened_onclear : true,
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
70 /**
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
71 * Indicates if only leaf nodes should be included in search results. Default is `false`.
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
72 * @name $.jstree.defaults.search.search_leaves_only
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
73 * @plugin search
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
74 */
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
75 search_leaves_only : false,
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
76 /**
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
77 * If set to a function it wil be called in the instance's scope with two arguments - search string and node (where node will be every node in the structure, so use with caution).
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
78 * If the function returns a truthy value the node will be considered a match (it might not be displayed if search_only_leaves is set to true and the node is not a leaf). Default is `false`.
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
79 * @name $.jstree.defaults.search.search_callback
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
80 * @plugin search
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
81 */
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
82 search_callback : false
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
83 };
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
84
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
85 $.jstree.plugins.search = function (options, parent) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
86 this.bind = function () {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
87 parent.bind.call(this);
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
88
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
89 this._data.search.str = "";
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
90 this._data.search.dom = $();
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
91 this._data.search.res = [];
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
92 this._data.search.opn = [];
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
93 this._data.search.som = false;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
94 this._data.search.smc = false;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
95 this._data.search.hdn = [];
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
96
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
97 this.element
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
98 .on("search.jstree", $.proxy(function (e, data) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
99 if(this._data.search.som && data.res.length) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
100 var m = this._model.data, i, j, p = [], k, l;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
101 for(i = 0, j = data.res.length; i < j; i++) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
102 if(m[data.res[i]] && !m[data.res[i]].state.hidden) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
103 p.push(data.res[i]);
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
104 p = p.concat(m[data.res[i]].parents);
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
105 if(this._data.search.smc) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
106 for (k = 0, l = m[data.res[i]].children_d.length; k < l; k++) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
107 if (m[m[data.res[i]].children_d[k]] && !m[m[data.res[i]].children_d[k]].state.hidden) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
108 p.push(m[data.res[i]].children_d[k]);
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
109 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
110 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
111 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
112 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
113 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
114 p = $.vakata.array_remove_item($.vakata.array_unique(p), $.jstree.root);
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
115 this._data.search.hdn = this.hide_all(true);
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
116 this.show_node(p, true);
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
117 this.redraw(true);
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
118 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
119 }, this))
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
120 .on("clear_search.jstree", $.proxy(function (e, data) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
121 if(this._data.search.som && data.res.length) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
122 this.show_node(this._data.search.hdn, true);
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
123 this.redraw(true);
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
124 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
125 }, this));
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
126 };
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
127 /**
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
128 * used to search the tree nodes for a given string
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
129 * @name search(str [, skip_async])
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
130 * @param {String} str the search string
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
131 * @param {Boolean} skip_async if set to true server will not be queried even if configured
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
132 * @param {Boolean} show_only_matches if set to true only matching nodes will be shown (keep in mind this can be very slow on large trees or old browsers)
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
133 * @param {mixed} inside an optional node to whose children to limit the search
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
134 * @param {Boolean} append if set to true the results of this search are appended to the previous search
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
135 * @plugin search
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
136 * @trigger search.jstree
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
137 */
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
138 this.search = function (str, skip_async, show_only_matches, inside, append, show_only_matches_children) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
139 if(str === false || $.trim(str.toString()) === "") {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
140 return this.clear_search();
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
141 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
142 inside = this.get_node(inside);
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
143 inside = inside && inside.id ? inside.id : null;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
144 str = str.toString();
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
145 var s = this.settings.search,
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
146 a = s.ajax ? s.ajax : false,
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
147 m = this._model.data,
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
148 f = null,
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
149 r = [],
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
150 p = [], i, j;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
151 if(this._data.search.res.length && !append) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
152 this.clear_search();
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
153 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
154 if(show_only_matches === undefined) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
155 show_only_matches = s.show_only_matches;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
156 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
157 if(show_only_matches_children === undefined) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
158 show_only_matches_children = s.show_only_matches_children;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
159 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
160 if(!skip_async && a !== false) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
161 if($.isFunction(a)) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
162 return a.call(this, str, $.proxy(function (d) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
163 if(d && d.d) { d = d.d; }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
164 this._load_nodes(!$.isArray(d) ? [] : $.vakata.array_unique(d), function () {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
165 this.search(str, true, show_only_matches, inside, append, show_only_matches_children);
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
166 });
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
167 }, this), inside);
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
168 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
169 else {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
170 a = $.extend({}, a);
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
171 if(!a.data) { a.data = {}; }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
172 a.data.str = str;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
173 if(inside) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
174 a.data.inside = inside;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
175 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
176 if (this._data.search.lastRequest) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
177 this._data.search.lastRequest.abort();
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
178 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
179 this._data.search.lastRequest = $.ajax(a)
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
180 .fail($.proxy(function () {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
181 this._data.core.last_error = { 'error' : 'ajax', 'plugin' : 'search', 'id' : 'search_01', 'reason' : 'Could not load search parents', 'data' : JSON.stringify(a) };
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
182 this.settings.core.error.call(this, this._data.core.last_error);
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
183 }, this))
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
184 .done($.proxy(function (d) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
185 if(d && d.d) { d = d.d; }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
186 this._load_nodes(!$.isArray(d) ? [] : $.vakata.array_unique(d), function () {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
187 this.search(str, true, show_only_matches, inside, append, show_only_matches_children);
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
188 });
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
189 }, this));
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
190 return this._data.search.lastRequest;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
191 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
192 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
193 if(!append) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
194 this._data.search.str = str;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
195 this._data.search.dom = $();
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
196 this._data.search.res = [];
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
197 this._data.search.opn = [];
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
198 this._data.search.som = show_only_matches;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
199 this._data.search.smc = show_only_matches_children;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
200 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
201
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
202 f = new $.vakata.search(str, true, { caseSensitive : s.case_sensitive, fuzzy : s.fuzzy });
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
203 $.each(m[inside ? inside : $.jstree.root].children_d, function (ii, i) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
204 var v = m[i];
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
205 if(v.text && !v.state.hidden && (!s.search_leaves_only || (v.state.loaded && v.children.length === 0)) && ( (s.search_callback && s.search_callback.call(this, str, v)) || (!s.search_callback && f.search(v.text).isMatch) ) ) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
206 r.push(i);
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
207 p = p.concat(v.parents);
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
208 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
209 });
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
210 if(r.length) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
211 p = $.vakata.array_unique(p);
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
212 for(i = 0, j = p.length; i < j; i++) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
213 if(p[i] !== $.jstree.root && m[p[i]] && this.open_node(p[i], null, 0) === true) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
214 this._data.search.opn.push(p[i]);
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
215 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
216 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
217 if(!append) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
218 this._data.search.dom = $(this.element[0].querySelectorAll('#' + $.map(r, function (v) { return "0123456789".indexOf(v[0]) !== -1 ? '\\3' + v[0] + ' ' + v.substr(1).replace($.jstree.idregex,'\\$&') : v.replace($.jstree.idregex,'\\$&'); }).join(', #')));
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
219 this._data.search.res = r;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
220 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
221 else {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
222 this._data.search.dom = this._data.search.dom.add($(this.element[0].querySelectorAll('#' + $.map(r, function (v) { return "0123456789".indexOf(v[0]) !== -1 ? '\\3' + v[0] + ' ' + v.substr(1).replace($.jstree.idregex,'\\$&') : v.replace($.jstree.idregex,'\\$&'); }).join(', #'))));
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
223 this._data.search.res = $.vakata.array_unique(this._data.search.res.concat(r));
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
224 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
225 this._data.search.dom.children(".jstree-anchor").addClass('jstree-search');
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
226 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
227 /**
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
228 * triggered after search is complete
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
229 * @event
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
230 * @name search.jstree
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
231 * @param {jQuery} nodes a jQuery collection of matching nodes
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
232 * @param {String} str the search string
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
233 * @param {Array} res a collection of objects represeing the matching nodes
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
234 * @plugin search
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
235 */
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
236 this.trigger('search', { nodes : this._data.search.dom, str : str, res : this._data.search.res, show_only_matches : show_only_matches });
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
237 };
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
238 /**
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
239 * used to clear the last search (removes classes and shows all nodes if filtering is on)
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
240 * @name clear_search()
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
241 * @plugin search
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
242 * @trigger clear_search.jstree
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
243 */
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
244 this.clear_search = function () {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
245 if(this.settings.search.close_opened_onclear) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
246 this.close_node(this._data.search.opn, 0);
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
247 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
248 /**
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
249 * triggered after search is complete
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
250 * @event
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
251 * @name clear_search.jstree
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
252 * @param {jQuery} nodes a jQuery collection of matching nodes (the result from the last search)
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
253 * @param {String} str the search string (the last search string)
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
254 * @param {Array} res a collection of objects represeing the matching nodes (the result from the last search)
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
255 * @plugin search
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
256 */
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
257 this.trigger('clear_search', { 'nodes' : this._data.search.dom, str : this._data.search.str, res : this._data.search.res });
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
258 if(this._data.search.res.length) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
259 this._data.search.dom = $(this.element[0].querySelectorAll('#' + $.map(this._data.search.res, function (v) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
260 return "0123456789".indexOf(v[0]) !== -1 ? '\\3' + v[0] + ' ' + v.substr(1).replace($.jstree.idregex,'\\$&') : v.replace($.jstree.idregex,'\\$&');
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
261 }).join(', #')));
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
262 this._data.search.dom.children(".jstree-anchor").removeClass("jstree-search");
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
263 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
264 this._data.search.str = "";
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
265 this._data.search.res = [];
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
266 this._data.search.opn = [];
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
267 this._data.search.dom = $();
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
268 };
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
269
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
270 this.redraw_node = function(obj, deep, callback, force_render) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
271 obj = parent.redraw_node.apply(this, arguments);
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
272 if(obj) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
273 if($.inArray(obj.id, this._data.search.res) !== -1) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
274 var i, j, tmp = null;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
275 for(i = 0, j = obj.childNodes.length; i < j; i++) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
276 if(obj.childNodes[i] && obj.childNodes[i].className && obj.childNodes[i].className.indexOf("jstree-anchor") !== -1) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
277 tmp = obj.childNodes[i];
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
278 break;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
279 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
280 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
281 if(tmp) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
282 tmp.className += ' jstree-search';
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
283 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
284 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
285 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
286 return obj;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
287 };
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
288 };
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
289
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
290 // helpers
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
291 (function ($) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
292 // from http://kiro.me/projects/fuse.html
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
293 $.vakata.search = function(pattern, txt, options) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
294 options = options || {};
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
295 options = $.extend({}, $.vakata.search.defaults, options);
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
296 if(options.fuzzy !== false) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
297 options.fuzzy = true;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
298 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
299 pattern = options.caseSensitive ? pattern : pattern.toLowerCase();
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
300 var MATCH_LOCATION = options.location,
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
301 MATCH_DISTANCE = options.distance,
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
302 MATCH_THRESHOLD = options.threshold,
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
303 patternLen = pattern.length,
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
304 matchmask, pattern_alphabet, match_bitapScore, search;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
305 if(patternLen > 32) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
306 options.fuzzy = false;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
307 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
308 if(options.fuzzy) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
309 matchmask = 1 << (patternLen - 1);
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
310 pattern_alphabet = (function () {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
311 var mask = {},
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
312 i = 0;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
313 for (i = 0; i < patternLen; i++) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
314 mask[pattern.charAt(i)] = 0;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
315 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
316 for (i = 0; i < patternLen; i++) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
317 mask[pattern.charAt(i)] |= 1 << (patternLen - i - 1);
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
318 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
319 return mask;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
320 }());
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
321 match_bitapScore = function (e, x) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
322 var accuracy = e / patternLen,
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
323 proximity = Math.abs(MATCH_LOCATION - x);
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
324 if(!MATCH_DISTANCE) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
325 return proximity ? 1.0 : accuracy;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
326 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
327 return accuracy + (proximity / MATCH_DISTANCE);
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
328 };
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
329 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
330 search = function (text) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
331 text = options.caseSensitive ? text : text.toLowerCase();
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
332 if(pattern === text || text.indexOf(pattern) !== -1) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
333 return {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
334 isMatch: true,
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
335 score: 0
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
336 };
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
337 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
338 if(!options.fuzzy) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
339 return {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
340 isMatch: false,
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
341 score: 1
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
342 };
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
343 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
344 var i, j,
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
345 textLen = text.length,
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
346 scoreThreshold = MATCH_THRESHOLD,
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
347 bestLoc = text.indexOf(pattern, MATCH_LOCATION),
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
348 binMin, binMid,
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
349 binMax = patternLen + textLen,
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
350 lastRd, start, finish, rd, charMatch,
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
351 score = 1,
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
352 locations = [];
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
353 if (bestLoc !== -1) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
354 scoreThreshold = Math.min(match_bitapScore(0, bestLoc), scoreThreshold);
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
355 bestLoc = text.lastIndexOf(pattern, MATCH_LOCATION + patternLen);
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
356 if (bestLoc !== -1) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
357 scoreThreshold = Math.min(match_bitapScore(0, bestLoc), scoreThreshold);
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
358 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
359 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
360 bestLoc = -1;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
361 for (i = 0; i < patternLen; i++) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
362 binMin = 0;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
363 binMid = binMax;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
364 while (binMin < binMid) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
365 if (match_bitapScore(i, MATCH_LOCATION + binMid) <= scoreThreshold) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
366 binMin = binMid;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
367 } else {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
368 binMax = binMid;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
369 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
370 binMid = Math.floor((binMax - binMin) / 2 + binMin);
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
371 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
372 binMax = binMid;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
373 start = Math.max(1, MATCH_LOCATION - binMid + 1);
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
374 finish = Math.min(MATCH_LOCATION + binMid, textLen) + patternLen;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
375 rd = new Array(finish + 2);
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
376 rd[finish + 1] = (1 << i) - 1;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
377 for (j = finish; j >= start; j--) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
378 charMatch = pattern_alphabet[text.charAt(j - 1)];
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
379 if (i === 0) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
380 rd[j] = ((rd[j + 1] << 1) | 1) & charMatch;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
381 } else {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
382 rd[j] = ((rd[j + 1] << 1) | 1) & charMatch | (((lastRd[j + 1] | lastRd[j]) << 1) | 1) | lastRd[j + 1];
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
383 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
384 if (rd[j] & matchmask) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
385 score = match_bitapScore(i, j - 1);
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
386 if (score <= scoreThreshold) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
387 scoreThreshold = score;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
388 bestLoc = j - 1;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
389 locations.push(bestLoc);
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
390 if (bestLoc > MATCH_LOCATION) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
391 start = Math.max(1, 2 * MATCH_LOCATION - bestLoc);
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
392 } else {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
393 break;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
394 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
395 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
396 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
397 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
398 if (match_bitapScore(i + 1, MATCH_LOCATION) > scoreThreshold) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
399 break;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
400 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
401 lastRd = rd;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
402 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
403 return {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
404 isMatch: bestLoc >= 0,
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
405 score: score
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
406 };
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
407 };
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
408 return txt === true ? { 'search' : search } : search(txt);
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
409 };
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
410 $.vakata.search.defaults = {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
411 location : 0,
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
412 distance : 100,
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
413 threshold : 0.6,
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
414 fuzzy : false,
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
415 caseSensitive : false
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
416 };
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
417 }($));
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
418
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
419 // include the search plugin by default
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
420 // $.jstree.defaults.plugins.push("search");
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
421 }));