Skip to content

Commit 8138252

Browse files
authored
Merge pull request #816 from geoffrosen/master
Bind `this` to onHint
2 parents 608d9ef + a4d3539 commit 8138252

File tree

4 files changed

+30
-20
lines changed

4 files changed

+30
-20
lines changed

dist/jquery.autocomplete.js

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@
9595
serviceUrl: null,
9696
lookup: null,
9797
onSelect: null,
98+
onHint: null,
9899
width: 'auto',
99100
minChars: 1,
100101
maxHeight: 300,
@@ -632,7 +633,7 @@
632633
that.selectedIndex = -1;
633634
clearTimeout(that.onChangeTimeout);
634635
$(that.suggestionsContainer).hide();
635-
that.signalHint(null);
636+
that.onHint(null);
636637
},
637638

638639
suggest: function () {
@@ -768,20 +769,24 @@
768769
return !foundMatch;
769770
});
770771

771-
that.signalHint(bestMatch);
772+
that.onHint(bestMatch);
772773
},
773774

774-
signalHint: function (suggestion) {
775-
var hintValue = '',
776-
that = this;
775+
onHint: function (suggestion) {
776+
var that = this,
777+
onHintCallback = that.options.onHint,
778+
hintValue = '';
779+
777780
if (suggestion) {
778781
hintValue = that.currentValue + suggestion.value.substr(that.currentValue.length);
779782
}
780783
if (that.hintValue !== hintValue) {
781784
that.hintValue = hintValue;
782785
that.hint = suggestion;
783-
(this.options.onHint || $.noop)(hintValue);
784-
}
786+
if ($.isFunction(onHintCallback)) {
787+
onHintCallback.call(that.element, hintValue);
788+
}
789+
}
785790
},
786791

787792
verifySuggestionsFormat: function (suggestions) {
@@ -922,7 +927,7 @@
922927
that.el.val(that.getValue(that.suggestions[index].value));
923928
}
924929

925-
that.signalHint(null);
930+
that.onHint(null);
926931
},
927932

928933
onSelect: function (index) {
@@ -936,7 +941,7 @@
936941
that.el.val(that.currentValue);
937942
}
938943

939-
that.signalHint(null);
944+
that.onHint(null);
940945
that.suggestions = [];
941946
that.selection = suggestion;
942947

0 commit comments

Comments
 (0)