summaryrefslogtreecommitdiffstats
path: root/skins/common/search.js
blob: ff1142911276cac8cbda58859b19c8a9706d176a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
// JS specific to Special:Search

// change the search link to what user entered
function mwSearchHeaderClick( obj ) {
	var searchbox = document.getElementById( 'searchText' );
	if( searchbox === null ) {
		searchbox = document.getElementById( 'powerSearchText' );
	}
	if( searchbox === null ) {
		return; // should always have either normal or advanced search
	}

	var searchterm = searchbox.value;
	var parts = obj.href.split( 'search=' );
	var lastpart = '';
	var prefix = 'search=';
	if( parts.length > 1 && parts[1].indexOf('&') >= 0 ) {
		lastpart = parts[1].substring( parts[1].indexOf('&') );
	} else {
		prefix = '&search=';
	}
	obj.href = parts[0] + prefix + encodeURIComponent( searchterm ) + lastpart;
}

function mwToggleSearchCheckboxes( btn ) {
	if( !document.getElementById ) {
		return;
	}

	var nsInputs = document.getElementById( 'powersearch' ).getElementsByTagName( 'input' );
	var isChecked = false;

	for ( var i = 0; i < nsInputs.length; i++ ) {
		var pattern = /^ns/;
		if ( ( nsInputs[i].type == 'checkbox' ) && ( pattern.test( nsInputs[i].name ) ) ) {
			switch ( btn ) {
				case 'none':
					if ( nsInputs[i].checked ) {
						nsInputs[i].checked = false;
					}
					break;
				case 'all':
					if ( !nsInputs[i].checked ) {
						nsInputs[i].checked = true;
					}
					break;
			}
		}
	}
}