-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathjquery.indextank.instantsearch.js
69 lines (57 loc) · 2.62 KB
/
jquery.indextank.instantsearch.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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
(function($){
if(!$.Indextank){
$.Indextank = new Object();
};
$.Indextank.InstantSearch = function(el, options){
// To avoid scope issues, use 'base' instead of 'this'
// to reference this class from internal events and functions.
var base = this;
// Access to jQuery and DOM versions of element
base.$el = $(el);
base.el = el;
// Add a reverse reference to the DOM object
base.$el.data("Indextank.InstantSearch", base);
base.init = function(){
base.options = $.extend({},$.Indextank.InstantSearch.defaultOptions, options);
// make autocomplete trigger a query when suggestions appear
base.$el.bind( "Indextank.Autocomplete.success", function (event, suggestions ) {
if ( suggestions.length > 0) {
// create the query
var query = base.$el.data("Indextank.AjaxSearch").getDefaultQuery().clone();
query.withQueryString(suggestions[0]);
// run it
base.$el.trigger( "Indextank.AjaxSearch.runQuery", query );
} else { base.$el.trigger( "Indextank.AjaxSearch.displayNoResults" ); }
});
// make autocomplete focus trigger an AjaxSearch, only if requested
if (base.options.focusTriggersSearch) {
base.$el.bind( "autocompletefocus", function (event, ui) {
// create the query
var query = base.$el.data("Indextank.AjaxSearch").getDefaultQuery().clone();
query.withQueryString(ui.item.value);
// run it
base.$el.trigger( "Indextank.AjaxSearch.runQuery", query );
});
}
};
// Sample Function, Uncomment to use
// base.functionName = function(paramaters){
//
// };
// Run initializer
base.init();
};
$.Indextank.InstantSearch.defaultOptions = {
// trigger a query whenever an option on the autocomplete box is
// focused. Either by keyboard or mouse hover.
// Note that setting this to true can be annoying if your search box is
// above the result set, as moving the mouse over the suggestions will
// change the result set.
focusTriggersSearch : false
};
$.fn.indextank_InstantSearch = function(options){
return this.each(function(){
(new $.Indextank.InstantSearch(this, options));
});
};
})(jQuery);