User:PanSola/WikiFormAter.js

/* WikiFormAter, Version 0.5alpha  */

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

Globals
*/ var WIKIFORMATER_RECEIPES = new Array(0); /*

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 FormAterDiv= document.createElement("div"); FormAterDiv.id = 'FormAterDiv'; FormAterDiv.style.border = '1px solid black'; FormAterDiv.style.clear='both'; FormAterDiv.innerHTML = 'WikiFormAter version 0.5alpha \n'; FormAterDiv.innerHTML = FormAterDiv.innerHTML + ' report a bug \n';

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

//	WikiFormAter.innerHTML = WikiFormAter.innerHTML + 'Auto-detect format ';

editBuffer.parentNode.insertBefore(WikiFormAterDiv, editBuffer);

}

addOnloadHook(WikiFormAterInit);

/*

cookUpForm(recipeIdx)
*/

function cookUpForm(recipeIdx){ var WikiFormAter_Dish = document.getElementById('WikiFormAter_dish_' + recipeIdx); if (!WikiFormAter_Dish) { WikiFormAterRecipe_getCooker(WIKIFORMATER_RECEIPES[recipeIdx])(recipeIdx); } else { WikiFormAter_Dish.style.display='block'; }	document.getElementById('FormAterDiv').style.display='none'; }

/*

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

/* */