debounce.js 653 B

12345678910111213141516171819202122232425262728
  1. /**
  2. * DO NOT EDIT THIS FILE.
  3. * See the following change record for more information,
  4. * https://www.drupal.org/node/2815083
  5. * @preserve
  6. **/
  7. Drupal.debounce = function (func, wait, immediate) {
  8. var timeout = void 0;
  9. var result = void 0;
  10. return function () {
  11. var context = this;
  12. var args = arguments;
  13. var later = function later() {
  14. timeout = null;
  15. if (!immediate) {
  16. result = func.apply(context, args);
  17. }
  18. };
  19. var callNow = immediate && !timeout;
  20. clearTimeout(timeout);
  21. timeout = setTimeout(later, wait);
  22. if (callNow) {
  23. result = func.apply(context, args);
  24. }
  25. return result;
  26. };
  27. };