User:PanSola/WikiFormAter.js

/* WikiFormAter, Version 0.5alpha  */

/* This should be loaded from MediaWiki:common.js */ /*

Globals
*/ var WIKIFORMATER_RECEIPES = new Array(0); var WIKIFORMATER_VERSION = '0.6 alpha'; /*

Includes
Inclusion order of recipes affects auto-detection order.

Uses: */ DocWriteJS('WikiFormAter.js/abstractions'); DocWriteJS('WikiFormAter.js/recipeCreature');
 * User:PanSola/WikiFormAter.js/abstractions
 * User:PanSola/WikiFormAter.js/recipeCreature
 * MediaWiki:WikiFormAter.js/abstractions
 * MediaWiki:WikiFormAter.js/recipeCreature

/*

Main functions
*/

/*

WikiFormAterInit
*/

function WikiFormAterInit { if(queryString('action')!='edit' && queryString('action')!='submit') return;

/* hides the hard-wired links provided by MediaWiki:NewArticleText which is used (new articles only) if the user disables Javascript */ var hardlinkdiv = document.getElementById('WikiFormAter_hard_links'); if(hardlinkdiv) { hardlinkdiv.style.display = 'none'; }

var editBuffer = document.getElementById("editform"); var anchorDiv = editBuffer.parentNode.insertBefore(document.createElement("div");, editBuffer); var anchorDiv.id = 'WikiFormAter_Anchor'; var anchorDiv.style.clear = 'both'; var anchorDiv.width = '100%';

var FormAterDiv = anchorDiv.appendChild(document.createElement("div")); FormAterDiv.id = 'FormAterDiv'; FormAterDiv.style.border = '1px solid black';

FormAterDiv.appendChild(document.createElement('B')).appendTextNode('WikiFormAter, version ' 				+ WIKIFORMATER_VERSION);

var reportBugLnk = FormAterDiv.appendChild(document.createElement('A')); reportBugLnk.href = ''; reportBugLnk.appendChild('report a bug'); FormAterDiv.appendChild(document.createElement('HR'));

for (var i = 0; i < WIKIFORMATER_RECEIPE.length; i++){ FormAterDiv.appendChild( WikiFormAterRecipe_getLabel( WIKIFORMATER_RECEIPE[i]) ); } }

addOnloadHook(WikiFormAterInit);

/*

WikiFormAter_getDish(recipeIdx)
*/

function WikiFormAter_getDish(recipeIdx){ var dish = document.getElementById('WikiFormAter_dish_' + recipeIdx); if (!dish) { WikiFormEater_setupDish(recipeIdx); } else { dish.style.display='block'; }	document.getElementById('FormAterDiv').style.display='none'; }

/*

WikiFormEater_setupDish(recipeIdx)
*/

function WikiFormEater_setupDish(recipeIdx){ var recipe = WIKIFORMATER_RECEIPES[recipeIdx]; var name = WikiFormAterRecipe_getName(recipe);

var toolsDiv = document.getElementById('WikiFormAter_Anchor').appendChild(document.createElement('DIV')); toolsDiv.style.border='1px solid black'; toolsDiv.id = 'WikiFormAter_dish_' + recipeIdx; toolsDiv.style.clear='both';

var mainForm = document.createElement('FORM'); mainForm.id = 'WikiFormAter_' + name + '_Form'; mainForm.name = mainForm.id; mainForm.action = 'javascript:return false;'; mainForm.onSubmit = 'return false;';

mainForm.appendChild(document.createElement('B')).appendTextNode('WikiFormAter ' 				+ name + ' extension, version ' + WIKIFORMATER_VERSION);

var reportBugLnk = mainForm.appendChild(document.createElement('A')); reportBugLnk.href = ''; reportBugLnk.appendChild('report a bug');

mainForm.appendChild(document.createElement('HR'));

var returnLnk = mainForm.appendChild(document.createElement('A')); returnLnk.href = 'javascript:openFormAterMenu("'+ toolsDiv.id + '");');	returnLnk.appendChild(document.createTextNode('Return to main menu');

var innerDiv = mainForm.appendChild(document.createElement('DIV')); innerDiv.id = mainForm.id + '_meat';

var buttonsDiv = mainForm.appendChild(document.createElement('DIV'));

var eatingButton = buttonsDiv.appendChild(document.createElement('INPUT')); eatingButton.type = 'SUBMIT'; eatingButton.value = 'Eat Form!'; eatingButton.onClick = 'WikiFormAter_EatForm(' + recipeIdx + '); return false;');

var regurgitateButton = buttonsDiv.appendChild(document.createElement('INPUT')); regurgitateButton.type = 'SUBMIT'; regurgitateButton.value = 'Regurgitate Data'; regurgitateButton.onClick = 'WikiFormAter_RegurgitateData(' + recipeIdx + '); return false;');

if (WIKIFORMATER_AUTOREGURGITATE) WikiFormAterRecipe_getRegurgitater(recipe); } /*

openFormAterMenu(foodDiv)
*/

function openFormAterMenu(foodDiv) { document.getElementById('WikiFormAterDiv').style.display='block'; document.getElementById(foodDiv).style.display='none'; }

/*

autoFormAte
*/ /* Modular section. Add additional tools for other templates here. */ function autoFormAte{ //	if (extractSkillTemplate){ //		return; //	} } /*

Util functions
*/ /*

oneSplit(inputString, separator)
*/ /* similar to split, but only at first occurance, and keep the rest intact */ function oneSplit(inputString, separator){ var idx = inputString.indexOf(separator); if (idx == -1){ return [,]; }	var car = inputString.slice(0, idx); var cdr = inputString.slice(idx+separator.length); return [car,cdr]; } /*

trimString(aString)
*/ // Removes whitespaces from the beginning and the end of a string, but not the middle // Thanks Datrio for the quick help! function trimString(aString){ return aString.replace(/^\s+|\s+$/g, ""); } /*

extractParameter(paramName, assignments)
*/ function extractParameter(paramName, assignments){ var result = ''; for (var i=0; i<assignments.length; i++){ var myAssign = 	assignments[i];

var Cons = oneSplit(myAssign,'=') var Car = trimString(Cons[0]); var Cdr = trimString(Cons[1]); if ( Car == (trimString(paramName)) && (Cdr != '') ){ result = Cdr; assignments[i] = ''; } 	}	return result; } /*

debug(message)
*/ function debug(message){ if (!DEBUGMODE) return; qDebugMsgLn(message); } /*

doubleSplit(input,break1,break2)
*/ /* Takes a string, break it at two locations by first occurance of two different criteria */ function doubleSplit(input,break1,break2){ var ConsCons = oneSplit(input,break1); var Cons = oneSplit(ConsCons[1],break2); return [ConsCons[0], Cons[0], Cons[1]]; } /*

queryString(p)
*/ /* Taken from wookiepdia */ function queryString(p) { var re = RegExp('[&?]' + p + '=([^&]*)'); var matches;

if(matches = re.exec(document.location)) { try { return decodeURI(matches[1]); }       catch(e) { } }

return null; }

/* */