|
|
| (20 dazwischenliegende Versionen desselben Benutzers werden nicht angezeigt) |
| Zeile 1: |
Zeile 1: |
| /** | | /* Minerva: Alle Abschnitte automatisch ausklappen */ |
| * Mobile: Alle Abschnitte automatisch ausklappen (Minerva/MobileFrontend)
| |
| * Datei: MediaWiki:Mobile.js
| |
| */
| |
| (function () { | | (function () { |
| // Nur im Minerva (mobile) Skin laufen lassen | | if (!window.mw) return; |
| var skin = mw.config.get('skin'); | | if (mw.config.get('skin') !== 'minerva') return; |
| if (skin !== 'minerva') return;
| |
|
| |
|
| function expandAllSectionsOnce() { | | function expandAll() { |
| var didSomething = false;
| | // 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) { |
| // 1) Variante A: Über ARIA-Attribute (stabiler, versionsunabhängig) | | try { btn.click(); } catch(e) {} |
| // Buttons/Headings, die Inhalte steuern und noch zugeklappt sind
| |
| document.querySelectorAll('[aria-controls][aria-expanded="false"]').forEach(function (btn) { | |
| var id = btn.getAttribute('aria-controls');
| |
| var panel = id && document.getElementById(id);
| |
| if (panel) {
| |
| btn.setAttribute('aria-expanded', 'true');
| |
| // Häufige Klassen, die das Zuklappen steuern, entfernen
| |
| btn.classList.remove('collapsed', 'mf-collapsible-button--collapsed');
| |
| panel.classList.remove('collapsed', 'mf-collapsible-content--collapsed', 'mf-collapsible--collapsed');
| |
| panel.style.display = ''; // falls per inline-style versteckt
| |
| didSomething = true;
| |
| }
| |
| });
| |
| | |
| // 2) Variante B: Falls MobileFrontend eigene Section-Headings nutzt
| |
| // (z. B. .section-heading[aria-expanded], .collapsible-header, etc.)
| |
| document.querySelectorAll('.section-heading, .collapsible-header, .mf-section-heading').forEach(function (heading) {
| |
| var expanded = heading.getAttribute('aria-expanded'); | |
| if (expanded === 'false') {
| |
| // Am sichersten: Klick simulieren, damit interne Logik läuft
| |
| heading.click();
| |
| didSomething = true;
| |
| }
| |
| // Zusätzliche Absicherung
| |
| heading.setAttribute('aria-expanded', 'true');
| |
| heading.classList.remove('collapsed');
| |
| }); | | }); |
|
| |
|
| // 3) Bekannte Content-Container sichtbar schalten | | // 2) Sicherheitsgurt: typische Inhalts-Container sichtbar erzwingen |
| document.querySelectorAll( | | document.querySelectorAll('.collapsible-block, .mf-section-contents, .section-content').forEach(function (el) { |
| '.section-content, .content, .collapsible-block, .mf-collapsible-content'
| | el.style.display = 'block'; |
| ).forEach(function (el) {
| | el.hidden = false; |
| // Nur wenn der Container direkt nach einer Heading-Struktur kommt oder collapsible ist | | el.classList.add('open-block'); |
| if (
| | el.classList.remove('collapsed'); |
| el.previousElementSibling &&
| |
| /section|collapsible|heading/i.test(el.previousElementSibling.className + '')
| |
| ) { | |
| el.style.display = '';
| |
| el.classList.remove('collapsed', 'mf-collapsible-content--collapsed');
| |
| }
| |
| }); | | }); |
|
| |
| return didSomething;
| |
| } | | } |
|
| |
|
| function expandWithRetries() { | | // Beim Rendern und bei dynamischen Änderungen erneut ausführen |
| // Sofort versuchen… | | function init() { |
| var changed = expandAllSectionsOnce();
| | expandAll(); |
| // …und noch ein paar Mal nachlegen, falls MF/JS später bootet oder Lazy-Transforms kommen | | // Nochmal kurz nach Seitenaufbau und nach spätem JS |
| var tries = 0; | | setTimeout(expandAll, 50); |
| var maxTries = 10;
| | setTimeout(expandAll, 400); |
| var interval = setInterval(function () {
| |
| tries++;
| |
| var did = expandAllSectionsOnce();
| |
| if (tries >= maxTries || (!did && tries > 2)) {
| |
| clearInterval(interval);
| |
| }
| |
| }, 300);
| |
| } | | } |
|
| |
|
| // Wenn MobileFrontend-Hooks vorhanden sind, darauf warten
| | if (mw.loader && mw.loader.using) { |
| if (mw.hook) { | | mw.loader.using(['mobile.init']).always(function () { |
| // Häufiger Hook, wenn die mobile Seite „bereit“ ist | | if (mw.hook) mw.hook('wikipage.content').add(init); |
| mw.hook('mobileFrontend.pageReady').add(expandWithRetries);
| | init(); |
| }
| | }); |
| | |
| // Fallback: nach DOMContentLoaded
| |
| if (document.readyState === 'loading') {
| |
| document.addEventListener('DOMContentLoaded', expandWithRetries); | |
| } else { | | } else { |
| expandWithRetries(); | | document.addEventListener('DOMContentLoaded', init); |
| } | | } |
| })(); | | })(); |