Jump to content

MediaWiki:Common.js

From Carbon Accounting Alliance Wiki
Revision as of 21:00, 11 March 2025 by WikiSysop (talk | contribs)

Note: After publishing, you may have to bypass your browser's cache to see the changes.

  • Firefox / Safari: Hold Shift while clicking Reload, or press either Ctrl-F5 or Ctrl-R (⌘-R on a Mac)
  • Google Chrome: Press Ctrl-Shift-R (⌘-Shift-R on a Mac)
  • Edge: Hold Ctrl while clicking Refresh, or press Ctrl-F5.
/* Any JavaScript here will be loaded for all users on every page load. */

#Filterable tables
document.addEventListener("DOMContentLoaded", function () {
    function createFilterInputs(table) {
        let thead = table.querySelector("thead");
        if (!thead) {
            console.warn("No <thead> found, creating one...");
            let headerRow = table.rows[0];
            if (!headerRow) return;
            thead = document.createElement("thead");
            thead.appendChild(headerRow.cloneNode(true));
            table.insertBefore(thead, table.firstChild);
        }

        let filterRow = document.createElement("tr");

        for (let i = 0; i < thead.rows[0].cells.length; i++) {
            let th = document.createElement("th");
            let input = document.createElement("input");

            input.setAttribute("type", "text");
            input.setAttribute("placeholder", "Filter...");
            input.style.width = "90%";
            input.dataset.column = i;

            input.addEventListener("keyup", function () {
                let colIndex =