/*! * Add search suggestions to the search form. */ ( function ( mw, $ ) { $( function () { var api, map, resultRenderCache, 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. // For Vector the suggestion box should align with the simpleSearch // container's borders, in other skins it should align with the input // element (not the search form, as that would leave the buttons // vertically between the input and the suggestions). $searchRegion = $( '#simpleSearch, #searchInput' ).first(), $searchInput = $( '#searchInput' ); // 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 computeResultRenderCache( context ) { var $form, baseHref, linkParams; // Compute common parameters for links' hrefs $form = context.config.$region.closest( 'form' ); baseHref = $form.attr( 'action' ); baseHref += baseHref.indexOf( '?' ) > -1 ? '&' : '?'; linkParams = {}; $.each( $form.serializeArray(), function ( idx, obj ) { linkParams[ obj.name ] = obj.value; } ); return { textParam: context.data.$textbox.attr( 'name' ), linkParams: linkParams, baseHref: baseHref }; } // The function used to render the suggestions. function renderFunction( text, context ) { if ( !resultRenderCache ) { resultRenderCache = computeResultRenderCache( context ); } // linkParams object is modified and reused resultRenderCache.linkParams[ resultRenderCache.textParam ] = text; // this is the container