Localisation updates from https://translatewiki.net.
[mediawiki.git] / resources / src / mediawiki.userSuggest.js
blobf04437d187f27ab0665e6a8c3fe162479449abd1
1 /*!
2  * Add autocomplete suggestions for names of registered users.
3  */
4 ( function () {
5         let api;
7         const config = {
8                 fetch: function ( userInput, response, maxRows ) {
9                         const node = this[ 0 ];
11                         api = api || new mw.Api();
13                         $.data( node, 'request', api.get( {
14                                 formatversion: 2,
15                                 action: 'query',
16                                 list: 'allusers',
17                                 auprefix: userInput,
18                                 aulimit: maxRows
19                         } ).done( ( data ) => {
20                                 const users = data.query.allusers.map( ( userObj ) => userObj.name );
21                                 response( users );
22                         } ) );
23                 },
24                 cancel: function () {
25                         const node = this[ 0 ],
26                                 request = $.data( node, 'request' );
28                         if ( request ) {
29                                 request.abort();
30                                 $.removeData( node, 'request' );
31                         }
32                 }
33         };
35         $( () => {
36                 $( '.mw-autocomplete-user' ).suggestions( config );
37         } );
38 }() );