Jump to content

MediaWiki:Common.js

Revision as of 12:34, 24 December 2025 by Rbutcher (talk | contribs) (Created page with "Any JavaScript here will be loaded for all users on every page load.: // Vector 2022: keep LEFT main menu OPEN for logged-out users on desktop (function () { // logged-out only if (mw.config.get('wgUserName')) return; function openMenu() { // desktop only (match your breakpoint) if (!window.matchMedia('(min-width: 1120px)').matches) return; const cb = document.getElementById('vector-main-menu-dropdown-checkbox'); if (!cb) return; // Forc...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Note: After publishing, you may have to bypass your browser's cache to see the changes.

  • Firefox / Safari: Hold Shift while clicking Reload, or press either Ctrl-F5 or Ctrl-R (⌘-R on a Mac)
  • Google Chrome: Press Ctrl-Shift-R (⌘-Shift-R on a Mac)
  • Edge: Hold Ctrl while clicking Refresh, or press Ctrl-F5.
/* Any JavaScript here will be loaded for all users on every page load. */
// Vector 2022: keep LEFT main menu OPEN for logged-out users on desktop
(function () {
  // logged-out only
  if (mw.config.get('wgUserName')) return;

  function openMenu() {
    // desktop only (match your breakpoint)
    if (!window.matchMedia('(min-width: 1120px)').matches) return;

    const cb = document.getElementById('vector-main-menu-dropdown-checkbox');
    if (!cb) return;

    // Force open
    cb.checked = true;

    // Trigger listeners
    cb.dispatchEvent(new Event('change', { bubbles: true }));
  }

  const obs = new MutationObserver(() => {
    if (document.documentElement.classList.contains('vector-animations-ready')) {
      openMenu();
      obs.disconnect();
      setTimeout(openMenu, 250);
      setTimeout(openMenu, 1000);
    }
  });

  obs.observe(document.documentElement, { attributes: true, attributeFilter: ['class'] });
  window.addEventListener('load', openMenu);
})();