Difference between revisions of "MediaWiki:Calculator.js/Mana Regeneration.js"

m
m
Line 18: Line 18:
 
                 calculate(meditationInput, focusInput, intInput, mrInput, manaPerSecondLabel);
 
                 calculate(meditationInput, focusInput, intInput, mrInput, manaPerSecondLabel);
 
         };
 
         };
         var calcTableRow = document.createElement('tr');
+
         var innerTable = document.createElement('table');
         var calcTableCell = document.createElement('td');
+
        var innerRow = document.createElement('tr');
 +
         var innerCell = document.createElement('td');
 
         var meditationInput = document.createElement('input');
 
         var meditationInput = document.createElement('input');
 
         var focusInput = document.createElement('input');
 
         var focusInput = document.createElement('input');
         var intInput = document.createElement('input');
+
         var intelligenceInput = document.createElement('input');
 
         var mrInput = document.createElement('input');
 
         var mrInput = document.createElement('input');
 
         var calculateButton = document.createElement('input');
 
         var calculateButton = document.createElement('input');
 
         var manaPerSecondLabel = document.createElement('div');
 
         var manaPerSecondLabel = document.createElement('div');
  
         calcTableCell.style.textAlign = 'right';
+
         innerCell.style.textAlign = 'right';
         calcTableCell.appendChild(document.createTextNode('Meditation:'));
+
         innerCell.appendChild(document.createTextNode('Meditation:'));
         calcTableRow.appendChild(calcTableCell);
+
         innerRow.appendChild(innerCell);
  
 
         meditationInput.maxLength = '5';
 
         meditationInput.maxLength = '5';
 
         meditationInput.type = 'text';
 
         meditationInput.type = 'text';
         meditationInput.style.width = '45px';
+
         meditationInput.style.width = '50px';
 
         meditationInput.onkeyup = function(keyEvent) {
 
         meditationInput.onkeyup = function(keyEvent) {
 
             detectEnter(keyEvent);
 
             detectEnter(keyEvent);
 
         };
 
         };
calcTableCell = document.createElement('td');
+
innerCell = document.createElement('td');
         calcTableCell.appendChild(meditationInput);
+
         innerCell.appendChild(meditationInput);
         calcTableRow.appendChild(calcTableCell);
+
         innerRow.appendChild(innerCell);
 +
        innerTable.appendChild(innerRow);
 +
 
 +
innerCell = document.createElement('td');
 +
        innerCell.style.textAlign = 'right';
 +
        innerCell.appendChild(document.createTextNode('Focus:'));
 +
        innerRow = document.createElement('tr');
 +
        innerRow.appendChild(innerCell);
 +
 
 +
        focusInput.maxLength = '5';
 +
        focusInput.type = 'text';
 +
        focusInput.style.width = '50px';
 +
        focusInput.onkeyup = function(keyEvent) {
 +
            detectEnter(keyEvent);
 +
        };
 +
innerCell = document.createElement('td');
 +
        innerCell.appendChild(focusInput);
 +
        innerRow.appendChild(innerCell);
 +
        innerTable.appendChild(innerRow);
 +
 
 +
innerCell = document.createElement('td');
 +
        innerCell.style.textAlign = 'right';
 +
        innerCell.appendChild(document.createTextNode('Intelligence:'));
 +
        innerRow = document.createElement('tr');
 +
        innerRow.appendChild(innerCell);
 +
 
 +
        intelligenceInput.maxLength = '3';
 +
        intelligenceInput.type = 'text';
 +
        intelligenceInput.style.width = '50px';
 +
        intelligenceInput.onkeyup = function(keyEvent) {
 +
            detectEnter(keyEvent);
 +
        };
 +
innerCell = document.createElement('td');
 +
        innerCell.appendChild(intelligenceInput);
 +
        innerRow.appendChild(innerCell);
 +
        innerTable.appendChild(innerRow);
 +
 
 +
innerCell = document.createElement('td');
 +
        innerCell.style.textAlign = 'right';
 +
        innerCell.appendChild(document.createTextNode('Equipped MR:'));
 +
        innerRow = document.createElement('tr');
 +
        innerRow.appendChild(innerCell);
 +
 
 +
        mrInput.maxLength = '3';
 +
        mrInput.type = 'text';
 +
        mrInput.style.width = '50px';
 +
        mrInput.onkeyup = function(keyEvent) {
 +
            detectEnter(keyEvent);
 +
        };
 +
innerCell = document.createElement('td');
 +
        innerCell.appendChild(mrInput);
 +
        innerRow.appendChild(innerCell);
 +
        innerTable.appendChild(innerRow);
  
 
         calculateButton.type = 'button';
 
         calculateButton.type = 'button';
Line 46: Line 99:
 
             calculate(meditationInput, focusInput, intInput, mrInput, manaPerSecondLabel);
 
             calculate(meditationInput, focusInput, intInput, mrInput, manaPerSecondLabel);
 
         };
 
         };
calcTableCell = document.createElement('td');
+
innerCell = document.createElement('td');
         calcTableCell.appendChild(calculateButton);
+
         innerCell.appendChild(calculateButton);
         calcTableRow.appendChild(calcTableCell);
+
         innerRow = document.createElement('tr');
 +
        innerRow.appendChild(innerCell);
  
 
         manaPerSecondLabel.appendChild(document.createTextNode('0 Mana Per Second'));
 
         manaPerSecondLabel.appendChild(document.createTextNode('0 Mana Per Second'));
 
         manaPerSecondLabel.style.textAlign = 'right';
 
         manaPerSecondLabel.style.textAlign = 'right';
 
         manaPerSecondLabel.style.width = '130px';
 
         manaPerSecondLabel.style.width = '130px';
calcTableCell = document.createElement('td');
+
innerCell = document.createElement('td');
         calcTableCell.appendChild(manaPerSecondLabel);
+
         innerCell.appendChild(manaPerSecondLabel);
         calcTableRow.appendChild(calcTableCell);
+
        innerRow.appendChild(innerCell);
 +
        innerTable.appendChild(innerRow);
 +
 
 +
        var calcTableRow = document.createElement('tr');
 +
         calcTableRow.appendChild(innerTable);
  
 
         this._super(calcTableRow, 'ManaPerSecond', 'Mana Per Second', 4);
 
         this._super(calcTableRow, 'ManaPerSecond', 'Mana Per Second', 4);

Revision as of 13:16, 4 May 2010

/**
 * Calculator that calculates your mana regenerated per second based on Meditation, Focus, Intelligence, and equipped MR.
 */
var ManaPerSecondCalculator = Calculator.extend({
    init: function() {
        var calculate = function(meditation, focus, int, mr, label) {
            if (!meditation.value || !isNumeric(meditation.value)) meditation.value = '0.0';
            if (!focus.value || !isNumeric(focus.value)) focus.value = '0.0';
            if (!int.value || !isNumeric(int.value)) int.value = '0';
            if (!mr.value || !isNumeric(mr.value)) mr.value = '0';
            var manaPerSecond = 2 / 10;
            removeChildren(label);
            label.appendChild(document.createTextNode(manaPerSecond + ' Mana Per Second'));
        };
        var detectEnter = function(keyEvent) {
            var keyID = window.event ? event.keyCode : keyEvent.keyCode;
            if (keyID == 13)
                calculate(meditationInput, focusInput, intInput, mrInput, manaPerSecondLabel);
        };
        var innerTable = document.createElement('table');
        var innerRow = document.createElement('tr');
        var innerCell = document.createElement('td');
        var meditationInput = document.createElement('input');
        var focusInput = document.createElement('input');
        var intelligenceInput = document.createElement('input');
        var mrInput = document.createElement('input');
        var calculateButton = document.createElement('input');
        var manaPerSecondLabel = document.createElement('div');

        innerCell.style.textAlign = 'right';
        innerCell.appendChild(document.createTextNode('Meditation:'));
        innerRow.appendChild(innerCell);

        meditationInput.maxLength = '5';
        meditationInput.type = 'text';
        meditationInput.style.width = '50px';
        meditationInput.onkeyup = function(keyEvent) {
            detectEnter(keyEvent);
        };
	innerCell = document.createElement('td');
        innerCell.appendChild(meditationInput);
        innerRow.appendChild(innerCell);
        innerTable.appendChild(innerRow);

	innerCell = document.createElement('td');
        innerCell.style.textAlign = 'right';
        innerCell.appendChild(document.createTextNode('Focus:'));
        innerRow = document.createElement('tr');
        innerRow.appendChild(innerCell);

        focusInput.maxLength = '5';
        focusInput.type = 'text';
        focusInput.style.width = '50px';
        focusInput.onkeyup = function(keyEvent) {
            detectEnter(keyEvent);
        };
	innerCell = document.createElement('td');
        innerCell.appendChild(focusInput);
        innerRow.appendChild(innerCell);
        innerTable.appendChild(innerRow);

	innerCell = document.createElement('td');
        innerCell.style.textAlign = 'right';
        innerCell.appendChild(document.createTextNode('Intelligence:'));
        innerRow = document.createElement('tr');
        innerRow.appendChild(innerCell);

        intelligenceInput.maxLength = '3';
        intelligenceInput.type = 'text';
        intelligenceInput.style.width = '50px';
        intelligenceInput.onkeyup = function(keyEvent) {
            detectEnter(keyEvent);
        };
	innerCell = document.createElement('td');
        innerCell.appendChild(intelligenceInput);
        innerRow.appendChild(innerCell);
        innerTable.appendChild(innerRow);

	innerCell = document.createElement('td');
        innerCell.style.textAlign = 'right';
        innerCell.appendChild(document.createTextNode('Equipped MR:'));
        innerRow = document.createElement('tr');
        innerRow.appendChild(innerCell);

        mrInput.maxLength = '3';
        mrInput.type = 'text';
        mrInput.style.width = '50px';
        mrInput.onkeyup = function(keyEvent) {
            detectEnter(keyEvent);
        };
	innerCell = document.createElement('td');
        innerCell.appendChild(mrInput);
        innerRow.appendChild(innerCell);
        innerTable.appendChild(innerRow);

        calculateButton.type = 'button';
        calculateButton.value = 'Calculate >>';
        calculateButton.onclick = function() {
            calculate(meditationInput, focusInput, intInput, mrInput, manaPerSecondLabel);
        };
	innerCell = document.createElement('td');
        innerCell.appendChild(calculateButton);
        innerRow = document.createElement('tr');
        innerRow.appendChild(innerCell);

        manaPerSecondLabel.appendChild(document.createTextNode('0 Mana Per Second'));
        manaPerSecondLabel.style.textAlign = 'right';
        manaPerSecondLabel.style.width = '130px';
	innerCell = document.createElement('td');
        innerCell.appendChild(manaPerSecondLabel);
        innerRow.appendChild(innerCell);
        innerTable.appendChild(innerRow);

        var calcTableRow = document.createElement('tr');
        calcTableRow.appendChild(innerTable);

        this._super(calcTableRow, 'ManaPerSecond', 'Mana Per Second', 4);
    }
});

function searchForCalculators() {
    var calculators = document.getElementsByTagName('div');

    for (var i in calculators) {
         if (calculators[i].id == 'ManaPerSecond') {
             new ManaPerSecondCalculator();
         }
    }
}
addOnloadHook(searchForCalculators);