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(makeSwitchbox); //Vars var switchBox = undefined; var switchBody = undefined; var searchHead = undefined; var searchBody = undefined; var searchForm = undefined; var articleForm = undefined; var editcountForm = undefined; var indexForm = undefined; var listuserForm = undefined; var contribsForm = undefined; //Functions function makeSwitchbox { 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( 'h5' ); h.appendChild( document.createTextNode( 'Switchbox' ) ); switchBox.appendChild( h ); switchBody = document.createElement( 'div' ); switchBody.id = 'switchboxBody'; switchBody.className = 'pBody'; var ul = document.createElement( 'ul' ); var li = document.createElement( 'li' ); var a = document.createElement( 'a' ); a.appendChild( document.createTextNode( 'Search' ) ); a.href = "javascript: switchboxSwitch( 'search' );"; li.appendChild( a ); ul.appendChild( li ); li = document.createElement( 'li' ); a = document.createElement( 'a' ); a.appendChild( document.createTextNode( 'Article' ) ); a.href = "javascript: switchboxSwitch( 'article' );"; li.appendChild( a ); ul.appendChild( li ); li = document.createElement( 'li' ); a = document.createElement( 'a' ); a.appendChild( document.createTextNode( 'Editcount' ) ); a.href = "javascript: switchboxSwitch( 'editcount' );"; li.appendChild( a ); ul.appendChild( li ); li = document.createElement( 'li' ); a = document.createElement( 'a' ); a.appendChild( document.createTextNode( 'PageIndex' ) ); a.href = "javascript: switchboxSwitch( 'index' );"; li.appendChild( a ); ul.appendChild( li ); li = document.createElement( 'li' ); a = document.createElement( 'a' ); a.appendChild( document.createTextNode( 'Listusers' ) ); a.href = "javascript: switchboxSwitch( 'listuser' );"; li.appendChild( a ); ul.appendChild( li ); li = document.createElement( 'li' ); a = document.createElement( 'a' ); a.appendChild( document.createTextNode( 'Contribs' ) ); a.href = "javascript: switchboxSwitch( 'contribs' );"; li.appendChild( a ); ul.appendChild( li ); switchBody.appendChild( ul ); switchBox.appendChild( switchBody ); document.getElementById( 'column-one' ).insertBefore( switchBox, searchBox ); //Create Forms searchForm = new SwitchForm; searchForm.grab( 'searchform' ); //	Article Box articleForm = new SwitchForm; 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' ); //	Editcount Box editcountForm = new SwitchForm; editcountForm.create( 'editcountform', "Special:Editcount" ); editcountForm.appendInput( 'text', 'editcountUsername', 'username', '', 'Username' ) editcountForm['username'].size = 20; editcountForm.appendInput( 'submit', 'editcountSubmitButton', 'submit', 'Submit' ); //	PageIndex Box indexForm = new SwitchForm; 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' ); //	Listusers Box listuserForm = new SwitchForm; 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' ); //	Contribs Box contribsForm = new SwitchForm; 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' ); } } function SwitchForm { 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 switchboxSwitch( sw ) { searchBody.innerHTML = ''; if( sw == 'article' ) { searchHead.innerHTML = 'Article'; searchBody.appendChild( articleForm.form ); } else if( sw == 'editcount' ) { searchHead.innerHTML = 'Editcount'; searchBody.appendChild( editcountForm.form ); } else if( sw == 'index' ) { searchHead.innerHTML = 'PageIndex'; searchBody.appendChild( indexForm.form ); } else if( sw == 'listuser' ) { searchHead.innerHTML = 'Listusers'; searchBody.appendChild( listuserForm.form ); } else if( sw == 'contribs' ) { searchHead.innerHTML = 'Contributions'; searchBody.appendChild( contribsForm.form ); } else { searchHead.innerHTML = 'Search'; searchBody.appendChild( searchForm.form ); } } /* */