2 * JavaScript for Special:Search
6 var $checkboxes, $headerLinks;
8 // Emulate HTML5 autofocus behavior in non HTML5 compliant browsers
9 if ( !( 'autofocus' in document.createElement( 'input' ) ) ) {
10 $( 'input[autofocus]' ).eq( 0 ).focus();
13 // Create check all/none button
14 $checkboxes = $( '#powersearch input[id^=mw-search-ns]' );
15 $( '#mw-search-togglebox' ).append(
17 .text( mw.msg( 'powersearch-togglelabel' ) )
19 $( '<input type="button" />' )
20 .attr( 'id', 'mw-search-toggleall' )
21 .prop( 'value', mw.msg( 'powersearch-toggleall' ) )
23 $checkboxes.prop( 'checked', true );
26 $( '<input type="button" />' )
27 .attr( 'id', 'mw-search-togglenone' )
28 .prop( 'value', mw.msg( 'powersearch-togglenone' ) )
30 $checkboxes.prop( 'checked', false );
34 // Change the header search links to what user entered
35 $headerLinks = $( '.search-types a' );
36 OO.ui.infuse( 'searchText' ).on( 'change', function ( searchterm ) {
37 $headerLinks.each( function () {
38 var parts = $( this ).attr( 'href' ).split( 'search=' ),
41 if ( parts.length > 1 && parts[1].indexOf( '&' ) !== -1 ) {
42 lastpart = parts[1].slice( parts[1].indexOf( '&' ) );
46 this.href = parts[0] + prefix + encodeURIComponent( searchterm ) + lastpart;
50 // When saving settings, use the proper request method (POST instead of GET).
51 $( '#mw-search-powersearch-remember' ).change( function () {
52 this.form.method = this.checked ? 'post' : 'get';
53 } ).trigger( 'change' );
57 }( mediaWiki, jQuery ) );