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 6: Line 6:
     sortPFCheckboxes();
     sortPFCheckboxes();
     infoboxEvenOdd();
     infoboxEvenOdd();
    showPageFooter();
});
});


Line 57: Line 58:
     el.classList.add(idx % 2 === 0 ? '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);
});
}
}

Latest revision as of 00:26, 23 March 2026

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


$(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 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');
  });
}

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

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