-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.js
49 lines (37 loc) · 965 Bytes
/
main.js
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
$(function() {
var search = $('#search');
// this selects all but the leaf-nodes of the nested lists
// nfo: the outer list is a ul, inner lists are ol
var allListItems = $('li')
var innerListItems = allListItems.filter(':has(~ol)');
highlightLines();
innerListItems.click(function() {
$(this).next().toggle(100, function() {
highlightLines();
});
});
search.change(function() {
// when a search term is entered highlight the word and it's parent and grandparent
var searchTerm = search.val();
var query = ":contains('" + searchTerm + "')";
var items = allListItems.filter(":contains('" + searchTerm + "')");
allListItems.removeClass('search');
items
.addClass('search');
items
.parent()
.prev()
.addClass('search');
items
.parent()
.parent()
.prev()
.addClass('search');
});
});
function highlightLines() {
$('li')
.removeClass('highlight')
.filter('li:not(:hidden):even')
.addClass('highlight');
}