MediaWiki:Common.js: differenze tra le versioni
Vai alla navigazione
Vai alla ricerca
m (Temporary disable ToggleTOC) |
(Function to automatically add row numbers) |
||
Riga 2: | Riga 2: | ||
/* [[Categoria:Pagine create manualmente]] */ | /* [[Categoria:Pagine create manualmente]] */ | ||
/* [[Categoria:Pagine importate dal sito di test]] */ | /* [[Categoria:Pagine importate dal sito di test]] */ | ||
/* | |||
Automatically add row numbers to a table with class "numberedrow" | |||
Only works with table headers | |||
See https://codepen.io/lucamauri/pen/MWdmQNj?editors=1111 for testing | |||
*/ | |||
function numberRows() { | |||
var table = document.getElementsByClassName("numberedrows")[0], | |||
rows = table.getElementsByTagName("tr"), | |||
text = "textContent" in document ? "textContent" : "innerText"; | |||
/* console.log(rows); */ | |||
for (var i = 0, len = rows.length; i < len; i++) { | |||
if (i == 0) { | |||
th = rows[i].insertBefore( | |||
document.createElement("th"), | |||
rows[i].children[0] | |||
); | |||
th.textContent = "N°"; | |||
} else { | |||
td = rows[i].insertBefore( | |||
document.createElement("td"), | |||
rows[i].children[0] | |||
); | |||
td.textContent = i; | |||
} | |||
} | |||
} |
Versione delle 15:48, 4 giu 2024
/* Il codice JavaScript inserito qui viene caricato da ciascuna pagina, per tutti gli utenti. */
/* [[Categoria:Pagine create manualmente]] */
/* [[Categoria:Pagine importate dal sito di test]] */
/*
Automatically add row numbers to a table with class "numberedrow"
Only works with table headers
See https://codepen.io/lucamauri/pen/MWdmQNj?editors=1111 for testing
*/
function numberRows() {
var table = document.getElementsByClassName("numberedrows")[0],
rows = table.getElementsByTagName("tr"),
text = "textContent" in document ? "textContent" : "innerText";
/* console.log(rows); */
for (var i = 0, len = rows.length; i < len; i++) {
if (i == 0) {
th = rows[i].insertBefore(
document.createElement("th"),
rows[i].children[0]
);
th.textContent = "N°";
} else {
td = rows[i].insertBefore(
document.createElement("td"),
rows[i].children[0]
);
td.textContent = i;
}
}
}