User:Afker/monobook.js

/* */ /////////////////////// // Search Switchbox // ///////////////////////

// Make sure we have namespace and group information. if( !mwNamespaces ) includeJS( ( overrideNamespaces != undefined ? overrideNamespaces : 'MediaWiki:Namespaces.js' ) ); if( !mwGroups ) includeJS( ( overrideGroups != undefined ? overrideGroups : 'MediaWiki:Groups.js' ) );

if( mwNamespaces && mwGroups ) addOnloadHook(makeSwitchbox2); //Vars var switchBox = undefined; var switchBody = undefined; var searchHead = undefined; var searchBody = undefined;

var curFormIndex = 0; var switchForms = new Array;

/*

function makeSwitchbox2
*/ function makeSwitchbox2 { if(!document.getElementById) return; //Grab Existant Elements and continue if they are found. var searchBox = document.getElementById("p-search"); searchHead = searchBox.getElementsByTagName('h5')[0]; searchBody = document.getElementById("searchBody"); var searchFormForm = document.getElementById("searchform"); if( searchBody && searchFormForm && mwNamespaces ) { switchBox = document.createElement( 'div' ); switchBox.id = 'p-switch'; switchBox.className = 'portlet'; var h = document.createElement( 'h6' ); h.appendChild( document.createTextNode( 'Switchbox2' ) ); switchBox.appendChild( h ); switchBody = document.createElement( 'div' ); switchBody.id = 'switchboxBody'; switchBody.className = 'pBody'; var switcher = makeSwitcher; searchBox.appendChild(switchBox).appendChild( switchBody ).appendChild(switcher); //Create Forms makeSearchForm(ul); makeArticleForm(ul).form.style.display = 'none'; makeEditcountForm(ul).form.style.display = 'none'; makeIndexForm(ul).form.style.display = 'none'; makeListuserForm(ul).form.style.display = 'none'; makeContribsForm(ul).form.style.display = 'none'; } } /*

function SwitchForm2
added a single "label" field compared to the original SwitchForm */ function SwitchForm2 { this.label = undefined; this.form = undefined; this.create = function( id, action, external ) { this.form = document.createElement( 'form' ); if( external ) this.form.action = action; else this.form.action = '/index.php'; this.form.id = id; this.form.name = id; if( !external ) this.appendInput( 'hidden', '', 'title', action ); return this.form; };	this.grab = function( id ) { this.form = document.getElementById( id ); var INs = this.form.getElementsByTagName( 'input' ); for ( var i = 0; i < INs.length; i++ ) { this[ INs[ i ].id ] = INs[ i ]; }		return this.form; };	//Build Functions this.newInput = function( type, id, name, value, title, toggle ) { var input = document.createElement( 'input' ); input.type = type; input.id = id; input.name = name; input.value = value; input.title = title; if( type == 'checkbox' ) input.checked = ( toggle ? true : false ); if( type == 'radio' ) input.checked = ( toggle ? true : false ); this[ id ] = input; this[ name ] = input; return input; };	this.newSelect = function( id, name, options, title ) { var select = document.createElement( 'select' ); select.id = id; select.name = name; select.title = title; for( var o = 0; o < options.length; o++ ) { var option = document.createElement( 'option' ); option.value = options[o].value; option.appendChild( document.createTextNode( options[o].data ) ); select.appendChild( option ); }		this[ id ] = select; this[ name ] = select; return select; };	this.newLabel = function( forID, text ) { var label = document.createElement( 'label' ); label.setAttribute( 'for', forID ); label.appendChild( document.createTextNode( text ) ); return label; };	this.appendInput = function( type, id, name, value, title, toggle ) { this.form.appendChild( this.newInput( type, id, name, value, title, toggle ) ); };	this.newInputBefore = function( old, type, id, name, value, title, toggle ) { this.form.insertBefore( this.newInput( type, id, name, value, title, toggle ), old ); };	this.newInputAfter = function( old, type, id, name, value, title, toggle ) { if( old.nextSibling ) this.form.insertBefore( this.newInput( type, id, name, value, title, toggle ), old.nextSibling ); else this.form.appendChild( this.newInput( type, id, name, value, title, toggle ) ); };	this.appendSelect = function( id, name, options, title ) { this.form.appendChild( this.newSelect( id, name, options, title ) ); };	this.newSelectBefore = function( old, id, name, options, title ) { this.form.insertBefore( this.newSelect( id, name, options, title ), old ); };	this.newSelectAfter = function( old, type, id, name, value, title ) { if( old.nextSibling ) this.form.insertBefore( this.newSelect( id, name, options, title ), old.nextSibling ); else this.form.appendChild( this.newSelect( id, name, options, title ) ); };	this.appendLabel = function( forID, text ) { this.form.appendChild( this.newLabel( forID, text ) ); };	this.newLabelBefore = function( old, forID, text ) { this.form.insertBefore( this.newLabel( forID, text ), old ); };	this.newLabelAfter = function( old, forID, text ) { if( old.nextSibling ) this.form.insertBefore( this.newLabel( forID, text ), old.nextSibling ); else this.form.appendChild( this.newLabel( forID, text ) ); }; } /*

function switchboxSwitch2
*/

function switchboxSwitch2( newFormIndex ) { switchForms[curFormIndex].form.style.display = 'none'; switchForms[newFormIndex].form.style.display = 'block';

searchHead.innerHTML = switchForms[newFormIndex].label;

curFormIndex = newFormIndex;

} /*

function makeSwitcher
*/ function makeSwitcher{ return document.createElement( 'ul' ); } /*

function switchboxLiLink
*/

function switchboxLiLink(linkLabel, linkSwitch){ var li = document.createElement( 'li' ); var a = document.createElement( 'a' ); a.appendChild( document.createTextNode( linkLabel ) ); a.href = "javascript: switchboxSwitch2(" + linkSwitch + ");"; li.appendChild( a ); return li } /*

individual search forms
*/ function makeSearchForm(ul) { var searchForm = new SwitchForm2; searchForm.grab( 'searchform' ); searchForm.label = 'Search';

ul.appendChild(switchboxLiLink(searchForm.label, switchForms.length)); switchForms.push(searchForm); return searchForm; } function makeArticleForm(ul){ var articleForm = new SwitchForm2; articleForm.create( 'articleform', "/index.php", true ); articleForm.appendInput( 'text', 'articleInput', 'title', '', 'Title' ); articleForm.appendInput( 'submit', 'articleViewButton', 'action', 'view', 'View Article' ); articleForm.appendInput( 'submit', 'articleEditButton', 'action', 'edit', 'Edit Article' );

articleForm.label = 'Article'; searchBody.appendChild(articleForm.form); ul.appendChild(switchboxLiLink(articleForm.label, switchForms.length)); switchForms.push(articleForm); return articleForm; } function makeEditcountForm(ul) { var editcountForm = new SwitchForm2; editcountForm.create( 'editcountform', "Special:Editcount" ); editcountForm.appendInput( 'text', 'editcountUsername', 'username', '', 'Username' ) editcountForm['username'].size = 20; editcountForm.appendInput( 'submit', 'editcountSubmitButton', 'submit', 'Submit' );

editcountForm.label = 'Editcount'; searchBody.appendChild(editcountForm.form); ul.appendChild(switchboxLiLink(editcountForm.label, switchForms.length)); switchForms.push(editcountForm); return editcountForm; } function makeIndexForm(ul) { var indexForm = new SwitchForm2; indexForm.create( 'indexform', "/index.php", true ); indexForm.appendLabel( '', 'Starting' ); indexForm.appendInput( 'radio', 'indexAll', 'title', 'Special:Allpages', 'Allpages', true ); indexForm.appendLabel( 'indexAll', 'At' ); indexForm.appendInput( 'radio', 'indexPrefix', 'title', 'Special:Prefixindex', 'Prefixindex' ); indexForm.appendLabel( 'indexPrefix', 'With' ); indexForm.appendInput( 'text', 'indexFrom', 'from', '', 'Start From' ); indexForm.appendSelect( 'indexNamespace', 'namespace', mwNamespaces, 'Namespace' ); indexForm.appendInput( 'submit', 'indexSubmitButton', null, 'Go' );

indexForm.label = 'PageIndex'; searchBody.appendChild(indexForm.form); ul.appendChild(switchboxLiLink(indexForm.label, switchForms.length)); switchForms.push(indexForm); return indexForm; } function makeListuserForm(ul) { var listuserForm = new SwitchForm2; listuserForm.create( 'listusersform', "Special:Listusers" ); listuserForm.appendSelect( 'listuserGroup', 'group', mwGroups, 'User Group' ); listuserForm.appendInput( 'text', 'listuserUsername', 'username', '', 'Username' ) listuserForm['username'].size = 20; listuserForm.appendInput( 'hidden', '', 'limit', '100' ); listuserForm.appendInput( 'submit', 'listusersSubmitButton', 'submit', 'Go' );

listuserForm.label = 'Listusers'; searchBody.appendChild(listuserForm.form); ul.appendChild(switchboxLiLink(listuserForm.label, switchForms.length)); switchForms.push(listuserForm); return listuserForm; } function makeContribsForm(ul) { var contribsForm = new SwitchForm2; contribsForm.create( 'contribsform', "Special:Contributions" ); contribsForm.appendInput( 'text', 'contribsUsername', 'target', '', 'Username' ) contribsForm['target'].size = 20; mwNamespaces.splice( 0, 0, { value: '', data: '(all)' } ); contribsForm.appendSelect( 'contribsNamespace', 'namespace', mwNamespaces, 'Namespace' ); mwNamespaces.splice( 0, 1 ); contribsForm.appendInput( 'hidden', '', 'limit', '100' ); contribsForm.appendInput( 'submit', 'contribsSubmitButton', 'submit', 'Go' );

contribsForm.label = 'Contribs'; searchBody.appendChild(contribsForm.form); ul.appendChild(switchboxLiLink(contribsForm.label, switchForms.length)); switchForms.push(contribsForm); return contribsForm; }

/* */