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 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 }

function classSearchForm { this.label = 'Search'; this.switchForm = undefined; this.instantiate = function(ul){ this.switchForm = new SwitchForm; this.switchForm.grab( 'searchform' );

ul.appendChild(switchboxLiLink(this.label, switchForms.length)); switchForms.push(this); } } function classArticleForm{ this.label = 'Article'; this.switchForm = undefined; this.instantiate = function(ul){ var 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' );

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

this.switchForm = editcountForm; searchBody.appendChild(this.switchForm.form); ul.appendChild(switchboxLiLink(this.label, switchForms.length)); switchForms.push(this); } } function classIndexForm { this.label = 'PageIndex'; this.switchForm = undefined; this.instantiate = function(ul){ var 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' );

this.switchForm = indexForm; searchBody.appendChild(this.switchForm.form); ul.appendChild(switchboxLiLink(this.label, switchForms.length)); switchForms.push(this); } } function classListuserForm { this.label = 'Listusers'; this.switchForm = undefined; this.instantiate = function(ul){ var 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' );

this.switchForm = listuserForm; searchBody.appendChild(this.switchForm.form); ul.appendChild(switchboxLiLink(this.label, switchForms.length)); switchForms.push(this); } } function classContribsForm { this.label = 'Contribs'; this.switchForm = undefined; this.instantiate = function(ul){ var 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' );

this.switchForm = contribsForm; searchBody.appendChild(this.switchForm.form); ul.appendChild(switchboxLiLink(this.label, switchForms.length)); switchForms.push(this); } }

//Functions 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( 'h5' ); h.appendChild( document.createTextNode( 'Switchbox' ) ); switchBox.appendChild( h ); switchBody = document.createElement( 'div' ); switchBody.id = 'switchboxBody'; switchBody.className = 'pBody'; var ul = document.createElement( 'ul' ); searchBox.appendChild(switchBox).appendChild( switchBody ).appendChild(ul); //Create Forms new classSearchForm.instantiate(ul); new classArticleForm.instantiate(ul); new classEditcountForm.instantiate(ul); new classIndexForm.instantiate(ul); new classListuserForm.instantiate(ul); new classContribsForm.instantiate(ul);

for (var i=1; i < switchForms.length; i++){ switchForms.form.style.display = 'none'; }	} }

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

searchHead.innerHTML = switchForms[newFormIdx].label;

curFormIdx = newFormIdx;

//	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 ); } } /* */