MW_NO_OUTPUT_BUFFER is never defined
[mediawiki.git] / resources / src / mediawiki / mediawiki.userSuggest.js
blobaed093caa8973ee6274b67ed48c639b671aba050
1 /*!
2  * Add autocomplete suggestions for names of registered users.
3  */
4 ( function ( mw, $ ) {
5         var api, config;
7         config = {
8                 fetch: function ( userInput ) {
9                         var $textbox = this,
10                                 node = this[0];
12                         api = api || new mw.Api();
14                         $.data( node, 'request', api.get( {
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.charAt( 0 ).toUpperCase() + userInput.slice( 1 )
20                         } ).done( function ( data ) {
21                                 var users = $.map( data.query.allusers, function ( userObj ) {
22                                         return userObj.name;
23                                 } );
24                                 // Set the results as the autocomplete options
25                                 $textbox.suggestions( 'suggestions', 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 ) );