MediaWiki:Minerva.js: Unterschied zwischen den Versionen

Keine Bearbeitungszusammenfassung
Markierungen: Mobile Bearbeitung Mobile Web-Bearbeitung Erweiterte mobile Bearbeitung
Keine Bearbeitungszusammenfassung
 
(16 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;


   // ---- KONFIG: Links als [Label, Seitentitel] ----
  const BLOCK_ID = 'ados-custom-links';
 
   // --- 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],
    ['Abfüllungen pro Jahr', 'Abfüllungen_pro_Jahr'],
    // optional:
    // ['Top 5 – Community', 'Top_5'],
 
    ['Hauptkategorien', null],
     ['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 18: Zeile 28:
     ['Die Whisky Elfen Abfüllungen', 'Kategorie:Die Whisky Elfen 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 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']
   ];
   ];
  const BLOCK_ID = 'ados-custom-links';


   function findMenuList() {
   function findMenuList() {
Zeile 31: 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 36: Zeile 60:
     const host = findMenuList();
     const host = findMenuList();
     if (!host) return false;
     if (!host) return false;
    if (document.getElementById(BLOCK_ID)) return true; // schon vorhanden


     const ul = document.createElement('ul');
    // schon eingebaut?
     ul.id = BLOCK_ID;
    if (document.getElementById(BLOCK_ID)) return true;
     ul.className = 'toggle-list__list';
 
     const sections = buildSectionsFromLinks(LINKS);
    if (!sections.length) return false;
 
    // Container für alle Sektionen
    const container = document.createElement('div');
     container.id = BLOCK_ID;
 
     sections.forEach((sec, idx) => {
      const secId = `${BLOCK_ID}-sec-${idx}`;
 
      // äußerer Block je Sektion
      const outer = document.createElement('ul');
      outer.className = 'toggle-list__list';
 
      // Header mit Icon + Toggle
      const headerLi = document.createElement('li');
      headerLi.className = 'toggle-list-item';


    // Header/Toggle
      const headerBtn = document.createElement('button');
    const [headerLabel] = LINKS[0];
      headerBtn.type = 'button';
    const headerLi = document.createElement('li');
      headerBtn.className = 'toggle-list-item__anchor';
    headerLi.className = 'toggle-list-item';
      headerBtn.setAttribute('aria-expanded', 'true');
    const headerBtn = document.createElement('button');
      headerBtn.innerHTML =
    headerBtn.type = 'button';
        '<span class="minerva-icon minerva-icon--listBullet"></span>' +
    headerBtn.className = 'toggle-list-item__anchor';
        `<span class="toggle-list-item__label">${sec.header}</span>`;
    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);
    ul.appendChild(headerLi);


    // Container für die eigentlichen Links (collapsible)
      headerLi.appendChild(headerBtn);
    const innerUl = document.createElement('ul');
      outer.appendChild(headerLi);
    innerUl.className = 'toggle-list__list';
    innerUl.style.marginLeft = '12px';


    for (let i = 1; i < LINKS.length; i++) {
      // Unterpunkte-Liste (ohne Icons)
      const [label, title] = LINKS[i];
       const inner = document.createElement('ul');
       const li = document.createElement('li');
       inner.className = 'toggle-list__list';
       li.className = 'toggle-list-item';
      inner.style.marginLeft = '10px';


       const a = document.createElement('a');
       sec.items.forEach(({ label, title }) => {
      a.className = 'toggle-list-item__anchor';
        const li = document.createElement('li');
      a.textContent = label;
        li.className = 'toggle-list-item';


      if (title) {
        const a = document.createElement('a');
         // sichere URL auf Basis des Seitentitels (Sonderzeichen/Leerzeichen ok)
         a.className = 'toggle-list-item__anchor';
        a.textContent = label;
         a.href = mw.util.getUrl(title);
         a.href = mw.util.getUrl(title);
      } else {
        a.href = '#';
        a.setAttribute('role', 'button');
      }


if (i === 1) { // beim ersten Unterpunkt noch kein Icon
        li.appendChild(a);
  const icon = document.createElement('span');
        inner.appendChild(li);
  icon.className = 'minerva-icon minerva-icon--article';
      });
  a.prepend(icon);
 
}
      outer.appendChild(inner);


       li.appendChild(a);
       // Toggle-Logik pro Sektion
      innerUl.appendChild(li);
      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) {}
      });


    ul.appendChild(innerUl);
      // Zustand wiederherstellen
      try {
        if (localStorage.getItem(secId + ':collapsed') === '1') {
          headerBtn.setAttribute('aria-expanded', 'false');
          inner.style.display = 'none';
        }
      } catch (e) {}


    // Toggle-Verhalten für Header
       container.appendChild(outer);
    headerBtn.addEventListener('click', function () {
      const expanded = this.getAttribute('aria-expanded') === 'true';
      this.setAttribute('aria-expanded', String(!expanded));
       innerUl.style.display = expanded ? 'none' : '';
      try { localStorage.setItem(BLOCK_ID + ':collapsed', expanded ? '1' : '0'); } catch (e) {}
     });
     });


     // Zustand wiederherstellen
     // nach der ersten vorhandenen UL einfügen (direkt unter Start/Zufällige Seite)
    try {
      if (localStorage.getItem(BLOCK_ID + ':collapsed') === '1') {
        headerBtn.setAttribute('aria-expanded', 'false');
        innerUl.style.display = 'none';
      }
    } catch (e) {}
 
    // Nach der ersten UL einfügen
     const firstUl = host.querySelector('ul') || host;
     const firstUl = host.querySelector('ul') || host;
     (firstUl.parentNode || host).insertBefore(ul, firstUl.nextSibling);
     (firstUl.parentNode || host).insertBefore(container, firstUl.nextSibling);


     return true;
     return true;
   }
   }


   // Beim Laden versuchen
   // beim Laden probieren …
   document.addEventListener('DOMContentLoaded', () => setTimeout(build, 0));
   document.addEventListener('DOMContentLoaded', () => setTimeout(build, 0));


   // Wenn das Menü erst beim Öffnen gebaut wird – nachklinken
   // … und wenn das Burger-Menü dynamisch aufgebaut wird, nochmal
   document.addEventListener('click', (e) => {
   document.addEventListener('click', (e) => {
     const btn = e.target.closest('button, a');
     const btn = e.target.closest('button, a');
Zeile 126: Zeile 152:
   });
   });


   // Fallback: Menü taucht asynchron auf
   // Fallback: Observer für lazy DOM
   const obs = new MutationObserver(() => { if (build()) obs.disconnect(); });
   const obs = new MutationObserver(() => { if (build()) obs.disconnect(); });
   obs.observe(document.documentElement, { childList: true, subtree: true });
   obs.observe(document.documentElement, { childList: true, subtree: true });
})();
// ----------Abschnitte Geöffnet-----------
/* Minerva: Alle Abschnitte automatisch ausklappen */
(function () {
  if (!window.mw) return;
  if (mw.config.get('skin') !== 'minerva') return;
  function expandAll() {
    // 1) Alle Toggle-Buttons, die noch "zu" sind, anklicken
    document.querySelectorAll('button.section-toggle[aria-expanded="false"], [data-event-name="section-toggle"][aria-expanded="false"]').forEach(function (btn) {
      try { btn.click(); } catch(e) {}
    });
    // 2) Sicherheitsgurt: typische Inhalts-Container sichtbar erzwingen
    document.querySelectorAll('.collapsible-block, .mf-section-contents, .section-content').forEach(function (el) {
      el.style.display = 'block';
      el.hidden = false;
      el.classList.add('open-block');
      el.classList.remove('collapsed');
    });
  }
  // Beim Rendern und bei dynamischen Änderungen erneut ausführen
  function init() {
    expandAll();
    // Nochmal kurz nach Seitenaufbau und nach spätem JS
    setTimeout(expandAll, 50);
    setTimeout(expandAll, 400);
  }
  if (mw.loader && mw.loader.using) {
    mw.loader.using(['mobile.init']).always(function () {
      if (mw.hook) mw.hook('wikipage.content').add(init);
      init();
    });
  } else {
    document.addEventListener('DOMContentLoaded', init);
  }
})();
})();