MediaWiki:Common.js: Unterschied zwischen den Versionen

Aus Lost Dreams Of Tomorrow Wiki
Keine Bearbeitungszusammenfassung
Markierung: Manuelle Zurücksetzung
Keine Bearbeitungszusammenfassung
Zeile 6: Zeile 6:
      
      
     function initSidebar() {
     function initSidebar() {
        // Suche nach DEINEN Custom Portlets (Players, World, etc.)
         var portlets = document.querySelectorAll('#p-Players, #p-World, #p-Items_and_Gear, #p-Guides, #p-Community');
         var portlets = document.querySelectorAll('#p-Players, #p-World, #p-Items_and_Gear, #p-Guides, #p-Community');
          
          
         console.log('Gefundene Portlets:', portlets.length); // Debug
         console.log('Gefundene Portlets:', portlets.length);
          
          
         portlets.forEach(function(portlet) {
         portlets.forEach(function(portlet) {
Zeile 19: Zeile 18:
             }
             }
              
              
             console.log('Initialisiere:', header.textContent); // Debug
            // WICHTIG: Prüfe ob bereits initialisiert
            if (header.hasAttribute('data-toggle-ready')) {
                console.log('Bereits initialisiert:', header.textContent);
                return;
            }
           
             console.log('Initialisiere:', header.textContent);
           
            // Markiere als initialisiert
            header.setAttribute('data-toggle-ready', 'true');
              
              
             // Füge Icon hinzu (RECHTS vom Title)
             // Füge Icon hinzu
             if (!header.querySelector('.toggle-icon')) {
             if (!header.querySelector('.toggle-icon')) {
                 var icon = document.createElement('span');
                 var icon = document.createElement('span');
Zeile 33: Zeile 41:
             }
             }
              
              
            // Cursor
             header.style.cursor = 'pointer';
             header.style.cursor = 'pointer';
             header.style.userSelect = 'none';
             header.style.userSelect = 'none';
              
              
             // Initial Status - DEFAULT OFFEN
             // Initial Status - DEFAULT OFFEN
             var isOpen = !header.classList.contains('closed'); // Umgekehrt: nur "closed" klappt zu
             var isOpen = !header.classList.contains('closed');
             if (!isOpen) {
             if (!isOpen) {
                 portletBody.style.display = 'none';
                 portletBody.style.display = 'none';
Zeile 45: Zeile 52:
             }
             }
              
              
             // Click Event
             // Click Event - NUR EINMAL!
             header.addEventListener('click', function(e) {
             header.addEventListener('click', function(e) {
                 e.preventDefault();
                 e.preventDefault();
                 e.stopPropagation(); // Verhindere Event-Bubbling
                 e.stopPropagation();
                console.log('KLICK!'); // Debug
                  
                  
                 var icon = this.querySelector('.toggle-icon');
                 var icon = this.querySelector('.toggle-icon');
Zeile 65: Zeile 71:
                     console.log('Geschlossen');
                     console.log('Geschlossen');
                 }
                 }
             });
             }, { once: false }); // Explicitly set once to false
         });
         });
     }
     }
      
      
    // Warte bis DOM geladen ist
     if (document.readyState === 'loading') {
     if (document.readyState === 'loading') {
         document.addEventListener('DOMContentLoaded', initSidebar);
         document.addEventListener('DOMContentLoaded', initSidebar);
Zeile 86: Zeile 91:
         const tabs = document.querySelectorAll('.tab-button');
         const tabs = document.querySelectorAll('.tab-button');
         const grids = document.querySelectorAll('.landing-grid');
         const grids = document.querySelectorAll('.landing-grid');
       
        console.log('Tabs gefunden:', tabs.length); // Debug
        console.log('Grids gefunden:', grids.length); // Debug
          
          
         if (tabs.length === 0 || grids.length === 0) {
         if (tabs.length === 0 || grids.length === 0) {
            console.log('Landing Features nicht gefunden - warte...');
             return;
             return;
         }
         }
          
          
         tabs.forEach(tab => {
         tabs.forEach(tab => {
            // Verhindere doppelte Initialisierung
            if (tab.hasAttribute('data-tab-ready')) {
                return;
            }
            tab.setAttribute('data-tab-ready', 'true');
           
             tab.addEventListener('click', function() {
             tab.addEventListener('click', function() {
                console.log('Tab geklickt:', this.dataset.tab); // Debug
               
                // Remove active from all tabs
                 tabs.forEach(t => t.classList.remove('active'));
                 tabs.forEach(t => t.classList.remove('active'));
                 this.classList.add('active');
                 this.classList.add('active');
                  
                  
                // Hide all grids
                 grids.forEach(g => g.classList.remove('active'));
                 grids.forEach(g => g.classList.remove('active'));
                  
                  
                // Show selected grid
                 const targetGrid = document.getElementById(this.dataset.tab);
                 const targetGrid = document.getElementById(this.dataset.tab);
                 if (targetGrid) {
                 if (targetGrid) {
                     targetGrid.classList.add('active');
                     targetGrid.classList.add('active');
                    console.log('Grid aktiviert:', this.dataset.tab);
                } else {
                    console.log('Grid nicht gefunden:', this.dataset.tab);
                 }
                 }
             });
             });
         });
         });
       
        console.log('Landing Tabs initialisiert!');
     }
     }
      
      
    // Mehrfache Versuche, den Code zu laden
     if (document.readyState === 'loading') {
     if (document.readyState === 'loading') {
         document.addEventListener('DOMContentLoaded', initLandingTabs);
         document.addEventListener('DOMContentLoaded', initLandingTabs);
Zeile 127: Zeile 123:
     }
     }
      
      
    // Zusätzlicher Versuch nach 500ms (falls MediaWiki später lädt)
     setTimeout(initLandingTabs, 500);
     setTimeout(initLandingTabs, 500);
   
})();
})();


// Collapsible Sidebar Sections - Mobile
// Collapsible Sidebar Sections - Mobile
$(document).ready(function() {
if (typeof jQuery !== 'undefined') {
    // Toggle für collapsible sections
    $(document).ready(function() {
    $('.sidebar-collapsible, h3[style*="cursor: pointer"]').click(function(e) {
        // NUR wenn noch nicht initialisiert
        e.preventDefault();
        if (!$('body').hasAttribute('data-jquery-sidebar-ready')) {
        $(this).toggleClass('closed');
            $('body').attr('data-jquery-sidebar-ready', 'true');
        $(this).next('.mw-portlet-body, ul').slideToggle(200);
           
            $('.sidebar-collapsible, h3[style*="cursor: pointer"]').click(function(e) {
                e.preventDefault();
                $(this).toggleClass('closed');
                $(this).next('.mw-portlet-body, ul').slideToggle(200);
            });
           
            if (window.innerWidth <= 850) {
                $('#mw-sidebar-checkbox:checked ~ .mw-sidebar').on('click', function(e) {
                    if (e.target === this) {
                        $('#mw-sidebar-checkbox').prop('checked', false);
                    }
                });
            }
        }
     });
     });
   
}
    // Schließe Sidebar beim Klick außerhalb (Mobile)
    if (window.innerWidth <= 850) {
        $('#mw-sidebar-checkbox:checked ~ .mw-sidebar').on('click', function(e) {
            if (e.target === this) {
                $('#mw-sidebar-checkbox').prop('checked', false);
            }
        });
    }
});

Version vom 12. Januar 2026, 00:27 Uhr

// MediaWiki Sidebar Toggle Script - Vanilla JS (Sichere Version)
/*------------------------Sidebar Toggle Script ------------------------------------------*/

(function() {
    'use strict';
    
    function initSidebar() {
        var portlets = document.querySelectorAll('#p-Players, #p-World, #p-Items_and_Gear, #p-Guides, #p-Community');
        
        console.log('Gefundene Portlets:', portlets.length);
        
        portlets.forEach(function(portlet) {
            var header = portlet.querySelector('h3');
            var portletBody = portlet.querySelector('.mw-portlet-body');
            
            if (!header || !portletBody) {
                return;
            }
            
            // WICHTIG: Prüfe ob bereits initialisiert
            if (header.hasAttribute('data-toggle-ready')) {
                console.log('Bereits initialisiert:', header.textContent);
                return;
            }
            
            console.log('Initialisiere:', header.textContent);
            
            // Markiere als initialisiert
            header.setAttribute('data-toggle-ready', 'true');
            
            // Füge Icon hinzu
            if (!header.querySelector('.toggle-icon')) {
                var icon = document.createElement('span');
                icon.className = 'toggle-icon';
                icon.innerHTML = '<svg xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><polyline points="6 9 12 15 18 9"></polyline></svg>';
                icon.style.marginLeft = '8px';
                icon.style.display = 'inline-block';
                icon.style.transition = 'transform 0.2s ease';
                icon.style.verticalAlign = 'middle';
                header.appendChild(icon);
            }
            
            header.style.cursor = 'pointer';
            header.style.userSelect = 'none';
            
            // Initial Status - DEFAULT OFFEN
            var isOpen = !header.classList.contains('closed');
            if (!isOpen) {
                portletBody.style.display = 'none';
                var icon = header.querySelector('.toggle-icon');
                icon.style.transform = 'rotate(-90deg)';
            }
            
            // Click Event - NUR EINMAL!
            header.addEventListener('click', function(e) {
                e.preventDefault();
                e.stopPropagation();
                
                var icon = this.querySelector('.toggle-icon');
                var body = portlet.querySelector('.mw-portlet-body');
                
                if (body.style.display === 'none') {
                    body.style.display = 'block';
                    icon.style.transform = 'rotate(0deg)';
                    this.classList.add('open');
                    console.log('Geöffnet');
                } else {
                    body.style.display = 'none';
                    icon.style.transform = 'rotate(-90deg)';
                    this.classList.remove('open');
                    console.log('Geschlossen');
                }
            }, { once: false }); // Explicitly set once to false
        });
    }
    
    if (document.readyState === 'loading') {
        document.addEventListener('DOMContentLoaded', initSidebar);
    } else {
        initSidebar();
    }
})();


/*------------------------Landing Features------------------------------------------*/

(function() {
    'use strict';
    
    function initLandingTabs() {
        const tabs = document.querySelectorAll('.tab-button');
        const grids = document.querySelectorAll('.landing-grid');
        
        if (tabs.length === 0 || grids.length === 0) {
            return;
        }
        
        tabs.forEach(tab => {
            // Verhindere doppelte Initialisierung
            if (tab.hasAttribute('data-tab-ready')) {
                return;
            }
            tab.setAttribute('data-tab-ready', 'true');
            
            tab.addEventListener('click', function() {
                tabs.forEach(t => t.classList.remove('active'));
                this.classList.add('active');
                
                grids.forEach(g => g.classList.remove('active'));
                
                const targetGrid = document.getElementById(this.dataset.tab);
                if (targetGrid) {
                    targetGrid.classList.add('active');
                }
            });
        });
    }
    
    if (document.readyState === 'loading') {
        document.addEventListener('DOMContentLoaded', initLandingTabs);
    } else {
        initLandingTabs();
    }
    
    setTimeout(initLandingTabs, 500);
})();

// Collapsible Sidebar Sections - Mobile
if (typeof jQuery !== 'undefined') {
    $(document).ready(function() {
        // NUR wenn noch nicht initialisiert
        if (!$('body').hasAttribute('data-jquery-sidebar-ready')) {
            $('body').attr('data-jquery-sidebar-ready', 'true');
            
            $('.sidebar-collapsible, h3[style*="cursor: pointer"]').click(function(e) {
                e.preventDefault();
                $(this).toggleClass('closed');
                $(this).next('.mw-portlet-body, ul').slideToggle(200);
            });
            
            if (window.innerWidth <= 850) {
                $('#mw-sidebar-checkbox:checked ~ .mw-sidebar').on('click', function(e) {
                    if (e.target === this) {
                        $('#mw-sidebar-checkbox').prop('checked', false);
                    }
                });
            }
        }
    });
}