Actions

MediaWiki

Common.js: Difference between revisions

From Necroxia Origin

mNo edit summary
m (Replaced content with "→‎Any JavaScript here will be loaded for all users on every page load.: mw.loader.load( '/w/index.php?title=MediaWiki:UrsagrodonTeleportCalculator.js&action=raw&ctype=t...")
Tag: Replaced
 
(29 intermediate revisions by the same user not shown)
Line 1: Line 1:
/* Any JavaScript here will be loaded for all users on every page load. */
/* Any JavaScript here will be loaded for all users on every page load. */
$("#testdiv").each(function() {
mw.loader.load( '/w/index.php?title=MediaWiki:UrsagrodonTeleportCalculator.js&action=raw&ctype=text/javascript' );
var parent = $(this);
//var inputs = ['currentRoom', 'currentCount', 'answerNumber'];
var inputs = [
['currentRoom', 1, 32, 1, 'Escribe aqui el numero de la habitacion en que te encuentras:'], ['currentCount', 0, 999, 0,'Escribe aqui tu cuenta actual:'], ['answerNumber', 31, 93, 77,'Escribe aqui el numero al que necesitas llegar:']
];
var textToPrint = "";
//var d = document.createElement('div');
$(this).append("<table id='table1'></table>");
for (i = 0; i < inputs.length; i++) {
$('#table1').append("<tr><td>"+inputs[i][4]+"</td><td><input type='number' id='" + inputs[i][0] + "' name='"+inputs[i][0]+"' min='"+inputs[i][1]+"' max='"+inputs[i][2]+"' value='"+inputs[i][3]+"' maxLength='4' style='width:70px'/></td></tr>");
//$(this).append("<input type='number' id='" + inputs[i][0] + "' name='"+inputs[i][0]+"' min='"+inputs[i][1]+"' max='"+inputs[i][2]+"' value='"+inputs[i][3]+"' maxLength='4' style='width:70px'/>");
$(this).append("<br> id="+inputs[i][0]+" name="+inputs[i][0]+" min="+inputs[i][1]+" max="+inputs[i][2]+" value="+inputs[i][3]);
}
$(this).append("<button id='button1'>getChance</button>");
$('#button1').click( function() {
textToPrint = getPossibleTeleports( $('#currentRoom').val(), $('#currentCount').val(), $('#answerNumber').val());
});
//var currentRoom = $('#currentRoom').val();
$(this).append("<br>"+currentRoom);
$(this).append("<br> " + $("input[id=currentRoom]").value);
});
 
 
 
function validateValues(roomsLeft, answerNumber, currentRoom, currentCount, answerNumberIni){
let isError = false;
let outputText = '';
if (currentRoom < 1) {
outputText += 'El numero de tu habitacion actual no puede ser menor a 1.<br>';
isError = true;
}
if (currentRoom > totalRooms) {
outputText += 'El numero de tu habitacion actual no puede ser mayor a ' + totalRooms + '.<br>';
isError = true;
}
if (currentCount < 0) {
outputText += 'Tu cuenta no puede ser menor a 0.<br>';
isError = true;
}
if (answerNumber < 0) {
outputText += 'Tu cuenta es muy alta debes reiniciar.<br>';
isError = true;
}
if (answerNumberIni < minCount) {
outputText += 'la cuenta total no puede ser menor a ' + minCount + '.<br>';
isError = true;
}
if (answerNumberIni > maxCount) {
outputText += 'la cuenta total no puede ser mayor a ' + maxCount + '.<br>';
isError = true;
}
if (isError) {
document.getElementById("answer").innerHTML = outputText;
}
return isError;
}
 
function calculateA(answerNumber, roomsLeft, c){
let a = c + (2 * roomsLeft) - answerNumber;
//console.log(a, " = ", c , " + (2 * ", roomsLeft, ") - ",answerNumber)
if (a < 0 || a % 1 !== 0){
//console.log("a % 1 = ",a % 1);
return -1;
}
return a;
}
 
function calculateB(answerNumber, roomsLeft, c){
let b = answerNumber - roomsLeft - (2 * c);
//console.log(b, " = ", answerNumber , " - ",roomsLeft ," - (2 * ", c, ")")
if (b < 0 || b % 1 !== 0){
//console.log("b % 1 = ",b % 1)
return -1;
}
return b;
}

Latest revision as of 12:08, 1 September 2020

/* Any JavaScript here will be loaded for all users on every page load. */
mw.loader.load( '/w/index.php?title=MediaWiki:UrsagrodonTeleportCalculator.js&action=raw&ctype=text/javascript' );