User:Afker/Searchswitch.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;

// Can choose between the default list switcher or a dropdown box switcher var switcher = makeListSwitcher; //var switcher = makeDropDownSwitcher; /*

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'; searchBox.appendChild(switchBox).appendChild( switchBody ).appendChild(switcher.upperAttachPoint); //Create Forms makeSearchForm; makeArticleForm.style.display = 'none'; makeEditcountForm.style.display = 'none'; makeIndexForm.style.display = 'none'; makeListuserForm.style.display = 'none'; makeContribsForm.style.display = 'none'; } } /*

switchers
*/ /*

classSwitcher
*/ function classSwitcher { this.upperAttachPoint = undefined; this.lowerAttachPoint = undefined; this.labels = undefined; this.forms = undefined; this.curFormIndex = 0;

this.toAttach = undefined;

this.toSwitch = function(newFormIndex) { var oldForm = this.forms[this.curFormIndex]; var newForm = this.forms[newFormIndex]; var tempText = '';

var oldInputs = oldForm.getElementsByTagName('INPUT'); for (var i = 0; i < oldInputs.length; i++){ if (oldInputs[i].type == 'text'){ tempText = oldInputs[i].value; break; }		}		var newInputs = newForm.getElementsByTagName('INPUT'); for (var i = 0; i < newInputs.length; i++){ if (newInputs[i].type == 'text'){ newInputs[i].value = tempText; break; }		}

oldForm.style.display = 'none'; newForm.style.display = 'block'; searchHead.firstChild.value = this.labels[newFormIndex]; this.curFormIndex = newFormIndex; } } /*

makeListSwitcher
*/ function makeListSwitcher { var thisSwitcher = new classSwitcher; thisSwitcher.labels = new Array; thisSwitcher.forms = new Array;

thisSwitcher.upperAttachPoint = document.createElement( 'ul' ); thisSwitcher.lowerAttachPoint = thisSwitcher.upperAttachPoint;

thisSwitcher.toAttach = function(switchForm, label){ var newIndex = thisSwitcher.labels.length;

var a = document.createElement('a'); a.appendChild( document.createTextNode(label) ); a.href = "javascript:switcher.toSwitch(" + newIndex + ");"; var li = document.createElement('li'); li.appendChild(a) thisSwitcher.lowerAttachPoint.appendChild(li);

thisSwitcher.labels.push(label); thisSwitcher.forms.push(switchForm.form); return searchBody.appendChild(switchForm.form); }	return thisSwitcher; } /*

makeDropDownSwitcher
*/

function makeDropDownSwitcher { alert("omega"); var thisSwitcher = new classSwitcher; thisSwitcher.labels = new Array; thisSwitcher.forms = new Array;

thisSwitcher.upperAttachPoint = document.createElement( 'form' ); thisSwitcher.lowerAttachPoint = thisSwitcher.upperAttachPoint.appendChild(document.createElement('select')); thisSwitcher.upperAttachPoint.setAttribute('onChange', 'javascript:alert("a"); return switcher.dropSwitch;');

thisSwitcher.toAttach = function(switchForm, label){ var opt = document.createElement('option'); opt.text = label; try { thisSwitcher.lowerAttachPoint.add(opt, null); } catch (e){ thisSwitcher.lowerAttachPoint.add(opt); }

thisSwitcher.labels.push(label); thisSwitcher.forms.push(switchForm.form); return searchBody.appendChild(switchForm.form); }

thisSwitcher.dropSwitch = function{ //alert("b"); return thisSwitcher.toSwitch(thisSwitcher.lowerAttachPoint.selectedIndex); }	return thisSwitcher; }

/*

individual search forms
*/ function makeSearchForm { var searchForm = new SwitchForm; searchForm.grab( 'searchform' );

return switcher.toAttach(searchForm, 'Search'); } function makeArticleForm{ 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' );

return switcher.toAttach(articleForm, 'Article'); } function makeEditcountForm { 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' );

return switcher.toAttach(editcountForm, 'Editcount'); } function makeIndexForm { 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' );

return switcher.toAttach(indexForm, 'PageIndex'); } function makeListuserForm { 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' );

return switcher.toAttach(listuserForm, 'Listusers'); } function makeContribsForm { 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' );

return switcher.toAttach(contribsForm, 'Contribs'); }

/* */