Difference between revisions of "MediaWiki:Sandbox.js"
Jump to navigation
Jump to search
Nussnougat (talk | contribs) |
Nussnougat (talk | contribs) |
||
(4 intermediate revisions by the same user not shown) | |||
Line 1: | Line 1: | ||
function drawTable(mobs) { | function drawTable(mobs) { | ||
var output = $("#sandbox-output"); | var output = $("#sandbox-output"); | ||
− | var html = "<table>< | + | var html = "<table class='vvwiki-table'><tr><th>Name</th><th>HP</th><th>Damage</th></tr>"; |
mobs.forEach(function(mob) { | mobs.forEach(function(mob) { | ||
+ | var url = "/index.php/Creatures:"+mob["name"]; | ||
html += "<tr>"; | html += "<tr>"; | ||
− | html += "<td><b>"+mob["name"]+"</b></td>"; | + | html += "<td><b><a href='"+url+"'>"+mob["name"]+"</a></b></td>"; |
html += "<td>"+mob["hp"]+"</td>"; | html += "<td>"+mob["hp"]+"</td>"; | ||
html += "<td>"+mob["damage"]+"</td>"; | html += "<td>"+mob["damage"]+"</td>"; | ||
Line 19: | Line 20: | ||
url: "/vv-api/get-creatures.php", | url: "/vv-api/get-creatures.php", | ||
success: function(data) { | success: function(data) { | ||
− | |||
drawTable(data.result); | drawTable(data.result); | ||
}, | }, | ||
error: function(status, exec) { | error: function(status, exec) { | ||
− | + | // TODO error message | |
} | } | ||
}); | }); |
Latest revision as of 06:37, 6 August 2019
function drawTable(mobs) { var output = $("#sandbox-output"); 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() { $.ajax({ type: "GET", dataType: "json", url: "/vv-api/get-creatures.php", success: function(data) { drawTable(data.result); }, error: function(status, exec) { // TODO error message } }); $('#sandbox-output').html('Sandbox JS loaded!'); });