User:Func/wpfunc/searchhelp.js
Appearance
Code that you insert on this page could contain malicious content capable of compromising your account. If you import a script from another page with "importScript", "mw.loader.load", "iusc", or "lusc", take note that this causes you to dynamically load a remote script, which could be changed by others. Editors are responsible for all edits and actions they perform, including by scripts. User scripts are not centrally supported and may malfunction or become inoperable due to software changes. A guide to help you find broken scripts is available. If you are unsure whether code you are adding to this page is safe, you can ask at the appropriate village pump. This code will be executed when previewing this page. |
Documentation for this user script can be added at User:Func/wpfunc/searchhelp. |
// Currently, restructures the checkboxes in a table,
// adding multiple-select checkboxes:
//
// √ all √ all √ everything
// √ (Main) √ ...talk √ both
// √ User √ ...talk √ both
// √ Wikipedia √ ...talk √ both
// √ Image √ ...talk √ both
// √ MediaWiki √ ...talk √ both
// √ Template √ ...talk √ both
// √ Help √ ...talk √ both
// √ Category √ ...talk √ both
// √ Portal √ ...talk √ both
//
// More stuff to add in the future....
//
function SearchHelp()
{
var form = document.getElementById( 'powersearch' ); if ( ! form ) return;
// Stupid ECMA....
//
// Eh, good place to do something else here anyway.
//
var labels = [], temp = form.getElementsByTagName( 'label' );
for ( var x = 0; x < temp.length; x++ )
{
labels[ x ] = temp[ x ];
labels[ x ].onclick = function()
{ this.checked = ! this.checked;
SearchHelpUpdate();
return true;
}
}
form.labels = labels; // allow event handlers to access, numerically
var i, text, input, label, td, tr, table;
for ( i = 1; i < labels.length; i += 2 )
labels[ i ].lastChild.nodeValue = '...talk';
table = document.createElement( 'table' );
// can't see what's going on....
//
form.insertBefore( table, form.firstChild.nextSibling );
tr = document.createElement( 'tr' );
td = document.createElement( 'td' );
label = document.createElement( 'label' );
input = document.createElement( 'input' );
input.type = 'checkbox';
form.col1 = input;
input.onclick = function()
{ var checked = ! this.checked;
for ( var i = 0; i < this.form.labels.length; i += 2 )
this.form.labels[ i ].firstChild.checked = checked;
this.checked = checked;
SearchHelpUpdate( this.form );
return true;
}
label.appendChild( input );
label.appendChild( document.createTextNode( 'all' ) );
label.style.fontStyle = 'italic';
td.appendChild( label );
tr.appendChild( td );
td = document.createElement( 'td' );
label = document.createElement( 'label' );
input = document.createElement( 'input' );
input.type = 'checkbox';
form.col2 = input;
input.onclick = function()
{ var checked = ! this.checked;
for ( var i = 1; i < this.form.labels.length; i += 2 )
this.form.labels[ i ].firstChild.checked = checked;
this.checked = checked;
SearchHelpUpdate( this.form );
return true;
}
label.appendChild( input );
label.appendChild( document.createTextNode( 'all' ) );
label.style.fontStyle = 'italic';
td.appendChild( label );
tr.appendChild( td );
td = document.createElement( 'td' );
label = document.createElement( 'label' );
input = document.createElement( 'input' );
input.type = 'checkbox';
form.allVals = input;
input.onclick = function()
{ for ( var i = 0; i < this.form.labels.length; i += 2 )
{ this.form.labels[ i ].firstChild.checked = this.checked;
this.form.labels[ i + 1 ].firstChild.checked = this.checked;
//this.form[ 'both' + i ] .firstChild.checked = checked;
}
this.form.col1.checked = this.checked;
this.form.col2.checked = this.checked;
return true;
}
label.appendChild( input );
label.appendChild( document.createTextNode( 'everything' ) );
label.style.fontStyle = 'italic';
td.appendChild( label );
tr.appendChild( td );
table.appendChild( tr );
for ( i = 0; i < labels.length; i += 2 )
{
tr = document.createElement( 'tr' );
td = document.createElement( 'td' ); td.appendChild( labels[ i ] );
tr.appendChild( td );
td = document.createElement( 'td' ); td.appendChild( labels[ i + 1 ] );
tr.appendChild( td );
td = document.createElement( 'td' );
label = document.createElement( 'label' );
input = document.createElement( 'input' );
input.type = 'checkbox';
form[ 'both' + i ] = input;
input.box1 = labels[ i ].firstChild;
input.box2 = labels[ i + 1 ].firstChild;
input.onclick = function()
{ this.box1.checked =
this.box2.checked = ! this.checked;
this.checked = ! this.checked;
SearchHelpUpdate( this.form );
return true;
}
label.appendChild( input );
label.appendChild( document.createTextNode( 'both' ) );
label.style.fontStyle = 'italic';
td.appendChild( label );
tr.appendChild( td );
table.appendChild( tr );
}
SearchHelpUpdate( form );
}
function SearchHelpUpdate( form )
{
var val1, val2, col1 = true, col2 = true;
var labels = form.labels;
for ( var i = 0; i < form.labels.length; i += 2 )
{
val1 = labels[ i ].firstChild.checked;
val2 = labels[ i + 1 ].firstChild.checked;
form[ 'both' + i ].checked = ( val1 && val2 );
if ( ! val1 ) col1 = false;
if ( ! val2 ) col2 = false;
}
form.col1.checked = col1;
form.col2.checked = col2;
form.allVals.checked = col1 && col2;
}
if ( window.addEventListener ) window.addEventListener( 'load', SearchHelp, false );
else if ( window.attachEvent ) window.attachEvent( 'onload', SearchHelp );