MediaWiki:Common.js: Difference between revisions
From Melvor Idle
(replace string literals) |
(Added code to resize. Only applies when stickyHeader tables are on the page.) |
||
Line 2: | Line 2: | ||
/* Sets the top property for stickyHeader tables */ | /* Sets the top property for stickyHeader tables */ | ||
function setStickyHeaderTop() { | |||
const stickyTables = document.getElementsByClassName('stickyHeader'); | const stickyTables = document.getElementsByClassName('stickyHeader'); | ||
const headHeight = document.getElementById('mw-header-container').offsetHeight; | const headHeight = document.getElementById('mw-header-container').offsetHeight; | ||
Line 25: | Line 24: | ||
} | } | ||
} | } | ||
}); | } | ||
$(document).ready(function () { | |||
if (document.getElementsByClassName('stickyHeader').length > 0) { | |||
setStickyHeaderTop(); | |||
$(window).resize(setStickyHeaderTop); | |||
} | |||
} | |||
); |
Revision as of 01:01, 12 June 2020
/* Any JavaScript here will be loaded for all users on every page load. */
/* Sets the top property for stickyHeader tables */
function setStickyHeaderTop() {
const stickyTables = document.getElementsByClassName('stickyHeader');
const headHeight = document.getElementById('mw-header-container').offsetHeight;
for (var i = 0; i < stickyTables.length; i++) {
const firstRow = stickyTables[i].getElementsByClassName('firstHeaderRow');
const secondRow = stickyTables[i].getElementsByClassName('secondHeaderRow');
var firstHeight = 0;
if (firstRow.length > 0) {
firstHeight = firstRow[0].offsetHeight;
const firstHeaders = firstRow[0].getElementsByTagName('th');
for (var j = 0; j < firstHeaders.length; j++) {
firstHeaders[j].style.top = headHeight + 'px';
}
if (secondRow.length > 0) {
const secondHeaders = secondRow[0].getElementsByTagName('th');
var secondHeight = headHeight + firstHeight;
for (var j = 0; j < secondHeaders.length; j++) {
secondHeaders[j].style.top = secondHeight + 'px';
}
}
}
}
}
$(document).ready(function () {
if (document.getElementsByClassName('stickyHeader').length > 0) {
setStickyHeaderTop();
$(window).resize(setStickyHeaderTop);
}
}
);