MediaWiki:Common.js: Difference between revisions

From Melvor Idle
(Attempting to fix error)
(Added semicolon?)
Line 11: Line 11:
     let firstHeight = 0;
     let firstHeight = 0;
     if (firstRow.length > 0) {
     if (firstRow.length > 0) {
       firstHeight = firstRow[0].offsetHeight
       firstHeight = firstRow[0].offsetHeight;
       const firstHeaders = firstRow[0].getElementsByTagName('th');
       const firstHeaders = firstRow[0].getElementsByTagName('th');
       for (let j = 0; j < firstHeaders.length; j++) {
       for (let j = 0; j < firstHeaders.length; j++) {

Revision as of 00:25, 12 June 2020

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

/* Sets the top property for stickyHeader tables */

$(document).ready(function() {
  const stickyTables = document.getElementsByClassName('stickyHeader');
  const headHeight = document.getElementById('mw-header-container').offsetHeight;
  for (i = 0; i < stickyTables.length; i++) {
    const firstRow = stickyTables[i].getElementsByClassName('firstHeaderRow');
    const secondRow = stickyTables[i].getElementsByClassName('secondHeaderRow');
    let firstHeight = 0;
    if (firstRow.length > 0) {
      firstHeight = firstRow[0].offsetHeight;
      const firstHeaders = firstRow[0].getElementsByTagName('th');
      for (let j = 0; j < firstHeaders.length; j++) {
        firstHeaders[j].style.top = `${headHeight}px`;
      }
      if (secondRow.length > 0) {
        const secondHeaders = secondRow[0].getElementsByTagName('th');
        for (let j = 0; j < secondHeaders.length; j++) {
          secondHeaders[j].style.top = `${headHeight + firstHeight}px`;
        }
      }
    }
  }
});