MediaWiki:Gadget-Tables.js

//

const ALTROW_MIN_ROWS = 5; // minimum number of data rows required in a table before alternating colors are enabled automatically

$(document).ready(function{	// Allows tables to have a horizontal scrollbar. See CSS.	// There doesn't seem to be a good way to achieve this by styling the table element itself	$('.wikitable:not(.infobox)').wrap(' ');	// Turn table rows with IDs into clickable links (excluding reference IDs)	// Gives readers a way to discover and share section links that aren't covered in the table of contents	$("tr[id], tr:has([id])").click(function { const id = $(this).attr("id") || $(this).find("[id]").attr("id"); if (!id.startsWith("cite_ref-")) { window.location.hash = id; }	});	// Add alternating row colors to large tables in the mainspace which do not have rowspans (rowspans mess up the alternations)	$(".ns-0 .wikitable:not(.infobox):not(:has([rowspan]))").each(function { const rowCount = $(this).find("tr:has(td)").length; if (rowCount >= ALTROW_MIN_ROWS) { $(this).addClass("altrow"); }	}); });