MediaWiki:Minerva.js: Unterschied zwischen den Versionen

Keine Bearbeitungszusammenfassung
Markierung: Zurückgesetzt
Keine Bearbeitungszusammenfassung
 
(5 dazwischenliegende Versionen desselben Benutzers werden nicht angezeigt)
Zeile 3: Zeile 3:
/* Weitere Menüs für MobileFrontend & MinervaNeue (Mobile Ansicht) */
/* Weitere Menüs für MobileFrontend & MinervaNeue (Mobile Ansicht) */
(function () {
(function () {
  // Nur Mobile-Skin (Minerva)
   if (mw.config.get('skin') !== 'minerva') return;
   if (mw.config.get('skin') !== 'minerva') return;
  const BLOCK_ID = 'ados-custom-links';


   // --- KONFIG: Label + Seitentitel (werden mit mw.util.getUrl() sicher verlinkt)
   // --- KONFIG: Label + Seitentitel (werden mit mw.util.getUrl() sicher verlinkt)
  // Header/Sektionen haben title = null
  // WICHTIG: "📊 Diagramm / Statistik" steht ganz oben
   const LINKS = [
   const LINKS = [
     ['Hauptkategorien', null], // Header/Toggle, kein Link
     ['📊 Diagramm / Statistik', null],
     ['Alle A Dream of Scotland Abfüllungen', 'Kategorie:Alle A Dream of Scotland Abfüllungen'],
     ['Abfüllungen pro Jahr', 'Abfüllungen_pro_Jahr'],
     ['Alle A Dream of Ireland Abfüllungen',  'Kategorie:Alle A Dream of Ireland Abfüllungen'],
     // optional:
     ['Alle A Dream of... Der Rest der Welt', 'Kategorie:Alle A Dream of... – Der Rest der Welt Abfüllungen'],
     // ['Top 5 Community', 'Top_5'],
    ['Cigar Malt Übersicht', 'Kategorie:Cigar Malt Übersicht'],
    ['Alle Rumbastic Abfüllungen', 'Kategorie:Alle Rumbastic Abfüllungen'],
    ['The Tasteful 8', 'Kategorie:The Tasteful 8'],
    ['Còmhlan Abfüllungen', 'Kategorie:Còmhlan Abfüllungen'],
    ['Friendly Mr. Z Whiskytainment Abfüllungen', 'Kategorie:Friendly Mr. Z Whiskytainment Abfüllungen'],
    ['Die Whisky Elfen Abfüllungen', 'Kategorie:Die Whisky Elfen Abfüllungen'],
    ['The Fine Art of Whisky Abfüllungen', 'Kategorie:The Fine Art of Whisky Abfüllungen'],
    ['The Forbidden Kingdom', 'Kategorie:The Forbidden Kingdom'],
    ['Sonderabfüllungen', 'Kategorie:Sonderabfüllungen'] // <— NEU
  ];


 
     ['Hauptkategorien', null],
  // --- KONFIG: Label + Seitentitel (werden mit mw.util.getUrl() sicher verlinkt)
  const LINKS = [
     ['Hauptkategorien', null], // Header/Toggle, kein Link
     ['Alle A Dream of Scotland Abfüllungen', 'Kategorie:Alle A Dream of Scotland Abfüllungen'],
     ['Alle A Dream of Scotland Abfüllungen', 'Kategorie:Alle A Dream of Scotland Abfüllungen'],
     ['Alle A Dream of Ireland Abfüllungen', 'Kategorie:Alle A Dream of Ireland Abfüllungen'],
     ['Alle A Dream of Ireland Abfüllungen', 'Kategorie:Alle A Dream of Ireland Abfüllungen'],
     ['Alle A Dream of... – Der Rest der Welt', 'Kategorie:Alle A Dream of... – Der Rest der Welt Abfüllungen'],
     ['Alle A Dream of... – Der Rest der Welt', 'Kategorie:Alle A Dream of... – Der Rest der Welt Abfüllungen'],
     ['Cigar Malt Übersicht', 'Kategorie:Cigar Malt Übersicht'],
     ['Cigar Malt Übersicht', 'Kategorie:Cigar Malt Übersicht'],
Zeile 37: Zeile 29:
     ['The Fine Art of Whisky Abfüllungen', 'Kategorie:The Fine Art of Whisky Abfüllungen'],
     ['The Fine Art of Whisky Abfüllungen', 'Kategorie:The Fine Art of Whisky Abfüllungen'],
     ['The Forbidden Kingdom', 'Kategorie:The Forbidden Kingdom'],
     ['The Forbidden Kingdom', 'Kategorie:The Forbidden Kingdom'],
     ['Sonderabfüllungen', 'Kategorie:Sonderabfüllungen'] // <— NEU
     ['Sonderabfüllungen', 'Kategorie:Sonderabfüllungen']
   ];
   ];
  const BLOCK_ID = 'ados-custom-links';


   function findMenuList() {
   function findMenuList() {
Zeile 50: Zeile 40:
       document.querySelector('.menu')
       document.querySelector('.menu')
     );
     );
  }
  function buildSectionsFromLinks(links) {
    const sections = [];
    let current = null;
    for (const [label, title] of links) {
      if (title === null) {
        current = { header: label, items: [] };
        sections.push(current);
      } else if (current) {
        current.items.push({ label, title });
      }
    }
    return sections;
   }
   }


Zeile 55: Zeile 60:
     const host = findMenuList();
     const host = findMenuList();
     if (!host) return false;
     if (!host) return false;
    if (document.getElementById(BLOCK_ID)) return true; // schon eingebaut


     // äußerer Block
     // schon eingebaut?
     const outer = document.createElement('ul');
     if (document.getElementById(BLOCK_ID)) return true;
    outer.id = BLOCK_ID;
    outer.className = 'toggle-list__list';


    // Header mit Icon + Toggle
     const sections = buildSectionsFromLinks(LINKS);
     const [headerLabel] = LINKS[0];
     if (!sections.length) return false;
     const headerLi = document.createElement('li');
    headerLi.className = 'toggle-list-item';


     const headerBtn = document.createElement('button');
    // Container für alle Sektionen
    headerBtn.type = 'button';
     const container = document.createElement('div');
    headerBtn.className = 'toggle-list-item__anchor';
     container.id = BLOCK_ID;
    headerBtn.setAttribute('aria-expanded', 'true');
     headerBtn.innerHTML =
      '<span class="minerva-icon minerva-icon--listBullet"></span>' +
      `<span class="toggle-list-item__label">${headerLabel}</span>`;


     headerLi.appendChild(headerBtn);
     sections.forEach((sec, idx) => {
    outer.appendChild(headerLi);
      const secId = `${BLOCK_ID}-sec-${idx}`;


    // Unterpunkte-Liste (ohne Icons)
      // äußerer Block je Sektion
    const inner = document.createElement('ul');
      const outer = document.createElement('ul');
    inner.className = 'toggle-list__list';
      outer.className = 'toggle-list__list';
    inner.style.marginLeft = '10px';


    for (let i = 1; i < LINKS.length; i++) {
      // Header mit Icon + Toggle
       const [label, title] = LINKS[i];
       const headerLi = document.createElement('li');
      const li = document.createElement('li');
       headerLi.className = 'toggle-list-item';
       li.className = 'toggle-list-item';


       const a = document.createElement('a');
       const headerBtn = document.createElement('button');
       a.className = 'toggle-list-item__anchor';
       headerBtn.type = 'button';
       a.textContent = label;
      headerBtn.className = 'toggle-list-item__anchor';
       a.href = title ? mw.util.getUrl(title) : '#';
       headerBtn.setAttribute('aria-expanded', 'true');
       headerBtn.innerHTML =
        '<span class="minerva-icon minerva-icon--listBullet"></span>' +
        `<span class="toggle-list-item__label">${sec.header}</span>`;


       // KEIN Icon bei Unterpunkten
      headerLi.appendChild(headerBtn);
       li.appendChild(a);
      outer.appendChild(headerLi);
      inner.appendChild(li);
 
    }
       // Unterpunkte-Liste (ohne Icons)
    outer.appendChild(inner);
      const inner = document.createElement('ul');
      inner.className = 'toggle-list__list';
      inner.style.marginLeft = '10px';
 
       sec.items.forEach(({ label, title }) => {
        const li = document.createElement('li');
        li.className = 'toggle-list-item';
 
        const a = document.createElement('a');
        a.className = 'toggle-list-item__anchor';
        a.textContent = label;
        a.href = mw.util.getUrl(title);
 
        li.appendChild(a);
        inner.appendChild(li);
      });
 
      outer.appendChild(inner);
 
      // Toggle-Logik pro Sektion
      headerBtn.addEventListener('click', function () {
        const expanded = this.getAttribute('aria-expanded') === 'true';
        this.setAttribute('aria-expanded', String(!expanded));
        inner.style.display = expanded ? 'none' : '';
        try { localStorage.setItem(secId + ':collapsed', expanded ? '1' : '0'); } catch (e) {}
      });
 
      // Zustand wiederherstellen
      try {
        if (localStorage.getItem(secId + ':collapsed') === '1') {
          headerBtn.setAttribute('aria-expanded', 'false');
          inner.style.display = 'none';
        }
      } catch (e) {}


    // Toggle-Logik
       container.appendChild(outer);
    headerBtn.addEventListener('click', function () {
      const expanded = this.getAttribute('aria-expanded') === 'true';
      this.setAttribute('aria-expanded', String(!expanded));
       inner.style.display = expanded ? 'none' : '';
      try { localStorage.setItem(BLOCK_ID + ':collapsed', expanded ? '1' : '0'); } catch (e) {}
     });
     });
    // Zustand wiederherstellen
    try {
      if (localStorage.getItem(BLOCK_ID + ':collapsed') === '1') {
        headerBtn.setAttribute('aria-expanded', 'false');
        inner.style.display = 'none';
      }
    } catch (e) {}


     // nach der ersten vorhandenen UL einfügen (direkt unter Start/Zufällige Seite)
     // nach der ersten vorhandenen UL einfügen (direkt unter Start/Zufällige Seite)
     const firstUl = host.querySelector('ul') || host;
     const firstUl = host.querySelector('ul') || host;
     (firstUl.parentNode || host).insertBefore(outer, firstUl.nextSibling);
     (firstUl.parentNode || host).insertBefore(container, firstUl.nextSibling);


     return true;
     return true;
Zeile 124: Zeile 141:
   // beim Laden probieren …
   // beim Laden probieren …
   document.addEventListener('DOMContentLoaded', () => setTimeout(build, 0));
   document.addEventListener('DOMContentLoaded', () => setTimeout(build, 0));
   // … und wenn das Burger-Menü dynamisch aufgebaut wird, nochmal
   // … und wenn das Burger-Menü dynamisch aufgebaut wird, nochmal
   document.addEventListener('click', (e) => {
   document.addEventListener('click', (e) => {
Zeile 133: Zeile 151:
     }
     }
   });
   });
   // Fallback: Observer für lazy DOM
   // Fallback: Observer für lazy DOM
   const obs = new MutationObserver(() => { if (build()) obs.disconnect(); });
   const obs = new MutationObserver(() => { if (build()) obs.disconnect(); });