Jump to content

MediaWiki:Common.js: Difference between revisions

From Emps-World Wiki
No edit summary
No edit summary
Line 27: Line 27:
          
          
         $.get( "../scripts/fetch_item.php", { id: itemId }).done(function(data) {
         $.get( "../scripts/fetch_item.php", { id: itemId }).done(function(data) {
var json = JSON.parse(data);
             var hc = 0, dc = 0;
             var hc = 0, dc = 0;


Line 36: Line 37:
             table.find("th").each(function() {
             table.find("th").each(function() {
                 if (hc === 0)
                 if (hc === 0)
                     $(this).text(data.name);
                     $(this).text(json.name);
                 hc++;
                 hc++;
             })
             })
Line 43: Line 44:
             table.find("td").each(function() {
             table.find("td").each(function() {
                 if (dc === 0)
                 if (dc === 0)
                     $(this).text(data.mlAcc);
                     $(this).text(json.mlAcc);
                 else if (dc === 1)
                 else if (dc === 1)
                     $(this).text(data.rnAcc);
                     $(this).text(json.rnAcc);
                 else if (dc === 2)
                 else if (dc === 2)
                     $(this).text(data.mgAcc);
                     $(this).text(json.mgAcc);
                 else if (dc === 3)
                 else if (dc === 3)
                     $(this).text(data.mlDef);
                     $(this).text(json.mlDef);
                 else if (dc === 4)
                 else if (dc === 4)
                     $(this).text(data.rnDef);
                     $(this).text(json.rnDef);
                 else if (dc === 5)
                 else if (dc === 5)
                     $(this).text(data.mgDef);
                     $(this).text(json.mgDef);
                 else if (dc == 6)
                 else if (dc == 6)
                     $(this).text(data.prayer);
                     $(this).text(json.prayer);
                 else if (dc == 7)
                 else if (dc == 7)
                     $(this).text(slotToName[data.slot]);
                     $(this).text(slotToName[json.slot]);
                 else if (dc === 8)
                 else if (dc === 8)
                     $(this).text(data.mlStr);
                     $(this).text(json.mlStr);
                 else if (dc === 9)
                 else if (dc === 9)
                     $(this).text(data.rnStr);
                     $(this).text(json.rnStr);
                 else if (dc === 10)
                 else if (dc === 10)
                     $(this).text(data.mgStr);
                     $(this).text(json.mgStr);
                 else if (dc === 11)
                 else if (dc === 11)
                     $(this).text(data.degrade);
                     $(this).text(json.degrade);
                 else if (dc === 12)
                 else if (dc === 12)
                     $(this).text(data.repair);
                     $(this).text(json.repair);
                 else if (dc === 13)
                 else if (dc === 13)
                     $(this).text(data.req);
                     $(this).text(json.req);
                 else if (dc === 14)
                 else if (dc === 14)
                     $(this).text(data.speed);
                     $(this).text(json.speed);
                 else
                 else
                     $(this).text(dc+" data column");
                     $(this).text(dc+" data column");

Revision as of 12:28, 30 August 2018

/* Any JavaScript here will be loaded for all users on every page load. */

// mapping slot id to a name
var slotToName = [
	"Hat",
	"Cape",
	"Amulet",
	"Weapon",
	"Body",
	"Shield",
	"Arms",
	"Legs",
	"",
	"Gloves",
	"Boots",
	"",
	"Ring",
	"Arrows",
	"Wing",
	"Aura",
];

$(document).ready(function() {
    $(".item-bonus-table").each(function() {
        var table = $(this);
        var itemId = $(this).data("item-id");
        
        $.get( "../scripts/fetch_item.php", { id: itemId }).done(function(data) {
			var json = JSON.parse(data);
            var hc = 0, dc = 0;

            console.log("data1: "+JSON.stringify(data));
            console.log("data2: "+data);
            console.log("data3: "+JSON.parse(data));
			
            // iterate over headers
            table.find("th").each(function() {
                if (hc === 0)
                    $(this).text(json.name);
                hc++;
            })
            
            // iterate over table data
            table.find("td").each(function() {
                if (dc === 0)
                    $(this).text(json.mlAcc);
                else if (dc === 1)
                    $(this).text(json.rnAcc);
                else if (dc === 2)
                    $(this).text(json.mgAcc);
                else if (dc === 3)
                    $(this).text(json.mlDef);
                else if (dc === 4)
                    $(this).text(json.rnDef);
                else if (dc === 5)
                    $(this).text(json.mgDef);
                else if (dc == 6)
                    $(this).text(json.prayer);
                else if (dc == 7)
                    $(this).text(slotToName[json.slot]);
                else if (dc === 8)
                    $(this).text(json.mlStr);
                else if (dc === 9)
                    $(this).text(json.rnStr);
                else if (dc === 10)
                    $(this).text(json.mgStr);
                else if (dc === 11)
                    $(this).text(json.degrade);
                else if (dc === 12)
                    $(this).text(json.repair);
                else if (dc === 13)
                    $(this).text(json.req);
                else if (dc === 14)
                    $(this).text(json.speed);
                else
                    $(this).text(dc+" data column");
                
                dc++;
            });
        });
    });
});