From: MatmaRex Date: Wed, 24 Oct 2012 15:51:59 +0000 (+0200) Subject: (bug 41349) mediawiki.searchSuggest: Reorder code + fix selectors X-Git-Tag: 1.31.0-rc.0~21883^2 X-Git-Url: https://git.cyclocoop.org/%7B%24www_url%7Dadmin/compta/banques/?a=commitdiff_plain;h=97e51ed1e76219a2574247ca510a99f9828e238d;p=lhc%2Fweb%2Fwiklou.git (bug 41349) mediawiki.searchSuggest: Reorder code + fix selectors The code for general suggestions wouldn't run at all if no primary search box was found. I moved this check down, to where the box is actually needed. The selectors were hardcoded with no explanation. Added comments, added selector .mw-searchInput (as a generic one to be used by skins with multiple search boxes, currently only CologneBlue). Change-Id: Ie22fb66926688b0fdb28a121cfa0fb61ead0246d --- diff --git a/resources/mediawiki/mediawiki.searchSuggest.js b/resources/mediawiki/mediawiki.searchSuggest.js index ca719ab8b6..a4a700e89e 100644 --- a/resources/mediawiki/mediawiki.searchSuggest.js +++ b/resources/mediawiki/mediawiki.searchSuggest.js @@ -3,7 +3,7 @@ */ ( function ( mw, $ ) { $( document ).ready( function ( $ ) { - var map, + var map, 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. @@ -14,14 +14,6 @@ $searchRegion = $( '#simpleSearch, #searchInput' ).first(), $searchInput = $( '#searchInput' ); - // Ensure that the thing is actually present! - if ( $searchRegion.length === 0 ) { - // Don't try to set anything up if simpleSearch is disabled sitewide. - // The loader code loads us if the option is present, even if we're - // not actually enabled (anymore). - return; - } - // Compatibility map map = { browsers: { @@ -49,13 +41,19 @@ return; } - // Placeholder text for search box - $searchInput - .attr( 'placeholder', mw.msg( 'searchsuggest-search' ) ) - .placeholder(); - // General suggestions functionality for all search boxes - $( '#searchInput, #searchInput2, #powerSearchText, #searchText' ) + searchboxesSelectors = [ + // Primary searchbox on every page in standard skins + '#searchInput', + // Secondary searchbox in legacy skins (LegacyTemplate::searchForm uses id "searchInput + unique id") + '#searchInput2', + // Special:Search + '#powerSearchText', + '#searchText', + // Generic selector for skins with multiple searchboxes (used by CologneBlue) + '.mw-searchInput' + ]; + $( searchboxesSelectors.join(', ') ) .suggestions( { fetch: function ( query ) { var $el, jqXhr; @@ -104,6 +102,19 @@ $( this ).trigger( 'keypress' ); } ); + // Ensure that the thing is actually present! + if ( $searchRegion.length === 0 ) { + // Don't try to set anything up if simpleSearch is disabled sitewide. + // The loader code loads us if the option is present, even if we're + // not actually enabled (anymore). + return; + } + + // Placeholder text for search box + $searchInput + .attr( 'placeholder', mw.msg( 'searchsuggest-search' ) ) + .placeholder(); + // Special suggestions functionality for skin-provided search box $searchInput.suggestions( { result: {