PC Gaming Shelter
An archive dedicated to preserving PC Gaming history and more

MediaWiki:Common.js: Difference between revisions

From PC Gaming Shelter
No edit summary
No edit summary
Line 4: Line 4:
managePersonalIconVis();
managePersonalIconVis();
     sortPFCheckboxes();
     sortPFCheckboxes();
    infoboxEvenOdd();
});
});
window.addEventListener('resize', infoboxEvenOdd);


function managePersonalIconVis(){
function managePersonalIconVis(){
Line 34: Line 37:
     );
     );
     labels.forEach(label => container.appendChild(label));
     labels.forEach(label => container.appendChild(label));
  });
}
function infoboxEvenOdd() {
  const container = document.querySelector('.infobox');
  if (!container) return;
  const items = Array.from(container.children).filter(
    el => el.nodeType === Node.ELEMENT_NODE
  );
  items.sort((a, b) =>
    a.getBoundingClientRect().top - b.getBoundingClientRect().top
  );
  items.forEach((el, idx) => {
    el.classList.remove('even', 'odd');
    el.classList.add(idx % 2 === 0 ? 'even' : 'odd');
   });
   });
}
}

Revision as of 22:57, 22 March 2026

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

$(function() {
	managePersonalIconVis();
    sortPFCheckboxes();
    infoboxEvenOdd();
});

window.addEventListener('resize', infoboxEvenOdd);

function managePersonalIconVis(){
  if (mw.config.get('wgUserId') !== null) {
	const personal = document.getElementById('p-personal');
	document.querySelector('#pane4').appendChild(personal);
  } else {
	const personalIcon = document.querySelector('.personal-tools-icon');
	if (personalIcon) {
		personalIcon.classList.add('d-none');
	}
  }
}

function sortPFCheckboxes() {
  const containers = document.querySelectorAll(".checkboxesSpan");

  containers.forEach(container => {
    const labels = Array.from(container.querySelectorAll("label.checkboxLabel"));

    const getText = el =>
      (el.querySelector("t").textContent || el.textContent).trim();

    labels.sort((a, b) =>
      getText(a).localeCompare(getText(b), undefined, {
        numeric: true,
        sensitivity: "base"
      })
    );
    labels.forEach(label => container.appendChild(label));
  });
}

function infoboxEvenOdd() {
  const container = document.querySelector('.infobox');
  if (!container) return;

  const items = Array.from(container.children).filter(
    el => el.nodeType === Node.ELEMENT_NODE
  );

  items.sort((a, b) =>
    a.getBoundingClientRect().top - b.getBoundingClientRect().top
  );

  items.forEach((el, idx) => {
    el.classList.remove('even', 'odd');
    el.classList.add(idx % 2 === 0 ? 'even' : 'odd');
  });
}