MediaWiki:Common.js: Difference between revisions

no edit summary
No edit summary
No edit summary
 
(10 intermediate revisions by the same user not shown)
Line 1:
/* Any JavaScript here will be loaded for all users on every page load. */
 
function trySortrunUntilSuccess(f) {
(function run() {
if (rerun!f()) {
setTimeout(trySortrun, 10);
}
})();
 
// Extra functionality for RAM/ROM maps
 
function trySort() {
// Sort table by the first column
/*runUntilSuccess(function() {
var tables = document.getElementsByClassName("ram_rom_map");
console.log("Checking for table sort on " + tables.length + " tables");
var rerun = false;
for (var i = 0; i < tables.length; i++) {
var table = tables[i];
var header = table.getElementsByTagName("th")[0];
if (header.classList.contains("headerSort")) {
console.log("Table " + i + " was sortable");
if (!header.classList.contains("headerSortUp")) {
header.click();
}
} else {
return false;
console.log("Table " + i + " was not sortable");
rerun = true;
}
}
return true;
});*/
if (rerun) {
setTimeout(trySort, 10);
}
setTimeout(trySort, 10);
 
// 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];
// Sort table by the first column
table.getElementsByTagName("th")[0].click();
// Add the ending address to the length column
var rows = table.getElementsByTagName("tbody")[0].children;
for (var j = 0; j < rows.length; j++) {
Line 43 ⟶ 44:
}
}
});
 
// 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;
tablevar svgs = canvas.getElementsByTagName("thsvg")[0].click();
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;
});