Benutzer:Shadowtweaker/AtkTable.js
Zur Navigation springen
Zur Suche springen
Hinweis: Leere nach dem Speichern den Browser-Cache, um die Änderungen sehen zu können.
- Firefox/Safari: Umschalttaste drücken und gleichzeitig Aktualisieren anklicken oder entweder Strg+F5 oder Strg+R (⌘+R auf dem Mac) drücken
- Google Chrome: Umschalttaste+Strg+R (⌘+Umschalttaste+R auf dem Mac) drücken
- Internet Explorer: Strg+F5 drücken oder Strg drücken und gleichzeitig Aktualisieren anklicken
- Opera: Extras → Internetspuren löschen … → Individuelle Auswahl → Den kompletten Cache löschen
- Konqueror: Aktualisieren anklicken oder F5 drücken
/* toggler function */
function at_toggle(gen) {
at_tmvmsortvalues(gen);
/* general toggling of generation-specific data */
$("*[data-gen]").each(function() {
if (this.dataset.gen == "-0") this.style.display = (gen == 0 ? "none" : "");
else if (gen != 0 && this.dataset.gen.substring(0, 1) == "+") this.style.display = "none";
else if (gen != 0 && Math.abs(this.dataset.gen) != gen) this.style.display = "none";
else if (gen == 0 && this.dataset.gen < 0) this.style.display = "none";
else this.style.display = "";
});
/* toggle rows that are irrelevant for this generation */
$(".at tbody tr:not(.expand-child)").each(function() {
$(this)[0].style.display = "";
if (gen != 0 && !$(this).find("td").toArray().filter(x => x.dataset.gen == gen || x.dataset.gen == "+" + gen).map(x => x.innerText.trim() != "—").reduce((acc, cv) => acc || cv, false))
$(this)[0].style.display = "none";
});
/* hide table if there are no relevant rows */
$(".at").each(function() {
var empty = $(this).find("tbody tr:not(.expand-child):not([style*='display'])").length == 0;
$(this).css("display", empty ? "none": "");
$(this).next().css("display", empty ? "" : "none");
});
/* toggle columns in tmvm and event tables */
$(".at_t tbody td[data-gen], .at_ev tbody td[data-gen]").each(function() {
$(this)[0].style.display = (gen == 0 ? "" : "none");
});
/* adjust level header */
$(".at_l").each(function() {
id = $(this).find("thead tr:nth-child(1) th:nth-child(2)")[0];
level = $(this).find("thead tr:nth-child(1) th:nth-child(3)")[0];
if (gen == 0) {
id.colSpan = level.colSpan;
$(this).find("thead tr:nth-child(1) th").toArray().slice(3).forEach(x => x.rowSpan = $(this).find("thead tr:nth-child(1) th:nth-child(1)")[0].rowSpan);
}
else {
id.colSpan = $(this).find("thead tr:nth-child(2) th").toArray().filter(x => x.dataset.gen == gen)[0].colSpan;
$(this).find("thead tr:nth-child(1) th").toArray().slice(3).forEach(x => x.rowSpan = $(this).find("thead tr:nth-child(2) th").toArray().filter(x => x.dataset.gen == gen)[0].colSpan);
}
$(this).find("thead tr:nth-child(2)")[0].style.display = (gen == 0 ? "" : "none");
if ($(this).find("thead tr:nth-child(3)")[0]) {
$(this).find("thead tr:nth-child(3)")[0].style.display = (gen == 0 ? "" : ($(this).find("thead tr:nth-child(2) th").toArray().filter(x => x.dataset.gen == gen)[0].rowSpan > 1 ? "none" : ""));
}
$(this).find("tfoot th")[0].colSpan = id.colSpan + 6;
});
/* adjust tmvm and event header */
$(".at_t thead tr:nth-child(1) th:nth-last-child(7), .at_ev thead tr:nth-child(1) th:nth-last-child(6)").toggleClass("round-topleft", gen != 0);
/* adjust tmvm footer */
$(".at_t").each(function() {
$(this).find("tfoot th")[0].colSpan = 7 + (gen == 0 ? $(this).find("thead tr:nth-child(1) th:nth-child(1)")[0].colSpan : 0);
});
/* adjust event footer */
$(".at_ev").each(function() {
$(this).find("tfoot th")[0].colSpan = 6 + (gen == 0 ? $(this).find("thead tr:nth-child(1) th:nth-child(1)")[0].colSpan : 0);
});
/* adjust breeding header and footer */
$(".at_z").each(function() {
var split = gen != 0 && $(this).find("thead tr:nth-child(2) th").toArray().filter(x => x.dataset.gen == "+" + gen)[0].colSpan > 1;
$(this).find("thead tr:nth-child(1) th:nth-child(2)")[0].style.display = (split ? "": "none");
$(this).find("thead tr:nth-child(1) th:nth-last-child(7)").toggleClass("round-topleft", gen != 0 && !split);
$(this).find("thead tr:nth-child(1) th:nth-last-child(2)").toggleClass("round-topright", gen == 0);
$(this).find("tfoot th")[0].colSpan = (gen == 0 ? 6 + $(this).find("thead tr:nth-child(1) th:nth-child(1)")[0].colSpan : (split ? 9 : 7));
$(this).find("tr.expand-child td").attr('colSpan', split ? 9 : 7);
});
$(".at_z").toggleClass("at_z_all", gen == 0);
/* adjust tutor footer */
$(".at_a").each(function() {
$(this).find("tfoot th")[0].colSpan = 6 + (gen == 0 ? $(this).find("thead tr:nth-child(1) th:nth-child(1)")[0].colSpan : 1);
});
/* table resorting */
$(".at").each(function() {
$(this).data('tablesorter').sort($(this)[0][Object.keys($(this)[0]).filter(x => x.startsWith("jQuery"))[0]].tablesorter.config.sortList.map(function(x) { a = {}; a[x[0]] = (x[1] == 0 ? 'asc' : 'desc'); return a; }));
});
}
/* tmvm sorting */
function at_tmvmsortvalues(gen) {
$(".at_t tbody td:nth-last-child(7)").each(function() {
value = $(this).find("> span").toArray().filter(x => x.dataset.gen == (gen == 0 ? "7" : gen) || x.dataset.gen == "-" + gen).map(x => x.innerText)[0];
if (value == undefined && gen == 0)
value = $(this).find("> span").toArray().filter(x => x.dataset.gen == 0).map(x => x.innerText)[0];
this.dataset.sortValue = (value == undefined ? "ZZ" : value.replace("(", "Z").replace("TM100", "TM999").split("*")[0]);
if (Object.keys(this).length > 0) this[Object.keys(this)[0]].sortValue = (value == undefined ? "ZZ" : value.replace("(", "Z").replace("TM100", "TM999").split("*")[0]); // jQuery-sortValue-Attribute manipulieren
});
}
jQuery(document).ready(function($) {
mw.loader.using('jquery.tablesorter', function() {
/* initialize generation labels and level sorting across generations */
$(".at").each(function() {
coltogen = $(this).find("thead tr:nth-child(2) th").toArray().map((x, i) => [Math.abs(x.dataset.gen), Math.abs(x.dataset.gen)].slice(0, x.colSpan).join(",")).join(",").split(",");
shift = $(this)[0].classList.contains("at_l") ? 1 : 0;
if ($(this)[0].classList.contains("at_z")) coltogen = coltogen.map(x => (coltogen.filter(y => y == x).length == 1 ? "+" : "") + x);
$(this).find("tbody tr:not(.expand-child)").each(function() {
$(this).find("td").toArray().slice(shift, coltogen.length+shift).forEach((x, i) => x.dataset.gen = coltogen[i]);
});
});
$(".at_l tbody tr td:nth-child(1)").each((i, x) => x.innerHTML = "" + i);
$(".at_l").each(function() {
id = $(this).find("thead tr:nth-child(1) th:nth-child(1)")[0];
level = $(this).find("thead tr:nth-child(1) th:nth-child(2)")[0];
id2 = document.createElement("th");
id2.rowSpan = id.rowSpan;
$(this).find("thead tr:nth-child(1)")[0].insertBefore(id2, id);
id.colSpan = level.colSpan;
id.rowSpan = level.rowSpan;
id.style.display = "";
level.style.display = "none";
});
/* initialize toggle buttons */
$(".at_toggle").each(function(index, object) {
var toggle = document.createElement("a");
toggle.className = 'at_togglerlink';
toggle.setAttribute('href', 'javascript:at_toggle("' + object.getAttribute("data-for") + '");');
var child = object.firstChild;
object.removeChild(child);
toggle.appendChild(child);
object.insertBefore(toggle, object.firstChild);
});
at_tmvmsortvalues(0);
});
});