/** * Add search suggestions to the search form. */ ( function ( mw, $ ) { $( function () { var 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 = { browsers: { // Left-to-right languages ltr: { // SimpleSearch is broken in Opera < 9.6 opera: [['>=', 9.6]], docomo: false, blackberry: false, ipod: false, iphone: false }, // Right-to-left languages rtl: { opera: [['>=', 9.6]], docomo: false, blackberry: false, ipod: false, iphone: false } } }; if ( !$.client.test( map ) ) { return; } // Compute form data for search suggestions functionality. function computeResultRenderCache( context ) { var $form, formAction, baseHref, linkParams; // Compute common parameters for links' hrefs $form = context.config.$region.closest( 'form' ); formAction = $form.attr( 'action' ); baseHref = formAction + ( formAction.match(/\?/) ? '&' : '?' ); 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