Difference between revisions of "MediaWiki:CreatureList.js"

From Virtuverse Wiki
Jump to navigation Jump to search
Line 15: Line 15:
  
 
$(document).ready(function() {
 
$(document).ready(function() {
   $.ajax({
+
   if ($("#creatures-list") != null) {
    type: "GET",
+
    $.ajax({
    dataType: "json",
+
        type: "GET",
    url: "/vv-api/get-creatures.php",
+
        dataType: "json",
    success: function(data) {
+
        url: "/vv-api/get-creatures.php",
        drawTable(data.result);
+
        success: function(data) {
    },
+
          drawTable(data.result);
    error: function(status, exec) {
+
        },
        $("#creatures-list").html("<i>Error retrieving mob data!</i>");
+
        error: function(status, exec) {
     }
+
          $("#creatures-list").html("<i>Error retrieving mob data!</i>");
   });
+
        }
 +
     });
 +
   }
 
});
 
});

Revision as of 13:23, 6 August 2019

function drawTable(mobs) {
   var output = $("#creatures-list");
   var html = "<table class='vvwiki-table'><tr><th>Name</th><th>HP</th><th>Damage</th></tr>";
   mobs.forEach(function(mob) {
      var url = "/index.php/Creatures:"+mob["name"];
      html += "<tr>";
      html += "<td><b><a href='"+url+"'>"+mob["name"]+"</a></b></td>";
      html += "<td>"+mob["hp"]+"</td>";
      html += "<td>"+mob["damage"]+"</td>";
      html += "</tr>"
   });
   html += "</table>";
   output.html(html);
}

$(document).ready(function() {
  if ($("#creatures-list") != null) {
     $.ajax({
        type: "GET",
        dataType: "json",
        url: "/vv-api/get-creatures.php",
        success: function(data) {
           drawTable(data.result);
        },
        error: function(status, exec) {
           $("#creatures-list").html("<i>Error retrieving mob data!</i>");
        }
     });
  }
});