mediawiki-skins-Citizen/resources/scripts/typeahead-init.js

31 lines
735 B
JavaScript
Raw Normal View History

2019-12-11 22:14:36 +00:00
/**
* Based on https://gerrit.wikimedia.org/g/wikimedia/portals/+/refs/heads/master
* See T219590 for more details
*/
/* global wmTest, WMTypeAhead, _, addEvent */
2019-12-11 22:25:24 +00:00
( function ( WMTypeAhead ) {
2019-12-11 22:14:36 +00:00
var inputEvent,
searchInput = document.getElementById( 'search-input' ),
typeAhead = new WMTypeAhead( 'search-form', 'searchInput' );
/**
* Testing for 'input' event and falling back to 'propertychange' event for IE.
*/
if ( 'oninput' in document ) {
inputEvent = 'input';
} else {
inputEvent = 'propertychange';
}
/**
* Attaching type-ahead query action to 'input' event.
*/
addEvent( searchInput, inputEvent, _.debounce( function () {
2019-12-11 23:09:05 +00:00
typeAhead.query( searchInput.value );
2019-12-11 22:14:36 +00:00
}, 100 ) );
2019-12-11 22:25:24 +00:00
}( WMTypeAhead ) );