autocomplete.es6.js 989 B

12345678910111213141516171819202122232425262728293031323334
  1. /**
  2. * @file
  3. * Claro's enhancement for autocomplete form element.
  4. */
  5. (($, Drupal) => {
  6. Drupal.behaviors.claroAutoCompete = {
  7. attach(context) {
  8. $(context)
  9. .find('input.form-autocomplete')
  10. .once('claroAutoComplete')
  11. .each((index, value) => {
  12. const $input = $(value);
  13. const timeout = 400;
  14. let classRemoveTimeout;
  15. const classRemove = $autoCompleteElem => {
  16. $autoCompleteElem.removeClass('is-autocompleting');
  17. };
  18. $input.on('input autocompletesearch autocompleteresponses', event => {
  19. if (event && event.type && event.type === 'autocompletesearch') {
  20. $(event.target).addClass('is-autocompleting');
  21. }
  22. clearTimeout(classRemoveTimeout);
  23. classRemoveTimeout = setTimeout(
  24. classRemove,
  25. timeout,
  26. $(event.target),
  27. );
  28. });
  29. });
  30. },
  31. };
  32. })(jQuery, Drupal);