Zum Inhalt springen

MediaWiki:Common.js: Unterschied zwischen den Versionen

Aus TerranianStar
Keine Bearbeitungszusammenfassung
Keine Bearbeitungszusammenfassung
Zeile 69: Zeile 69:
});
});


/* Sidebar sofort schließen, bevor Vector sie öffnet */
/* Vector-2022: Alle Sidebar-Blöcke beim Laden zuverlässig schließen */
(function () {
(function () {
     const interval = setInterval(() => {
     const interval = setInterval(() => {
         const sections = document.querySelectorAll('#vector-sidebar .vector-menu');
         const headings = document.querySelectorAll('#vector-sidebar .vector-menu-heading');
        if (sections.length === 0) return;


         sections.forEach(section => {
         if (headings.length === 0) return;
             section.classList.add('vector-menu-collapsed');
 
        headings.forEach(h => {
             // Button finden, der das aria-expanded trägt
            const btn = h.querySelector('button');
            if (btn) {
                btn.setAttribute('aria-expanded', 'false');
            }
 
            // Optische Klasse setzen
            h.classList.add('collapsed');
 
            // Inhalt wirklich verstecken
            const content = h.nextElementSibling;
            if (content) {
                const list = content.querySelector('.vector-menu-content-list');
                if (list) {
                    list.style.display = 'none';
                }
            }
         });
         });


         clearInterval(interval);
         clearInterval(interval);
     }, 10);
     }, 20);
})();
})();

Version vom 25. Mai 2026, 14:05 Uhr

/* ============================================================
   Sidebar einklappbar – Vector‑2011 + Vector‑2022
   ============================================================ */

$(document).ready(function() {

    /* Vector‑2022 */
    $('.mw-portlet .vector-menu-heading').each(function() {
        const heading = $(this);

        // Vector‑2022: Inhalt liegt in .vector-menu-content-list
        const content = heading.closest('.mw-portlet').find('.vector-menu-content-list');

        if (content.length) {
            heading.css('cursor', 'pointer');

            heading.on('click', function(e) {
                e.preventDefault();
                e.stopPropagation();
                content.slideToggle(200);
                heading.toggleClass('collapsed');
            });
        }
    });

    /* Vector‑2011 */
    $('.mw-portlet h3').each(function() {
        const heading = $(this);
        const content = heading.next('.body');

        if (content.length) {
            heading.css('cursor', 'pointer');

            heading.on('click', function() {
                content.slideToggle(200);
                heading.toggleClass('collapsed');
            });
        }
    });

});

/* Sidebar-Zustände speichern und wiederherstellen (Vector-2022, MW 1.45.3) */
mw.loader.using('mediawiki.util').then(function () {
    document.addEventListener('DOMContentLoaded', function () {
        const sections = document.querySelectorAll('#vector-sidebar .vector-menu');

        sections.forEach(section => {
            const heading = section.querySelector('.vector-menu-heading');
            if (!heading || !section.id) return;

            const key = 'sidebar-state-' + section.id;

            // Zustand wiederherstellen
            const saved = localStorage.getItem(key);
            if (saved === 'collapsed') {
                section.classList.add('vector-menu-collapsed');
            }

            // Nach dem Klick speichern (nachdem Vector umgeschaltet hat)
            heading.addEventListener('click', () => {
                setTimeout(() => {
                    const isCollapsed = section.classList.contains('vector-menu-collapsed');
                    localStorage.setItem(key, isCollapsed ? 'collapsed' : 'expanded');
                }, 0);
            });
        });
    });
});

/* Vector-2022: Alle Sidebar-Blöcke beim Laden zuverlässig schließen */
(function () {
    const interval = setInterval(() => {
        const headings = document.querySelectorAll('#vector-sidebar .vector-menu-heading');

        if (headings.length === 0) return;

        headings.forEach(h => {
            // Button finden, der das aria-expanded trägt
            const btn = h.querySelector('button');
            if (btn) {
                btn.setAttribute('aria-expanded', 'false');
            }

            // Optische Klasse setzen
            h.classList.add('collapsed');

            // Inhalt wirklich verstecken
            const content = h.nextElementSibling;
            if (content) {
                const list = content.querySelector('.vector-menu-content-list');
                if (list) {
                    list.style.display = 'none';
                }
            }
        });

        clearInterval(interval);
    }, 20);
})();