ca719ab8b64b1c736f679e8f46e54398b2ad04b9
2 * Add search suggestions to the search form.
5 $( document
).ready( function ( $ ) {
7 // Region where the suggestions box will appear directly below
8 // (using the same width). Can be a container element or the input
9 // itself, depending on what suits best in the environment.
10 // For Vector the suggestion box should align with the simpleSearch
11 // container's borders, in other skins it should align with the input
12 // element (not the search form, as that would leave the buttons
13 // vertically between the input and the suggestions).
14 $searchRegion
= $( '#simpleSearch, #searchInput' ).first(),
15 $searchInput
= $( '#searchInput' );
17 // Ensure that the thing is actually present!
18 if ( $searchRegion
.length
=== 0 ) {
19 // Don't try to set anything up if simpleSearch is disabled sitewide.
20 // The loader code loads us if the option is present, even if we're
21 // not actually enabled (anymore).
28 // Left-to-right languages
30 // SimpleSearch is broken in Opera < 9.6
37 // Right-to-left languages
48 if ( !$.client
.test( map
) ) {
52 // Placeholder text for search box
54 .attr( 'placeholder', mw
.msg( 'searchsuggest-search' ) )
57 // General suggestions functionality for all search boxes
58 $( '#searchInput, #searchInput2, #powerSearchText, #searchText' )
60 fetch: function ( query
) {
63 if ( query
.length
!== 0 ) {
66 url
: mw
.util
.wikiScript( 'api' ),
75 success: function ( data
) {
76 if ( $.isArray( data
) && data
.length
) {
77 $el
.suggestions( 'suggestions', data
[1] );
81 $el
.data( 'request', jqXhr
);
85 var jqXhr
= $(this).data( 'request' );
86 // If the delay setting has caused the fetch to have not even happened
87 // yet, the jqXHR object will have never been set.
88 if ( jqXhr
&& $.isFunction( jqXhr
.abort
) ) {
90 $(this).removeData( 'request' );
94 select: function ( $input
) {
95 $input
.closest( 'form' ).submit();
101 .bind( 'paste cut drop', function () {
102 // make sure paste and cut events from the mouse and drag&drop events
103 // trigger the keypress handler and cause the suggestions to update
104 $( this ).trigger( 'keypress' );
107 // Special suggestions functionality for skin-provided search box
108 $searchInput
.suggestions( {
110 select: function ( $input
) {
111 $input
.closest( 'form' ).submit();
115 render: function ( query
) {
117 if ( $el
.children().length
=== 0 ) {
121 .addClass( 'special-label' )
122 .text( mw
.msg( 'searchsuggest-containing' ) ),
124 .addClass( 'special-query' )
130 $el
.find( '.special-query' )
135 select: function ( $input
) {
136 $input
.closest( 'form' ).append(
137 $( '<input type="hidden"/>', {
142 $input
.closest( 'form' ).submit();
145 $region
: $searchRegion
148 // In most skins (at least Monobook and Vector), the font-size is messed up in <body>.
149 // (they use 2 elements to get a sane font-height). So, instead of making exceptions for
150 // each skin or adding more stylesheets, just copy it from the active element so auto-fit.
152 .data( 'suggestions-context' )
154 .css( 'fontSize', $searchInput
.css( 'fontSize' ) );
158 }( mediaWiki
, jQuery
) );