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 94: Line 94:
         const inactive = maxScroll <= 0
         const inactive = maxScroll <= 0
           || (dir < 0 && body.scrollTop <= 0)
           || (dir < 0 && body.scrollTop <= 0)
           || (dir > 0 && body.scrollTop >= maxScroll - 1);
           || (dir > 0 && body.scrollTop >= maxScroll - 4);


         button.disabled = inactive;
         button.disabled = inactive;

Revision as of 14:11, 19 June 2026

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

mw.loader.load(
  '/w/index.php?title=MediaWiki:Featured-video.js&action=raw&ctype=text/javascript'
);
mw.loader.load(
  '/w/index.php?title=MediaWiki:Datatables.js&action=raw&ctype=text/javascript'
);

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

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 containers = document.querySelectorAll('.infobox-row');
  if (!containers.length) return;

  containers.forEach(container => {
    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');
    });
  });
}

function showPageFooter(){
	const catlinks = document.getElementById('catlinks');
	const footers = document.querySelectorAll('.page-footer');

	footers.forEach(el => {
		catlinks.parentNode.insertBefore(el, catlinks);
	});
}

document.querySelectorAll('.thumbwall').forEach((card) => {
    const body = card.querySelector('.card-body');
    const buttons = card.querySelectorAll('[data-scroll-dir]');

    if (!body || !buttons.length) {
      return;
    }

    const scrollStep = 64;

    const updateButtons = () => {
      const maxScroll = body.scrollHeight - body.clientHeight;

      buttons.forEach((button) => {
        const dir = Number(button.dataset.scrollDir);
        const inactive = maxScroll <= 0
          || (dir < 0 && body.scrollTop <= 0)
          || (dir > 0 && body.scrollTop >= maxScroll - 4);

        button.disabled = inactive;
        button.classList.toggle('is-inactive', inactive);
        button.setAttribute('aria-disabled', inactive);
      });
    };

    buttons.forEach((button) => {
      button.addEventListener('click', () => {
        body.scrollBy({
          top: Number(button.dataset.scrollDir) * scrollStep,
          behavior: 'smooth'
        });
      });
    });

    body.addEventListener('scroll', updateButtons);
    window.addEventListener('resize', updateButtons);
    updateButtons();
});