mirror of
https://github.com/devbridge/jQuery-Autocomplete.git
synced 2024-11-25 14:17:45 +00:00
Track hintValue and signal hint only when hintValue changes.
This commit is contained in:
parent
adfbf7a4e9
commit
5a6eaca541
@ -26,17 +26,14 @@
|
||||
var
|
||||
utils = (function () {
|
||||
return {
|
||||
|
||||
extend: function (target, source) {
|
||||
return $.extend(target, source);
|
||||
escapeRegExChars: function (value) {
|
||||
return value.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, "\\$&");
|
||||
},
|
||||
|
||||
createNode: function (html) {
|
||||
var div = document.createElement('div');
|
||||
div.innerHTML = html;
|
||||
return div.firstChild;
|
||||
}
|
||||
|
||||
};
|
||||
}()),
|
||||
|
||||
@ -102,6 +99,7 @@
|
||||
suggestion: 'autocomplete-suggestion'
|
||||
};
|
||||
that.hint = null;
|
||||
that.hintValue = '';
|
||||
|
||||
// Initialize and set options:
|
||||
that.initialize();
|
||||
@ -113,8 +111,7 @@
|
||||
$.Autocomplete = Autocomplete;
|
||||
|
||||
Autocomplete.formatResult = function (suggestion, currentValue) {
|
||||
var reEscape = new RegExp('(\\' + ['/', '.', '*', '+', '?', '|', '(', ')', '[', ']', '{', '}', '\\'].join('|\\') + ')', 'g'),
|
||||
pattern = '(' + currentValue.replace(reEscape, '\\$1') + ')';
|
||||
var pattern = '(' + utils.escapeRegExChars(currentValue) + ')';
|
||||
|
||||
return suggestion.value.replace(new RegExp(pattern, 'gi'), '<strong>$1<\/strong>');
|
||||
};
|
||||
@ -191,7 +188,7 @@
|
||||
var that = this,
|
||||
options = that.options;
|
||||
|
||||
utils.extend(options, suppliedOptions);
|
||||
$.extend(options, suppliedOptions);
|
||||
|
||||
that.isLocal = $.isArray(options.lookup);
|
||||
|
||||
@ -521,7 +518,8 @@
|
||||
if (suggestion) {
|
||||
hintValue = that.currentValue + suggestion.value.substr(that.currentValue.length);
|
||||
}
|
||||
if (that.hint !== suggestion) {
|
||||
if (that.hintValue !== hintValue) {
|
||||
that.hintValue = hintValue;
|
||||
that.hint = suggestion;
|
||||
(this.options.onHint || $.noop)(hintValue);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user