17,097
edits
(Remove dark mode JS - Managed entirely through CSS & notice has already been present for months) |
(Attempt to correct issue where sticky headers may not be initialized correctly before the page fully loads) |
||
Line 523: | Line 523: | ||
/* Sets the top property for stickyHeader tables */ | /* Sets the top property for stickyHeader tables */ | ||
function setStickyHeaderTop() { | function setStickyHeaderTop() { | ||
var stickyTables = document.getElementsByClassName('stickyHeader'); | |||
var headStyles = getComputedStyle(document.getElementById('mw-header-container')); | |||
var headHeight = document.getElementById('mw-header-container').offsetHeight; | |||
if (headStyles !== undefined && headStyles.position === 'static') { | |||
headHeight = 0; | |||
} | |||
for (var i = 0; i < stickyTables.length; i++) { | |||
var firstRow = stickyTables[i].getElementsByClassName('headerRow-0'); | |||
var secondRow = stickyTables[i].getElementsByClassName('headerRow-1'); | |||
var firstHeight = 0; | |||
if (firstRow.length > 0) { | |||
firstHeight = firstRow[0].offsetHeight; | |||
var firstHeaders = firstRow[0].getElementsByTagName('th'); | |||
for (var j = 0; j < firstHeaders.length; j++) { | |||
firstHeaders[j].style.top = headHeight + 'px'; | |||
} | |||
if (secondRow.length > 0) { | |||
var secondHeaders = secondRow[0].getElementsByTagName('th'); | |||
var secondHeight = headHeight + firstHeight - 1; | |||
for (var j = 0; j < secondHeaders.length; j++) { | |||
secondHeaders[j].style.top = secondHeight + 'px'; | |||
} | |||
} | |||
} | |||
} | |||
} | |||
} | |||
} | } | ||
$(document).ready(function () { | $(document).ready(function () { | ||
// Table sticky headers | // Table sticky headers | ||
var elemSticky = document.getElementsByClassName('stickyHeader'); | |||
if (elemSticky.length > 0) { | if (elemSticky.length > 0) { | ||
// Sticky headers do not function well when Tabber containers/article tags. | // Sticky headers do not function well when Tabber containers/article tags. | ||
// Therefore identify any stickyHeader tables within these containers | // Therefore identify any stickyHeader tables within these containers | ||
// and remove the stickyHeader class | // and remove the stickyHeader class | ||
var elemArticle = document.getElementsByTagName('article'); | |||
if (elemArticle.length > 0) { | if (elemArticle.length > 0) { | ||
for (var kS = 0; kS < elemSticky.length; kS++) { | for (var kS = 0; kS < elemSticky.length; kS++) { | ||
for (var kA = 0; kA < elemArticle.length; kA++) { | for (var kA = 0; kA < elemArticle.length; kA++) { | ||
var eSticky = elemSticky[kS]; | |||
var eArticle = elemArticle[kA]; | |||
if (eArticle.contains(eSticky)) { | if (eArticle.contains(eSticky)) { | ||
eSticky.classList.remove('stickyHeader'); | eSticky.classList.remove('stickyHeader'); | ||
Line 598: | Line 569: | ||
} | } | ||
} | } | ||
// Initialize sticky header positions | |||
setStickyHeaderTop(); | setStickyHeaderTop(); | ||
// Reset sticky header positions when the window resizes, as this may | |||
// affect visibility of fixed elements at the top of the page | |||
$(window).resize(setStickyHeaderTop); | $(window).resize(setStickyHeaderTop); | ||
// Reset sticky header positions once the page is fully loaded. | |||
// Without this, headers may have an incorrect offset | |||
window.addEventListener('load', function(event) { setStickyHeaderTop(); }); | |||
} | } | ||
}); | }); |