Added release notes for 'ContentHandler::runLegacyHooks' removal
[mediawiki.git] / resources / src / mediawiki.special / mediawiki.special.search.js
blobe809f2ea93d2012e8b4f89cac737a71d668b8304
1 /*!
2  * JavaScript for Special:Search
3  */
4 ( function ( mw, $ ) {
5         $( function () {
6                 var $checkboxes, $headerLinks, updateHeaderLinks, searchWidget;
8                 // Emulate HTML5 autofocus behavior in non HTML5 compliant browsers
9                 if ( !( 'autofocus' in document.createElement( 'input' ) ) ) {
10                         $( 'input[autofocus]' ).eq( 0 ).focus();
11                 }
13                 // Create check all/none button
14                 $checkboxes = $( '#powersearch input[id^=mw-search-ns]' );
15                 $( '#mw-search-togglebox' ).append(
16                         $( '<label>' )
17                                 .text( mw.msg( 'powersearch-togglelabel' ) )
18                 ).append(
19                         $( '<input>' ).attr( 'type', 'button' )
20                                 .attr( 'id', 'mw-search-toggleall' )
21                                 .prop( 'value', mw.msg( 'powersearch-toggleall' ) )
22                                 .click( function () {
23                                         $checkboxes.prop( 'checked', true );
24                                 } )
25                 ).append(
26                         $( '<input>' ).attr( 'type', 'button' )
27                                 .attr( 'id', 'mw-search-togglenone' )
28                                 .prop( 'value', mw.msg( 'powersearch-togglenone' ) )
29                                 .click( function () {
30                                         $checkboxes.prop( 'checked', false );
31                                 } )
32                 );
34                 // Change the header search links to what user entered
35                 $headerLinks = $( '.search-types a' );
36                 searchWidget = OO.ui.infuse( 'searchText' );
37                 updateHeaderLinks = function ( value ) {
38                         $headerLinks.each( function () {
39                                 var parts = $( this ).attr( 'href' ).split( 'search=' ),
40                                         lastpart = '',
41                                         prefix = 'search=';
42                                 if ( parts.length > 1 && parts[ 1 ].indexOf( '&' ) !== -1 ) {
43                                         lastpart = parts[ 1 ].slice( parts[ 1 ].indexOf( '&' ) );
44                                 } else {
45                                         prefix = '&search=';
46                                 }
47                                 this.href = parts[ 0 ] + prefix + encodeURIComponent( value ) + lastpart;
48                         } );
49                 };
50                 searchWidget.on( 'change', updateHeaderLinks );
51                 updateHeaderLinks( searchWidget.getValue() );
53                 // When saving settings, use the proper request method (POST instead of GET).
54                 $( '#mw-search-powersearch-remember' ).change( function () {
55                         this.form.method = this.checked ? 'post' : 'get';
56                 } ).trigger( 'change' );
58         } );
60 }( mediaWiki, jQuery ) );