* Add search suggestions to the search form.
*/
( function ( mw, $ ) {
+ var searchNS = $.map( mw.config.get( 'wgFormattedNamespaces' ), function ( nsName, nsID ) {
+ if ( nsID >= 0 && mw.user.options.get( 'searchNs' + nsID ) ) {
+ // Cast string key to number
+ return Number( nsID );
+ }
+ } );
mw.searchSuggest = {
// queries the wiki and calls response with the result
- request: function ( api, query, response, maxRows ) {
+ request: function ( api, query, response, maxRows, namespace ) {
return api.get( {
formatversion: 2,
action: 'opensearch',
search: query,
- namespace: 0,
+ namespace: namespace || searchNS,
limit: maxRows,
suggest: true
} ).done( function ( data, jqXHR ) {
};
$( function () {
- var api, map, searchboxesSelectors,
+ var api, searchboxesSelectors,
// Region where the suggestions box will appear directly below
// (using the same width). Can be a container element or the input
// itself, depending on what suits best in the environment.
$searchInput = $( '#searchInput' ),
previousSearchText = $searchInput.val();
- // Compatibility map
- map = {
- // SimpleSearch is broken in Opera < 9.6
- opera: [ [ '>=', 9.6 ] ],
- // Older Konquerors are unable to position the suggestions correctly (bug 50805)
- konqueror: [ [ '>=', '4.11' ] ],
- docomo: false,
- blackberry: false,
- // Support for iOS 6 or higher. It has not been tested on iOS 5 or lower
- ipod: [ [ '>=', 6 ] ],
- iphone: [ [ '>=', 6 ] ]
- };
-
- if ( !$.client.test( map ) ) {
- return;
- }
-
// Compute form data for search suggestions functionality.
function getFormData( context ) {
var $form, baseHref, linkParams;
*/
function getInputLocation( context ) {
return context.config.$region
- .closest( 'form' )
- .find( '[data-search-loc]' )
- .data( 'search-loc' ) || 'header';
+ .closest( 'form' )
+ .find( '[data-search-loc]' )
+ .data( 'search-loc' ) || 'header';
}
/**
var $this = $( this );
$this
.data( 'suggestions-context' )
- .data.$container
- .css( 'fontSize', $this.css( 'fontSize' ) );
+ .data.$container.css( 'fontSize', $this.css( 'fontSize' ) );
} );
// Ensure that the thing is actually present!