Merging resourceloader branch into trunk. Full documentation is at http://www.mediawi...
[lhc/web/wiklou.git] / resources / mediawiki / legacy / mediawiki.legacy.search.js
1 /*
2 * Legacy emulation for the now depricated skins/common/search.js
3 *
4 * Progressive enhancement for Special:Search
5 */
6
7 ( function( $, mw ) {
8
9 /* Extension */
10
11 $.extend( true, mw.legacy, {
12
13 /* Functions */
14
15 /**
16 * Change the search link to what user entered
17 */
18 'mwSearchHeaderClick': function( obj ) {
19 var searchbox = document.getElementById( 'searchText' );
20 if ( searchbox === null ) {
21 searchbox = document.getElementById( 'powerSearchText' );
22 }
23 if ( searchbox === null ) {
24 return; // should always have either normal or advanced search
25 }
26 var searchterm = searchbox.value;
27 var parts = obj.href.split( 'search=' );
28 var lastpart = '';
29 var prefix = 'search=';
30 if ( parts.length > 1 && parts[1].indexOf('&') >= 0 ) {
31 lastpart = parts[1].substring( parts[1].indexOf('&') );
32 } else {
33 prefix = '&search=';
34 }
35 obj.href = parts[0] + prefix + encodeURIComponent( searchterm ) + lastpart;
36 },
37 'mwToggleSearchCheckboxes': function( btn ) {
38 if ( !document.getElementById ) {
39 return;
40 }
41 var nsInputs = document.getElementById( 'powersearch' ).getElementsByTagName( 'input' );
42 var isChecked = false;
43 for ( var i = 0; i < nsInputs.length; i++ ) {
44 var pattern = /^ns/;
45 if ( ( nsInputs[i].type == 'checkbox' ) && ( pattern.test( nsInputs[i].name ) ) ) {
46 switch ( btn ) {
47 case 'none':
48 if ( nsInputs[i].checked ) {
49 nsInputs[i].checked = false;
50 }
51 break;
52 case 'all':
53 if ( !nsInputs[i].checked ) {
54 nsInputs[i].checked = true;
55 }
56 break;
57 }
58 }
59 }
60 }
61 } );
62
63 } )( jQuery, mediaWiki );