Merge "Update docs/hooks.txt for ShowSearchHitTitle"
[mediawiki.git] / resources / src / mediawiki / mediawiki.userSuggest.js
blob99e9dbe01bf745fbbc4981fa8a1cb15c1da3efb4
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                                 formatversion: 2,
15                                 action: 'query',
16                                 list: 'allusers',
17                                 // Prefix of list=allusers is case sensitive. Normalise first
18                                 // character to uppercase so that "fo" may yield "Foo".
19                                 auprefix: userInput[ 0 ].toUpperCase() + userInput.slice( 1 ),
20                                 aulimit: maxRows
21                         } ).done( function ( data ) {
22                                 var users = $.map( data.query.allusers, function ( userObj ) {
23                                         return userObj.name;
24                                 } );
25                                 response( users );
26                         } ) );
27                 },
28                 cancel: function () {
29                         var node = this[ 0 ],
30                                 request = $.data( node, 'request' );
32                         if ( request ) {
33                                 request.abort();
34                                 $.removeData( node, 'request' );
35                         }
36                 }
37         };
39         $( function () {
40                 $( '.mw-autocomplete-user' ).suggestions( config );
41         } );
42 }( mediaWiki, jQuery ) );