*/
( 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.
$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: {
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;
var jqXhr = $(this).data( 'request' );
// If the delay setting has caused the fetch to have not even happened
// yet, the jqXHR object will have never been set.
- if ( jqXhr && $.isFunction ( jqXhr.abort ) ) {
+ if ( jqXhr && $.isFunction( jqXhr.abort ) ) {
jqXhr.abort();
$(this).removeData( 'request' );
}
$( 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: {
.append(
$( '<div>' )
.addClass( 'special-label' )
- .text( mw.msg( 'searchsuggest-containing' ) )
- )
- .append(
+ .text( mw.msg( 'searchsuggest-containing' ) ),
$( '<div>' )
.addClass( 'special-query' )
.text( query )
.show();
} else {
$el.find( '.special-query' )
- .empty()
.text( query )
.autoEllipsis();
}
},
select: function ( $input ) {
$input.closest( 'form' ).append(
- $( '<input type="hidden"/>', {
- name: 'fulltext',
- val: '1'
- })
+ $( '<input type="hidden" name="fulltext" value="1"/>' )
);
$input.closest( 'form' ).submit();
}
} );
-}( mediaWiki, jQuery ) );
\ No newline at end of file
+}( mediaWiki, jQuery ) );