Merge "Make jquery.suggestions obey maxRows setting"
authorjenkins-bot <jenkins-bot@gerrit.wikimedia.org>
Mon, 5 Jan 2015 14:29:08 +0000 (14:29 +0000)
committerGerrit Code Review <gerrit@wikimedia.org>
Mon, 5 Jan 2015 14:29:08 +0000 (14:29 +0000)
resources/src/jquery/jquery.suggestions.js
resources/src/mediawiki/mediawiki.searchSuggest.js
resources/src/mediawiki/mediawiki.userSuggest.js

index a83a70a..f1b214e 100644 (file)
@@ -28,7 +28,7 @@
  * suggestions: Suggestions to display
  *             Type: Array of strings
  * maxRows: Maximum number of suggestions to display at one time
- *             Type: Number, Range: 1 - 100, Default: 7
+ *             Type: Number, Range: 1 - 100, Default: 10
  * delay: Number of ms to wait for the user to stop typing
  *             Type: Number, Range: 0 - 1200, Default: 120
  * cache: Whether to cache results from a fetch
@@ -125,6 +125,7 @@ $.suggestions = {
                                                context.data.$textbox,
                                                val,
                                                function ( suggestions ) {
+                                                       suggestions = suggestions.slice( 0, context.config.maxRows );
                                                        context.data.$textbox.suggestions( 'suggestions', suggestions );
                                                        if ( context.config.cache ) {
                                                                cache[ val ] = {
@@ -132,7 +133,8 @@ $.suggestions = {
                                                                        timestamp: +new Date()
                                                                };
                                                        }
-                                               }
+                                               },
+                                               context.config.maxRows
                                        );
                                }
                        }
@@ -513,7 +515,7 @@ $.fn.suggestions = function () {
                                        result: {},
                                        $region: $( this ),
                                        suggestions: [],
-                                       maxRows: 7,
+                                       maxRows: 10,
                                        delay: 120,
                                        cache: false,
                                        cacheMaxAge: 60000,
index d372e8f..7b7ccf3 100644 (file)
                ];
                $( searchboxesSelectors.join( ', ' ) )
                        .suggestions( {
-                               fetch: function ( query, response ) {
+                               fetch: function ( query, response, maxRows ) {
                                        var node = this[0];
 
                                        api = api || new mw.Api();
                                                action: 'opensearch',
                                                search: query,
                                                namespace: 0,
+                                               limit: maxRows,
                                                suggest: ''
                                        } ).done( function ( data ) {
                                                response( data[ 1 ] );
index aed093c..3964f0b 100644 (file)
@@ -5,9 +5,8 @@
        var api, config;
 
        config = {
-               fetch: function ( userInput ) {
-                       var $textbox = this,
-                               node = this[0];
+               fetch: function ( userInput, response, maxRows ) {
+                       var node = this[0];
 
                        api = api || new mw.Api();
 
                                list: 'allusers',
                                // Prefix of list=allusers is case sensitive. Normalise first
                                // character to uppercase so that "fo" may yield "Foo".
-                               auprefix: userInput.charAt( 0 ).toUpperCase() + userInput.slice( 1 )
+                               auprefix: userInput.charAt( 0 ).toUpperCase() + userInput.slice( 1 ),
+                               aulimit: maxRows
                        } ).done( function ( data ) {
                                var users = $.map( data.query.allusers, function ( userObj ) {
                                        return userObj.name;
                                } );
-                               // Set the results as the autocomplete options
-                               $textbox.suggestions( 'suggestions', users );
+                               response( users );
                        } ) );
                },
                cancel: function () {