Jump to content

MediaWiki:Common.js: Difference between revisions

From Doom Relics
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..."
 
No edit summary
Line 1: Line 1:
/* Any JavaScript here will be loaded for all users on every page load. */
/* 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
// Vector 2022: for logged-out users on desktop, OPEN the menu and PIN it (real left sidebar)
(function () {
(function () {
  // logged-out only
   if (mw.config.get('wgUserName')) return; // logged-out only
   if (mw.config.get('wgUserName')) return;


   function openMenu() {
   function click(sel) {
     // desktop only (match your breakpoint)
     const el = document.querySelector(sel);
    if (el) { el.click(); return true; }
    return false;
  }
 
  function forceRealSidebar() {
     if (!window.matchMedia('(min-width: 1120px)').matches) return;
     if (!window.matchMedia('(min-width: 1120px)').matches) return;


    // 1) Ensure the menu is opened (your install uses a checkbox toggle)
     const cb = document.getElementById('vector-main-menu-dropdown-checkbox');
     const cb = document.getElementById('vector-main-menu-dropdown-checkbox');
     if (!cb) return;
     if (cb) {
 
      cb.checked = true;
    // Force open
      cb.dispatchEvent(new Event('change', { bubbles: true }));
    cb.checked = true;
    }


     // Trigger listeners
     // 2) Click the PIN button (this is what makes it a real left sidebar)
     cb.dispatchEvent(new Event('change', { bubbles: true }));
     // Try the standard selector first; keep fallbacks for version differences.
    click('[data-event-name="pinnable-header.vector-main-menu.pin"]') ||
    click('[data-event-name="pinnable-header.vector-main-menu.unpin"]') ||
    click('#vector-main-menu-pinned-container button');
   }
   }


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


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

Revision as of 12:39, 24 December 2025

/* Any JavaScript here will be loaded for all users on every page load. */
// Vector 2022: for logged-out users on desktop, OPEN the menu and PIN it (real left sidebar)
(function () {
  if (mw.config.get('wgUserName')) return; // logged-out only

  function click(sel) {
    const el = document.querySelector(sel);
    if (el) { el.click(); return true; }
    return false;
  }

  function forceRealSidebar() {
    if (!window.matchMedia('(min-width: 1120px)').matches) return;

    // 1) Ensure the menu is opened (your install uses a checkbox toggle)
    const cb = document.getElementById('vector-main-menu-dropdown-checkbox');
    if (cb) {
      cb.checked = true;
      cb.dispatchEvent(new Event('change', { bubbles: true }));
    }

    // 2) Click the PIN button (this is what makes it a real left sidebar)
    // Try the standard selector first; keep fallbacks for version differences.
    click('[data-event-name="pinnable-header.vector-main-menu.pin"]') ||
    click('[data-event-name="pinnable-header.vector-main-menu.unpin"]') ||
    click('#vector-main-menu-pinned-container button');
  }

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

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