Advertisement
Guest User

typeahead-init.js

a guest
Dec 11th, 2019
187
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.75 KB | None | 0 0
  1. /**
  2. * Based on https://gerrit.wikimedia.org/g/wikimedia/portals/+/refs/heads/master
  3. * See T219590 for more details
  4. */
  5.  
  6. /* global wmTest, WMTypeAhead, _, addEvent */
  7.  
  8. ( function ( WMTypeAhead ) {
  9.  
  10. var inputEvent,
  11. searchInput = document.getElementById( 'search-input' ),
  12. typeAhead = new WMTypeAhead( 'search-form', 'search-input' );
  13.  
  14. /**
  15. * Testing for 'input' event and falling back to 'propertychange' event for IE.
  16. */
  17. if ( 'oninput' in document ) {
  18. inputEvent = 'input';
  19. } else {
  20. inputEvent = 'propertychange';
  21. }
  22.  
  23. /**
  24. * Attaching type-ahead query action to 'input' event.
  25. */
  26. addEvent( searchInput, inputEvent, _.debounce( function () {
  27. typeAhead.query( searchInput.value );
  28. }, 100 ) );
  29.  
  30. }( WMTypeAhead ) );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement