MediaWiki:Common.js

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

// Artifacts page table scroll if (mw.config.get("wgPageName") == "Artifacts") { waitForCollapsible function waitForCollapsible { if ($(".mw-collapsible").length == $(".mw-collapsible.mw-made-collapsible").length) { bind }   else { window.setTimeout(waitForCollapsible, 200) } }  function bind { var notestoggle = false var tableHeight = $("#artifact-table").offset.top + $("#artifact-table").outerHeight(true) $("#artifact-notes").click(function {     if (notestoggle) {        var windowHeight = $(window).height        if (tableHeight < $(window).scrollTop + windowHeight) {          window.scroll(0, tableHeight - windowHeight)        }      }      notestoggle = !notestoggle    }) } }

// 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 if ($("table.floatheader").length) { window.setTimeout(waitForTablesorter, 200) }

function waitForTablesorter { if ($("table.sortable").length == $("table.sortable.jquery-tablesorter").length) { floatheader } else { window.setTimeout(waitForTablesorter, 200) } }

function floatheader { $("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 header    $("th", clonedHeaderRow).each(function { // Transparency var 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").removeAttr("tabindex").removeAttr("title") }     // Handle collapsible columns if ($(this).hasClass("mw-made-collapsible")) { $(this).removeClass("mw-made-collapsible").makeCollapsible }   })  })  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")      }    }) } }