diff options
Diffstat (limited to 'core/misc/debounce.js')
-rw-r--r-- | core/misc/debounce.js | 11 |
1 files changed, 8 insertions, 3 deletions
diff --git a/core/misc/debounce.js b/core/misc/debounce.js index c2cfe9abe0e9..e33575670c09 100644 --- a/core/misc/debounce.js +++ b/core/misc/debounce.js @@ -6,26 +6,31 @@ **/ Drupal.debounce = function (func, wait, immediate) { - var timeout = void 0; - var result = void 0; + var timeout; + var result; return function () { - for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) { + for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) { args[_key] = arguments[_key]; } var context = this; + var later = function later() { timeout = null; + if (!immediate) { result = func.apply(context, args); } }; + var callNow = immediate && !timeout; clearTimeout(timeout); timeout = setTimeout(later, wait); + if (callNow) { result = func.apply(context, args); } + return result; }; };
\ No newline at end of file |