-
Notifications
You must be signed in to change notification settings - Fork 0
/
searchbar.js
46 lines (40 loc) · 1.13 KB
/
searchbar.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
var searchTermCache = '';
Session.setDefault('searchMode', 'initial');
Template.searchbar.created = function () {
EasySearch.getComponentInstance({ index: "resources" }).on('searchingDone', function (hasSearched) {
if (hasSearched) {
Session.set('searchMode', 'done');
}
}, Template.searchbar.autorun);
};
Template.searchbar.helpers({
'inputIconClass' : function () {
switch (Session.get('searchMode')) {
case 'initial':
return 'search';
case 'searching':
return 'loading';
case 'done':
return 'lightbulb';
}
},
'positionClass' : function () {
if (Session.equals('searchMode', 'searching') || Session.equals('searchMode', 'done')) {
return 'left';
}
}
});
Template.searchbar.events({
'keyup #globalSearchbar input' : function (e) {
var searchValue = $(e.target).val().compact();
if (searchTermCache === searchValue) {
return;
}
if (searchValue.length > 0) {
Session.set('searchMode', 'searching');
searchTermCache = searchValue;
} else {
Session.set('searchMode', 'initial');
}
}
});