-
Notifications
You must be signed in to change notification settings - Fork 28
Expand file tree
/
Copy pathfilter.js
More file actions
63 lines (49 loc) · 2.04 KB
/
Copy pathfilter.js
File metadata and controls
63 lines (49 loc) · 2.04 KB
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
/**
* Copyright 2014 Openstack Foundation
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* http://www.apache.org/licenses/LICENSE-2.0
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
**/
jQuery(document).ready(function($) {
//default each row to visible
$('.filter li').addClass('visible');
//overrides CSS display:none property
//so only users w/ JS will see the
//filter box
$('#search').show();
$('#search input').focus();
$('#filter').keyup(function(event) {
//if esc is pressed or nothing is entered
if (event.keyCode == 27 || $(this).val() == '') {
//if esc is pressed we want to clear the value of search box
$(this).val('');
//we want each row to be visible because if nothing
//is entered then all rows are matched.
$('.filter li').removeClass('visible').show().addClass('visible');
$('.filter .groupHeading').removeClass('visible').show().addClass('visible');
$('#filterHeading').removeClass('visible').hide();
}
//if there is text, lets filter
else {
// Hide the group headings
$('.filter .groupHeading').removeClass('visible').hide();
// Show the filter heading
$('#filterHeading').removeClass('visible').show().addClass('visible');
filter('.filter li', $(this).val());
}
});
});
//filter results based on query
function filter(selector, query) {
query = $.trim(query); //trim white space
query = query.replace(/ /gi, '|'); //add OR for regex
$(selector).each(function() {
($(this).children('strong').text().search(new RegExp(query, "i")) < 0) ? $(this).hide().removeClass('visible') : $(this).show().addClass('visible');
});
}