Implement extension registration from an extension.json file
[mediawiki.git] / resources / src / mediawiki / mediawiki.userSuggest.js
blob3964f0b2859f3125634471ce4de49a248d5913c1
1 /*!
2  * Add autocomplete suggestions for names of registered users.
3  */
4 ( function ( mw, $ ) {
5         var api, config;
7         config = {
8                 fetch: function ( userInput, response, maxRows ) {
9                         var node = this[0];
11                         api = api || new mw.Api();
13                         $.data( node, 'request', api.get( {
14                                 action: 'query',
15                                 list: 'allusers',
16                                 // Prefix of list=allusers is case sensitive. Normalise first
17                                 // character to uppercase so that "fo" may yield "Foo".
18                                 auprefix: userInput.charAt( 0 ).toUpperCase() + userInput.slice( 1 ),
19                                 aulimit: maxRows
20                         } ).done( function ( data ) {
21                                 var users = $.map( data.query.allusers, function ( userObj ) {
22                                         return userObj.name;
23                                 } );
24                                 response( users );
25                         } ) );
26                 },
27                 cancel: function () {
28                         var node = this[0],
29                                 request = $.data( node, 'request' );
31                         if ( request ) {
32                                 request.abort();
33                                 $.removeData( node, 'request' );
34                         }
35                 }
36         };
38         $( function () {
39                 $( '.mw-autocomplete-user' ).suggestions( config );
40         } );
41 }( mediaWiki, jQuery ) );