Skip to content

Commit 8d07d2c

Browse files
author
Tomas Kirda
committed
Change setInterval to setTimeout, closes #575
1 parent 56677b9 commit 8d07d2c

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

src/jquery.autocomplete.js

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -102,9 +102,9 @@
102102
that.badQueries = [];
103103
that.selectedIndex = -1;
104104
that.currentValue = that.element.value;
105-
that.intervalId = 0;
105+
that.timeoutId = null;
106106
that.cachedResponse = {};
107-
that.onChangeInterval = null;
107+
that.onChangeTimeout = null;
108108
that.onChange = null;
109109
that.isLocal = false;
110110
that.suggestionsContainer = null;
@@ -276,7 +276,7 @@
276276
disable: function () {
277277
var that = this;
278278
that.disabled = true;
279-
clearInterval(that.onChangeInterval);
279+
clearTimeout(that.onChangeTimeout);
280280
that.abortAjax();
281281
},
282282

@@ -357,7 +357,7 @@
357357
killSuggestions: function () {
358358
var that = this;
359359
that.stopKillSuggestions();
360-
that.intervalId = window.setInterval(function () {
360+
that.timeoutId = setTimeout(function () {
361361
if (that.visible) {
362362
// No need to restore value when
363363
// preserveInput === true,
@@ -374,7 +374,7 @@
374374
},
375375

376376
stopKillSuggestions: function () {
377-
window.clearInterval(this.intervalId);
377+
clearTimeout(this.timeoutId);
378378
},
379379

380380
isCursorAtEnd: function () {
@@ -467,13 +467,13 @@
467467
return;
468468
}
469469

470-
clearInterval(that.onChangeInterval);
470+
clearTimeout(that.onChangeTimeout);
471471

472472
if (that.currentValue !== that.el.val()) {
473473
that.findBestHint();
474474
if (that.options.deferRequestBy > 0) {
475475
// Defer lookup in case when value changes very quickly:
476-
that.onChangeInterval = setInterval(function () {
476+
that.onChangeTimeout = setTimeout(function () {
477477
that.onValueChange();
478478
}, that.options.deferRequestBy);
479479
} else {
@@ -493,7 +493,7 @@
493493
(options.onInvalidateSelection || $.noop).call(that.element);
494494
}
495495

496-
clearInterval(that.onChangeInterval);
496+
clearTimeout(that.onChangeTimeout);
497497
that.currentValue = value;
498498
that.selectedIndex = -1;
499499

@@ -640,7 +640,7 @@
640640

641641
that.visible = false;
642642
that.selectedIndex = -1;
643-
clearInterval(that.onChangeInterval);
643+
clearTimeout(that.onChangeTimeout);
644644
$(that.suggestionsContainer).hide();
645645
that.signalHint(null);
646646
},

0 commit comments

Comments
 (0)