forked from mhuggins/jquery-ui-autocomplete-hints
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjquery.autocomplete.js
72 lines (59 loc) · 1.66 KB
/
jquery.autocomplete.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
70
71
72
(function($) {
var plugin = $.ui.autocomplete.prototype;
// store copies of the original plugin functions before overwriting
var functions = {};
for (var i in plugin) {
if (typeof(plugin[i]) === 'function') {
functions[i] = plugin[i];
}
}
// extend existing functionality of the autocomplete plugin
$.extend(true, plugin, {
_create: function () {
var self = this,
doc = this.element[0].ownerDocument;
functions._create.apply(this, arguments);
this.hintText = this.element.data('hint');
this.searchText = this.element.data('searching');
// set up the hint object
this.hint = $('<div></div>')
.addClass('ui-autocomplete-hint')
.appendTo($(this.options.appendTo || 'body', doc)[0]);
// show/hide hint text on focus/blur
this.element
.bind('focus.autocomplete', function () {
self._showHint(self.hintText);
})
.bind('blur.autocomplete', function () {
self._hideHint();
});
},
_destroy: function () {
this.hint.remove();
return functions._destroy.apply(this, arguments);
},
_search: function () {
this._showHint(this.searchText);
return functions._search.apply(this, arguments);
},
_response: function () {
this._hideHint();
return functions._response.apply(this, arguments);
},
_showHint: function (text) {
text = $.trim(text);
if (text !== '') {
this.hint.text(text).show();
this._resizeHint();
}
},
_hideHint: function () {
this.hint.hide();
},
_resizeHint: function () {
this.hint
.outerWidth(this.element.outerWidth())
.position($.extend({ of: this.element }, this.options.position));
}
});
})(jQuery);