MediaWiki:Common.js: Unterschied zwischen den Versionen

Aus Lost Dreams Of Tomorrow Wiki
Keine Bearbeitungszusammenfassung
Keine Bearbeitungszusammenfassung
Zeile 1: Zeile 1:
// MediaWiki Sidebar Toggle Script
// MediaWiki Sidebar Toggle Script - Vanilla JS
$(document).ready(function() {
(function() {
    // Finde alle sidebar-collapsible Überschriften
    'use strict';
    $('.sidebar-collapsible').each(function() {
   
         var $header = $(this);
    function initSidebar() {
        var $portletBody = $header.next('.mw-portlet-body');
        // Finde alle sidebar-collapsible Überschriften
         var headers = document.querySelectorAll('.sidebar-collapsible');
          
          
         // Füge ein Icon hinzu
         console.log('Gefundene Headers:', headers.length); // Debug
        if ($header.find('.toggle-icon').length === 0) {
            $header.prepend('<span class="toggle-icon">▼</span> ');
        }
          
          
         // Mache die Überschrift klickbar
         headers.forEach(function(header) {
        $header.css('cursor', 'pointer');
            var portletBody = header.nextElementSibling;
       
           
        // Überprüfe den initialen Status (open/closed Klasse)
            if (!portletBody || !portletBody.classList.contains('mw-portlet-body')) {
        if (!$header.hasClass('open')) {
                console.log('Kein portlet-body gefunden für:', header);
            $portletBody.hide();
                return;
            $header.find('.toggle-icon').text('');
            }
        }
           
       
            // Füge Icon hinzu
        // Click Event
            if (!header.querySelector('.toggle-icon')) {
        $header.on('click', function(e) {
                var icon = document.createElement('span');
             e.preventDefault();
                icon.className = 'toggle-icon';
                icon.textContent = '';
                header.insertBefore(icon, header.firstChild);
             }
              
              
             var $icon = $(this).find('.toggle-icon');
             // Cursor
            var $body = $(this).next('.mw-portlet-body');
            header.style.cursor = 'pointer';
              
              
             // Toggle
             // Initial Status
             if ($body.is(':visible')) {
             if (!header.classList.contains('open')) {
                 $body.slideUp(200);
                 portletBody.style.display = 'none';
                $icon.text('');
                 header.querySelector('.toggle-icon').textContent = '';
                 $(this).removeClass('open');
            } else {
                $body.slideDown(200);
                $icon.text('▼');
                $(this).addClass('open');
             }
             }
           
            // Click Event
            header.addEventListener('click', function(e) {
                e.preventDefault();
                console.log('Klick auf:', this); // Debug
               
                var icon = this.querySelector('.toggle-icon');
                var body = this.nextElementSibling;
               
                if (body.style.display === 'none') {
                    body.style.display = 'block';
                    icon.textContent = '▼ ';
                    this.classList.add('open');
                } else {
                    body.style.display = 'none';
                    icon.textContent = '▶ ';
                    this.classList.remove('open');
                }
            });
         });
         });
     });
     }
});
   
    // Warte bis DOM geladen ist
    if (document.readyState === 'loading') {
        document.addEventListener('DOMContentLoaded', initSidebar);
    } else {
        initSidebar();
    }
})();

Version vom 11. Januar 2026, 04:28 Uhr

// MediaWiki Sidebar Toggle Script - Vanilla JS
(function() {
    'use strict';
    
    function initSidebar() {
        // Finde alle sidebar-collapsible Überschriften
        var headers = document.querySelectorAll('.sidebar-collapsible');
        
        console.log('Gefundene Headers:', headers.length); // Debug
        
        headers.forEach(function(header) {
            var portletBody = header.nextElementSibling;
            
            if (!portletBody || !portletBody.classList.contains('mw-portlet-body')) {
                console.log('Kein portlet-body gefunden für:', header);
                return;
            }
            
            // Füge Icon hinzu
            if (!header.querySelector('.toggle-icon')) {
                var icon = document.createElement('span');
                icon.className = 'toggle-icon';
                icon.textContent = '▼ ';
                header.insertBefore(icon, header.firstChild);
            }
            
            // Cursor
            header.style.cursor = 'pointer';
            
            // Initial Status
            if (!header.classList.contains('open')) {
                portletBody.style.display = 'none';
                header.querySelector('.toggle-icon').textContent = '▶ ';
            }
            
            // Click Event
            header.addEventListener('click', function(e) {
                e.preventDefault();
                console.log('Klick auf:', this); // Debug
                
                var icon = this.querySelector('.toggle-icon');
                var body = this.nextElementSibling;
                
                if (body.style.display === 'none') {
                    body.style.display = 'block';
                    icon.textContent = '▼ ';
                    this.classList.add('open');
                } else {
                    body.style.display = 'none';
                    icon.textContent = '▶ ';
                    this.classList.remove('open');
                }
            });
        });
    }
    
    // Warte bis DOM geladen ist
    if (document.readyState === 'loading') {
        document.addEventListener('DOMContentLoaded', initSidebar);
    } else {
        initSidebar();
    }
})();