From: gladoscc Date: Sun, 4 Jan 2015 00:14:46 +0000 (+1100) Subject: Make jquery.suggestions obey maxRows setting X-Git-Tag: 1.31.0-rc.0~12804^2 X-Git-Url: http://git.cyclocoop.org/%22%20.%20generer_url_ecrire%28%22statistiques_visites%22%2C%22%22%29%20.%20%22?a=commitdiff_plain;h=94649e6fc42cd1143a3c4a2d6b64f72d3494ed87;p=lhc%2Fweb%2Fwiklou.git Make jquery.suggestions obey maxRows setting The maxRows setting was previously unused and had no effect. This patch passes the property in the fetch() call, and makes it enforce the setting. Also updates mediawiki.userSuggest.js to use response() The previously unused setting of 7 is changed to 10 to match current behaviour. Bug: T39316 Change-Id: I2873963aba9fd751607d11904b94bfcec8eb2d32 --- diff --git a/resources/src/jquery/jquery.suggestions.js b/resources/src/jquery/jquery.suggestions.js index a83a70aa6b..f1b214e4dc 100644 --- a/resources/src/jquery/jquery.suggestions.js +++ b/resources/src/jquery/jquery.suggestions.js @@ -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, diff --git a/resources/src/mediawiki/mediawiki.searchSuggest.js b/resources/src/mediawiki/mediawiki.searchSuggest.js index d372e8f438..7b7ccf3f55 100644 --- a/resources/src/mediawiki/mediawiki.searchSuggest.js +++ b/resources/src/mediawiki/mediawiki.searchSuggest.js @@ -119,7 +119,7 @@ ]; $( searchboxesSelectors.join( ', ' ) ) .suggestions( { - fetch: function ( query, response ) { + fetch: function ( query, response, maxRows ) { var node = this[0]; api = api || new mw.Api(); @@ -128,6 +128,7 @@ action: 'opensearch', search: query, namespace: 0, + limit: maxRows, suggest: '' } ).done( function ( data ) { response( data[ 1 ] ); diff --git a/resources/src/mediawiki/mediawiki.userSuggest.js b/resources/src/mediawiki/mediawiki.userSuggest.js index aed093caa8..3964f0b285 100644 --- a/resources/src/mediawiki/mediawiki.userSuggest.js +++ b/resources/src/mediawiki/mediawiki.userSuggest.js @@ -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(); @@ -16,13 +15,13 @@ 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 () {