MediaWiki:Common.js: Difference between revisions
Content added Content deleted
Piranhaplant (talk | contribs) No edit summary |
Piranhaplant (talk | contribs) No edit summary |
||
(4 intermediate revisions by the same user not shown) | |||
Line 2: | Line 2: | ||
function runUntilSuccess(f) { |
function runUntilSuccess(f) { |
||
console.log("Running function"); |
|||
(function run() { |
(function run() { |
||
if (!f()) { |
if (!f()) { |
||
console.log("Rerunning function"); |
|||
setTimeout(run, 10); |
setTimeout(run, 10); |
||
} |
} |
||
Line 14: | Line 12: | ||
// Sort table by the first column |
// Sort table by the first column |
||
runUntilSuccess(function() { |
/*runUntilSuccess(function() { |
||
var tables = document.getElementsByClassName("ram_rom_map"); |
var tables = document.getElementsByClassName("ram_rom_map"); |
||
for (var i = 0; i < tables.length; i++) { |
for (var i = 0; i < tables.length; i++) { |
||
Line 29: | Line 27: | ||
} |
} |
||
return true; |
return true; |
||
}); |
});*/ |
||
// Add the ending address to the length column |
// Add the ending address to the length column |
||
Line 50: | Line 48: | ||
// Modify BPMN chart embeds to be just the SVG |
// Modify BPMN chart embeds to be just the SVG |
||
runUntilSuccess(function() { |
runUntilSuccess(function() { |
||
console.log("Checking for BPMN"); |
|||
if (document.getElementsByClassName("bpmn_embed").length > 0) { |
if (document.getElementsByClassName("bpmn_embed").length > 0) { |
||
console.log("BPMN found"); |
|||
var canvas = document.getElementById("canvas"); |
var canvas = document.getElementById("canvas"); |
||
var parent = canvas.parentElement; |
var parent = canvas.parentElement; |
||
var svgs = canvas.getElementsByTagName("svg"); |
var svgs = canvas.getElementsByTagName("svg"); |
||
if (svgs.length == 0) { |
if (svgs.length == 0 || svgs[0].getAttribute("data-element-id") == null) { |
||
console.log("No SVG found"); |
|||
return false; |
return false; |
||
} |
} |
||
console.log("SVG found"); |
|||
var clone = svgs[0].cloneNode(true); |
var clone = svgs[0].cloneNode(true); |
||
Line 67: | Line 61: | ||
var bbox = clone.getBBox(); |
var bbox = clone.getBBox(); |
||
clone.setAttribute("width", |
clone.setAttribute("width", bbox.width + "px"); |
||
clone.setAttribute("height", |
clone.setAttribute("height", bbox.height + "px"); |
||
clone.setAttribute("viewBox", |
clone.setAttribute("viewBox", bbox.x + " " + bbox.y + " " + bbox.width + " " + bbox.height); |
||
} |
} |
||
return true; |
return true; |
Latest revision as of 01:15, 29 June 2024
/* Any JavaScript here will be loaded for all users on every page load. */
function runUntilSuccess(f) {
(function run() {
if (!f()) {
setTimeout(run, 10);
}
})();
}
// Extra functionality for RAM/ROM maps
// Sort table by the first column
/*runUntilSuccess(function() {
var tables = document.getElementsByClassName("ram_rom_map");
for (var i = 0; i < tables.length; i++) {
var table = tables[i];
var header = table.getElementsByTagName("th")[0];
if (header.classList.contains("headerSort")) {
if (!header.classList.contains("headerSortUp")) {
header.click();
}
} else {
return false;
}
}
return true;
});*/
// Add the ending address to the length column
$(function() {
var tables = document.getElementsByClassName("ram_rom_map");
for (var i = 0; i < tables.length; i++) {
var table = tables[i];
var rows = table.getElementsByTagName("tbody")[0].children;
for (var j = 0; j < rows.length; j++) {
var row = rows[j];
var address = row.children[0].innerText;
var length = parseInt(row.children[1].innerText);
var endAddress = address.substr(0, 4) + (parseInt(address.substr(4, 4), 16) + length).toString(16).padStart(4, "0").toUpperCase();
row.children[1].title = "[" + address + ", " + endAddress + ")";
}
}
});
// Modify BPMN chart embeds to be just the SVG
runUntilSuccess(function() {
if (document.getElementsByClassName("bpmn_embed").length > 0) {
var canvas = document.getElementById("canvas");
var parent = canvas.parentElement;
var svgs = canvas.getElementsByTagName("svg");
if (svgs.length == 0 || svgs[0].getAttribute("data-element-id") == null) {
return false;
}
var clone = svgs[0].cloneNode(true);
canvas.remove();
parent.appendChild(clone);
var bbox = clone.getBBox();
clone.setAttribute("width", bbox.width + "px");
clone.setAttribute("height", bbox.height + "px");
clone.setAttribute("viewBox", bbox.x + " " + bbox.y + " " + bbox.width + " " + bbox.height);
}
return true;
});