-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsearch.js
28 lines (25 loc) · 848 Bytes
/
search.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
MeteorSearch = function (options) {
options = options || {};
var searchTemplate = options.searchTemplate || Template.search;
var inputSelector = options.inputSelector || '.queryinput';
var urlKey = options.urlKey || 'q';
searchTemplate.helpers({
query: function () {
return Router.current().params.query[urlKey];
}
});
searchTemplate.events({
'submit form': function (e) {
$(inputSelector).blur();
var params = Router.current().params;
params.query[urlKey] = $(e.target).find(inputSelector).val();
Router.go(Router.current().route.getName(), params, {query: params.query, hash: params.hash});
return false;
}
});
return {
getSearchQuery: function () {
return Router.current() && Router.current().params.query && Router.current().params.query[urlKey];
}
};
};