Jump to content

MediaWiki:Common.js: Difference between revisions

From Emps-World Wiki
No edit summary
Whiterich12 (talk | contribs)
No edit summary
Line 3: Line 3:
// TODO: link images directly, because the parser has already run at this point
// TODO: link images directly, because the parser has already run at this point
// cannot use wiki commands here anymore.
// cannot use wiki commands here anymore.
// mapping slot id to a name
// mapping slot id to a file
/*var imgSize = "30px";
var slotToImg = [
var slotToName = [
     "c/ca/Helmetslot.png",
     "[[file:Helmetslot.png|"+imgSize+"]]",
     "d/d7/Capeslot.png",
     "[[file:Capeslot.png|"+imgSize+"]]",
     "8/85/Amuletslot.png",
     "[[file:Amuletslot.png|"+imgSize+"]]",
     "a/aa/Weaponslot.png",
     "[[file:Weaponslot.png|"+imgSize+"]]",
     "9/94/Bodyslot.png",
     "[[file:Bodyslot.png|"+imgSize+"]]",
     "9/91/Shieldslot.png",
     "[[file:Shieldslot.png|"+imgSize+"]]",
     "Arms",
     "Arms",
     "[[file:Legsslot.png|"+imgSize+"]]",
     "5/5e/Legsslot.png",
     "",
     "",
     "[[file:Glovesslot.png|"+imgSize+"]]",
     "8/89/Glovesslot.png",
     "[[file:Bootsslot.png|"+imgSize+"]]",
     "f/f8/Bootsslot.png",
     "",
     "",
     "[[file:Ringslot.png|"+imgSize+"]]",
     "c/ce/Ringslot.png",
     "[[file:Ammoslot.png|"+imgSize+"]]",
     "5/54/Ammoslot.png",
     "[[file:Wingsslot.png|"+imgSize+"]]",
     "7/77/Wingsslot.png",
     "[[file:Auraslot.png|"+imgSize+"]]",
     "d/d5/Auraslot.png"
];*/
];
 
// mapping slot id to a name
var slotToName = [
var slotToName = [
     "Hat",
     "Helmet",
     "Cape",
     "Cape",
     "Amulet",
     "Amulet",
Line 38: Line 37:
     "",
     "",
     "Ring",
     "Ring",
     "Arrows",
     "Ammo",
     "Wing",
     "Wings",
     "Aura",
     "Aura",
];
];
Line 56: Line 55:
             //console.log("data3: "+json);
             //console.log("data3: "+json);
             //console.log("data4: "+json.name);
             //console.log("data4: "+json.name);
           
             // iterate over headers
             // iterate over headers
             table.find("th").each(function() {
             table.find("th").each(function() {
Line 80: Line 79:
                 else if (dc == 6)
                 else if (dc == 6)
                     $(this).text(json.prayer);
                     $(this).text(json.prayer);
                 else if (dc == 7)
                 else if (dc == 7) {
                     $(this).text(slotToName[json.slot]);
                    // equipment slot icon, wih same attributes as the old template.
                 else if (dc === 8)
                    var iconLink = document.createElement("a");
                    $(iconLink).attr("href", "/wiki/File:"+slotToName[json.slot]+"slot.png");
                    $(iconLink).attr("class", "image");
                    var iconImg = document.createElement("img");
                     $(iconImg).attr("alt", slotToName[json.slot]+"slot.png");
                    $(iconImg).attr("src", "/wiki/images/thumb/"+slotToImg[json.slot]+"/30px-"+slotToName[json.slot]+"slot.png");
                    $(iconImg).attr("width", "30");
                    $(iconImg).attr("height", "30");
                    $(iconImg).attr("srcset", "/wiki/images/"+slotToImg[json.slot]+" 1.5x, /wiki/images/"+slotToImg[json.slot]+" 2x");
                    iconLink.appendChild(iconImg);
                    this.innerHTML = "";
                    this.appendChild(iconLink);
                 } else if (dc === 8)
                     $(this).text(json.mlStr);
                     $(this).text(json.mlStr);
                 else if (dc === 9)
                 else if (dc === 9)

Revision as of 13:50, 8 September 2018

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

// TODO: link images directly, because the parser has already run at this point
// cannot use wiki commands here anymore.
// mapping slot id to a file
var slotToImg = [
    "c/ca/Helmetslot.png",
    "d/d7/Capeslot.png",
    "8/85/Amuletslot.png",
    "a/aa/Weaponslot.png",
    "9/94/Bodyslot.png",
    "9/91/Shieldslot.png",
    "Arms",
    "5/5e/Legsslot.png",
    "",
    "8/89/Glovesslot.png",
    "f/f8/Bootsslot.png",
    "",
    "c/ce/Ringslot.png",
    "5/54/Ammoslot.png",
    "7/77/Wingsslot.png",
    "d/d5/Auraslot.png"
];
// mapping slot id to a name
var slotToName = [
    "Helmet",
    "Cape",
    "Amulet",
    "Weapon",
    "Body",
    "Shield",
    "Arms",
    "Legs",
    "",
    "Gloves",
    "Boots",
    "",
    "Ring",
    "Ammo",
    "Wings",
    "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);
            //console.log("data4: "+json.name);
            
            // 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) {
                    // equipment slot icon, wih same attributes as the old template.
                    var iconLink = document.createElement("a");
                    $(iconLink).attr("href", "/wiki/File:"+slotToName[json.slot]+"slot.png");
                    $(iconLink).attr("class", "image");
                    var iconImg = document.createElement("img");
                    $(iconImg).attr("alt", slotToName[json.slot]+"slot.png");
                    $(iconImg).attr("src", "/wiki/images/thumb/"+slotToImg[json.slot]+"/30px-"+slotToName[json.slot]+"slot.png");
                    $(iconImg).attr("width", "30");
                    $(iconImg).attr("height", "30");
                    $(iconImg).attr("srcset", "/wiki/images/"+slotToImg[json.slot]+" 1.5x, /wiki/images/"+slotToImg[json.slot]+" 2x");
                    iconLink.appendChild(iconImg);
                    this.innerHTML = "";
                    this.appendChild(iconLink);
                } 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 === "1" ? "Yes" : "No");
                else if (dc === 12)
                    $(this).text(json.repair === "1" ? "Yes" : "No");
                else if (dc === 13) {
                    if (json.req === "")
                        $(this).text("None");
                    else
                        $(this).text(json.req);
                } else if (dc === 14) {
                    if (json.slot === "3")
                        $(this).text(json.speed);
                    else
                        $(this).text("-");
                } else
                    $(this).text(dc+" data column");
                
                dc++;
            });
        });
    });
});