MediaWiki:Common.js

/* Any JavaScript here will be loaded for all users on every page load. */

// Ace Editor if ((mw.config.get("wgAction") == "edit") && ((mw.config.get("wgNamespaceNumber") == 8) || (mw.config.get("wgNamespaceNumber") == 828))) { var observer = new MutationObserver(function(mutations) {   mutations.forEach(function(mutation) { var newNodes = mutation.addedNodes if (newNodes !== null) { $(newNodes).each(function {         if ($(this).hasClass("ace_content")) {            observer.disconnect            $(".ui-resizable").height(660)            var editor = ace.edit(document.getElementsByClassName("ace_editor")[0])            editor.setOptions({ theme: "ace/theme/solarized_dark", useSoftTabs: true, printMargin: false })           if (editor.session.$modeId != "ace/mode/css") {              editor.setOptions({ tabSize: 2, wrap: true })           }          }        })      }    })  })  observer.observe(document.getElementsByClassName("mw-body")[0], { childList: true, subtree: true }) }

// Floating table header // https://dev.fandom.com/wiki/FloatingTableHeader /* function waitForJQuery { if (typeof jQuery != "undefined") { floatheaderinit } else { window.setTimeout(waitForJQuery, 200) } } window.setTimeout(waitForJQuery, 200) //function floatheaderinit { if ($("table.floatheader").length) { $("table.floatheader").each(function {     $(this).wrap(" ")      var originalHeaderRow = $("tr:first", this)      var clonedHeaderRow = originalHeaderRow.clone      clonedHeaderRow.insertAfter(originalHeaderRow)      clonedHeaderRow.addClass("tableFloatingHeader")      clonedHeaderRow.css("position", "absolute")      clonedHeaderRow.css("top", "0")      clonedHeaderRow.css("left", $(this).css("margin-left"))      clonedHeaderRow.css("visibility", "hidden")      originalHeaderRow.addClass("tableFloatingHeaderOriginal")    }) // Remove transparency (& sort buttons) from floating headers /*   $(".tableFloatingHeader, .tableFloatingHeader th").each(function {      // Transparency      let bgcolors = $(this).css("background-color")      if (bgcolors != "rgba(0, 0, 0, 0)") {        $(this).css("background-color", "rgb(" + bgcolors.match(/\d+/g).slice(0, 3).join(" ") + ")")      }      // Sort buttons      if ($(this).hasClass("headerSort")) {        //$(this).removeClass("headerSort") // Header cells lose the width of the sort buttons        $(this).attr("style", function(i, s) { return (s + ";" || "") + "background-image: none !important" }) // Header cells are still clickable as if they were sortable      }    }) */   UpdateTableHeaders $(window).scroll(UpdateTableHeaders).resize(UpdateTableHeaders) function UpdateTableHeaders { $("div.divTableWithFloatingHeader").each(function {       var originalHeaderRow = $(".tableFloatingHeaderOriginal", this)        var floatingHeaderRow = $(".tableFloatingHeader", this)        var offset = $(this).offset        var scrollTop = $(window).scrollTop        if ((scrollTop > offset.top) && (scrollTop < offset.top + $(this).height)) {          floatingHeaderRow.css("visibility", "visible")          floatingHeaderRow.css("top", Math.min(scrollTop - offset.top, $(this).height - floatingHeaderRow.height) + "px")          // Copy cell widths from original header          $("th", floatingHeaderRow).each(function(index) { var cellWidth = $("th", originalHeaderRow).eq(index).css("width") $(this).css("width", cellWidth) })         // Copy row width from whole table          floatingHeaderRow.css("width", $(this).css("width"))        }        else {          floatingHeaderRow.css("visibility", "hidden")          floatingHeaderRow.css("top", "0")        }      }) } } //}