MediaWiki:Common.js

// Google Analytics JS code var _gaq = _gaq || []; _gaq.push(['_setAccount', 'UA-38837799-1']); _gaq.push(['_trackPageview']);

(function {   var ga = document.createElement('script');     ga.type = 'text/javascript';     ga.async = true;    ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';   var s = document.getElementsByTagName('script')[0];     s.parentNode.insertBefore(ga, s);  });

// End Google Analytics JS code

// =================================== start converter ========================================= // If you use this code please leave credits: S. Zurek, www.Encyclopedia-Magnetica.com, 2013 // =================================== start converter =========================================

function converterMultiplier {

var outputString;

// check if exists, if not do not execute the code if (document.getElementById("multiplierA")) {

// read parameters var converterString = document.getElementById('multiplierA').innerHTML; var converterArray = converterString.split(" ");

// convert parameters dataInInitialA = parseFloat(converterArray[0]); multiplierValueA = parseFloat(converterArray[1]); powerA = parseFloat(converterArray[2]); offsetA = parseFloat(converterArray[3]); unitA = converterArray[4];

dataInInitialB = parseFloat(converterArray[5]); multiplierValueB = parseFloat(converterArray[6]); powerB = parseFloat(converterArray[7]); offsetB = parseFloat(converterArray[8]); unitB = converterArray[9];

invisibleAll = converterArray[10];

// first converter document.getElementById('multiplierA').innerHTML = ' '+		'' + ' ' + unitA + ' ' + ' convert => " onClick="convertA" />' + ' ' + ''+ ' ' + unitB + ' '; + ' ';

// second converter (inverse) document.getElementById('multiplierB').innerHTML = ' '+		'' + ' ' + unitB + ' ' + ' convert => " onClick="convertB" />'+ ' ' + '' + ' ' + unitA; + ' ';

document.getElementById('inputA').value = dataInInitialA; document.getElementById('inputB').value = dataInInitialB;

if (invisibleAll == "invisible"){ document.getElementById('multiplierA').innerHTML = ' '; document.getElementById('multiplierB').innerHTML = ' '; } else { convertA convertB };

}; // end if exists here

};

function convertA { var dataInA; var dataOutA;

// read data dataInAtemp = parseFloat( document.getElementById('inputA').value );

dataInA = dataInAtemp.toPrecision(5);

// tell the user what was read out document.getElementById('inputA').value = dataInA; dataOutAtemp = Math.pow(dataInA,powerA) * multiplierValueA + offsetA; dataOutA = dataOutAtemp.toPrecision(5); document.getElementById('outputA').value = dataOutA; }

function convertB { var dataInB; var dataOutB;

// read data dataInBtemp = parseFloat( document.getElementById('inputB').value );

dataInB = dataInBtemp.toPrecision(5);

// tell the user what was read out document.getElementById('inputB').value = dataInB; dataOutBtemp = Math.pow(dataInB,powerB) * multiplierValueB + offsetB; dataOutB = dataOutBtemp.toPrecision(5); document.getElementById('outputB').value = dataOutB; }

addOnloadHook(converterMultiplier);

// ================= end of converter ==================

// ======================================= arbitrary function ================================== // If you use this code please leave credits: S. Zurek, www.Encyclopedia-Magnetica.com, 2013 // ======================================= arbitrary function ==================================

// declare OUTSIDE of function to make it global var arbFunctionCodeString;

function arbFunction {

// check if exists, if not do not execute the code if (document.getElementById("ArbFunctionCode")) {

// read the equation arbFunctionCodeString = document.getElementById('ArbFunctionCode').innerHTML; document.getElementById('ArbFunctionCode').innerHTML = ' ';

// read all parameters var arbFunctionString = document.getElementById('ArbFunctionParameters').innerHTML;

// use special string to split parameters - this is to allow usage of space in the strings var arbFunctionArray = arbFunctionString.split("_'_");

param0arb = parseFloat(arbFunctionArray[0]); param1arb = arbFunctionArray[1]; param2arb = parseFloat(arbFunctionArray[2]); param3arb = arbFunctionArray[3]; param4arb = parseFloat(arbFunctionArray[4]); param5arb = arbFunctionArray[5]; param6arb = parseFloat(arbFunctionArray[6]); param7arb = arbFunctionArray[7]; param8arb = arbFunctionArray[8];

// blank description of inactive parameters if (param2arb==0){param3arb="";}; if (param4arb==0){param5arb="";}; if (param6arb==0){param7arb="";};

// generate converter document.getElementById('ArbFunctionParameters').innerHTML = ' '+ param1arb + ''+'   '+ param3arb + ''+'   '+ param5arb + ''+'   '+ param7arb + ''+' ' + ''+'   &nbsp&nbsp&nbsp'+ param8arb + ''+ ' ';

// reformat numbers to fit into inputs param0arb = param0arb.toPrecision(5); document.getElementById('input1').value = param0arb; param2arb = param2arb.toPrecision(5); document.getElementById('input2').value = param2arb; param4arb = param4arb.toPrecision(5); document.getElementById('input3').value = param4arb; param6arb = param6arb.toPrecision(5); document.getElementById('input4').value = param6arb;

// hide unused inputs if (param2arb==0){document.getElementById("input2").style.visibility="hidden"; }; if (param4arb==0){document.getElementById("input3").style.visibility="hidden"; }; if (param6arb==0){document.getElementById("input4").style.visibility="hidden"; };

document.getElementById('noJavaScript').innerHTML = ' ';

// show result for the initial values computeEquation;

}; // end if exists

};

// active function function computeEquation {

// read data and reformat param0arb = parseFloat( document.getElementById('input1').value ); param0arb = param0arb.toPrecision(5); document.getElementById('input1').value = param0arb; param2arb = parseFloat( document.getElementById('input2').value ); param2arb = param2arb.toPrecision(5); document.getElementById('input2').value = param2arb; param4arb = parseFloat( document.getElementById('input3').value ); param4arb = param4arb.toPrecision(5); document.getElementById('input3').value = param4arb; param6arb = parseFloat( document.getElementById('input4').value ); param6arb = param6arb.toPrecision(5); document.getElementById('input4').value = param6arb;

// execute the main function outputStringInitial = eval(arbFunctionCodeString); outputString = parseFloat(outputStringInitial); outputString = outputString.toPrecision(5); document.getElementById('functionOutput').value = outputString;

};

addOnloadHook(arbFunction);

// ========== end of arb function ================

// ======================================= arbitrary unit converter ================================== // If you use this code please leave credits: S. Zurek, www.Encyclopedia-Magnetica.com, 2013 // ======================================= arbitrary unit converter ==================================

// declare OUTSIDE of function to make it global var arbFunctionCodeStringUnits;

function arbFunctionUnits {

// check if exists, if not do not execute the code if (document.getElementById("ArbFunctionParametersUnits")) {

// read all parameters var arbFunctionStringUnits = document.getElementById('ArbFunctionParametersUnits').innerHTML;

// use special string to split parameters - this is to allow usage of space in the strings var arbFunctionArrayUnits = arbFunctionStringUnits.split("_'_");

param0arbUnits = parseFloat(arbFunctionArrayUnits[0]); // value of unit A param1arbUnits = arbFunctionArrayUnits[1];            // name of unit A param2arbUnits = parseFloat(arbFunctionArrayUnits[2]); // value of unit B param3arbUnits = arbFunctionArrayUnits[3];             // name of unit B arbFunctionCodeStringUnitsA = arbFunctionArrayUnits[4];             // code to convert from A to B arbFunctionCodeStringUnitsB = arbFunctionArrayUnits[5];             // code to convert from B to A

// generate converter document.getElementById('ArbFunctionParametersUnits').innerHTML = ' '+ ''+' '+ param1arbUnits + ' ' + ' convert => " onClick="computeEquationUnits" />' + '  ' + ''+ ' ' + param3arbUnits + ' ' + ''+' '+ param3arbUnits + ' ' + '<input type="button" value=" => convert => " onClick="computeEquationUnits" />' + '  ' + '<input id="outputBUnits" type="text" readonly="" size="10" style="background-color: rgb(224, 224, 224);" />'+ ' ' + param1arbUnits + ' ' + ' '

// reformat numbers to fit into inputs param0arbUnits = param0arbUnits.toPrecision(5); document.getElementById('inputAUnits').value = param0arbUnits; param2arbUnits = param2arbUnits.toPrecision(5); document.getElementById('inputBUnits').value = param2arbUnits;

// hide "no JavaScript" error document.getElementById('noJavaScriptUnits').innerHTML = ' ';

// show result for the initial values computeEquationUnits;

}; // end "if exists" function

};

// active function function computeEquationUnits {

// read data and reformat param0arbUnits = parseFloat( document.getElementById('inputAUnits').value ); param0arbUnits = param0arbUnits.toPrecision(5); document.getElementById('inputAUnits').value = param0arbUnits;

param2arbUnits = parseFloat( document.getElementById('inputBUnits').value ); param2arbUnits = param2arbUnits.toPrecision(5); document.getElementById('inputBUnits').value = param2arbUnits;

// execute the main function outputStringInitialUnitsA = eval(arbFunctionCodeStringUnitsA); outputStringUnitsA = parseFloat(outputStringInitialUnitsA); outputStringUnitsA = outputStringUnitsA.toPrecision(5); document.getElementById('outputAUnits').value = outputStringUnitsA;

outputStringInitialUnitsB = eval(arbFunctionCodeStringUnitsB); outputStringUnitsB = parseFloat(outputStringInitialUnitsB); outputStringUnitsB = outputStringUnitsB.toPrecision(5); document.getElementById('outputBUnits').value = outputStringUnitsB;

};

addOnloadHook(arbFunctionUnits);

// ========== end of arb unit converter ================