/
text-ext-filter.html
206 lines (187 loc) · 5.6 KB
/
text-ext-filter.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>Test Fancytree Filter Ext</title>
<!-- Include latest jQuery and Fancytree from CDN ... -->
<!--
<script src="https://code.jquery.com/jquery-3.6.0.js"></script>
<link href="https://cdn.jsdelivr.net/npm/jquery.fancytree/dist/skin-win8/ui.fancytree.min.css"
rel="stylesheet">
<script src="https://cdn.jsdelivr.net/npm/jquery.fancytree/dist/jquery.fancytree-all-deps.min.js">
</script>
-->
<!-- ... or include from own asset folders: -->
<script src="../../lib/jquery.js"></script>
<script src="../../lib/jquery-ui.custom.js"></script>
<link href="../../src/skin-lion/ui.fancytree.css" rel="stylesheet" />
<script src="../../src/jquery.fancytree.js"></script>
<script src="../../src/jquery.fancytree.filter.js"></script>
<style type="text/css">
.fancytree-ext-filter-dimm tr.fancytree-match span.fancytree-title,
.fancytree-ext-filter-dimm span.fancytree-node.fancytree-match span.fancytree-title {
color: black;
font-weight: unset !important;
}
</style>
<script type="text/javascript">
$(function() {
// Initialize Fancytree
$('#tree').fancytree({
extensions: ['filter'],
source: { url: '../../demo/ajax-tree-plain.json' },
autoCollapse: true,
checkbox: true,
quicksearch: true,
filter: {},
init: function(event, data) {},
lazyLoad: function(event, data) {
data.result = { url: 'sample_sub.json', debugDelay: 5000 };
},
loadChildren: function(event, data) {
// data.node.fixSelection3FromEndNodes();
},
});
var tree = $.ui.fancytree.getTree('#tree');
// Check these options by default
const defaultOptions = [
'#autoExpand',
'#highlight',
'#hideExpandedCounter',
'#fuzzy',
'#hideMode'
];
const options = $('#options');
defaultOptions.forEach(id => {
options.find(id).prop('checked', true);
});
/*
* Event handlers for our little demo interface
*/
$('input[name=search]')
.on('keyup', function(e) {
var n,
tree = $.ui.fancytree.getTree(),
args = 'autoApply autoExpand fuzzy hideExpanders highlight leavesOnly nodata'.split(' '),
opts = {},
filterFunc = $('#branchMode').is(':checked') ? tree.filterBranches : tree.filterNodes,
match = $(this).val();
$.each(args, function(i, o) {
opts[o] = $('#' + o).is(':checked');
});
opts.mode = $('#hideMode').is(':checked') ? 'hide' : 'dimm';
if ((e && e.which === $.ui.keyCode.ESCAPE) || tools.trim(match) === '') {
$('button#btnResetSearch').trigger("click");
return;
}
if ($('#regex').is(':checked')) {
// Pass function to perform match
n = filterFunc.call(
tree,
function(node) {
return new RegExp(match, 'i').test(node.title);
},
opts
);
} else {
// Pass a string to perform case insensitive matching
n = filterFunc.call(tree, match, opts);
}
$('button#btnResetSearch').attr('disabled', false);
$('span#matches').text('(' + n + ' matches)');
})
.focus();
$('fieldset input:checkbox').change(function(e) {
var id = $(this).attr('id'),
flag = $(this).is(':checked');
// Some options can only be set with general filter options (not method args):
switch (id) {
case 'counter':
case 'hideExpandedCounter':
tree.options.filter[id] = flag;
break;
}
tree.clearFilter();
$('input[name=search]').keyup();
});
$('button#btnResetSearch')
.click(function(e) {
$('input[name=search]').val('');
$('span#matches').text('');
$.ui.fancytree.getTree().clearFilter();
})
.attr('disabled', true);
$('#button1').click(function(event) {
var tree = $.ui.fancytree.getTree(),
node = tree.getActiveNode();
tree.filterBranches('folder');
});
});
</script>
</head>
<body class="example">
<h1>Playground To Test Filter Ext</h1>
<p class="description">
(TODO: optionally add a short description here...)
</p>
<button id="button1">Test 1</button>
<p>
<label>Filter:</label>
<input name="search" placeholder="Filter..." autocomplete="off" />
<button id="btnResetSearch">×</button>
<span id="matches"></span>
</p>
<fieldset id="options">
<legend>Options</legend>
<label for="regex">
<input type="checkbox" id="regex" />
Regular expression
</label>
<br />
<label for="hideMode">
<input type="checkbox" id="hideMode" />
Hide unmatched nodes
</label>
<label for="autoExpand">
<input type="checkbox" id="autoExpand" />
Auto expand
</label>
<label for="branchMode">
<input type="checkbox" id="branchMode" />
Match whole branch
</label>
<label for="leavesOnly">
<input type="checkbox" id="leavesOnly" />
Match end nodes only
</label>
<br />
<label for="fuzzy">
<input type="checkbox" id="fuzzy" />
Fuzzy
</label>
<label for="hideExpanders">
<input type="checkbox" id="hideExpanders" />
hideExpanders
</label>
<label for="highlight">
<input type="checkbox" id="highlight" />
Highlight
</label>
<label for="nodata">
<input type="checkbox" id="nodata" />
nodata
</label>
<br />
<label for="counter">
<input type="checkbox" id="counter" />
Add counter badges
</label>
<label for="hideExpandedCounter">
<input type="checkbox" id="hideExpandedCounter" />
hideExpandedCounter
</label>
</fieldset>
<hr />
<div id="tree"></div>
</body>
</html>