Aktionen

Benutzer

Benutzer:Theo/common.js

Aus exmediawiki

Hinweis: Leere nach dem Veröffentlichen den Browser-Cache, um die Änderungen sehen zu können.

  • Firefox/Safari: Umschalttaste drücken und gleichzeitig Aktualisieren anklicken oder entweder Strg+F5 oder Strg+R (⌘+R auf dem Mac) drücken
  • Google Chrome: Umschalttaste+Strg+R (⌘+Umschalttaste+R auf dem Mac) drücken
  • Edge: Strg+F5 drücken oder Strg drücken und gleichzeitig Aktualisieren anklicken
// Wait for MediaWiki to finish loading
mw.hook('wikipage.content').add(function($content) {
  // Function to initialize the collapsible behavior
  function initializeCollapsibles() {
    const toggleButtons = document.querySelectorAll('.toggle-button');
    const contentSections = document.querySelectorAll('.content-section');
    let currentlyOpen = null;

    // Remove any existing listeners to avoid duplicates
    toggleButtons.forEach(function(button) {
      button.removeEventListener('click', button.clickHandler);
    });

    toggleButtons.forEach(function(button) {
      button.clickHandler = function() {
        const targetId = this.getAttribute('data-target');
        const targetContent = document.getElementById(targetId);
        
        console.log('Button clicked:', targetId); // Debug log
        console.log('Target content found:', targetContent); // Debug log
        
        if (!targetContent) {
          console.log('Target content not found!');
          return;
        }
        
        // If clicking the same button that's already open, close it
        if (currentlyOpen === targetId) {
          targetContent.style.display = 'none';
          currentlyOpen = null;
          console.log('Closed:', targetId);
          return;
        }
        
        // Hide all content sections
        contentSections.forEach(function(section) {
          section.style.display = 'none';
        });
        
        // Show the target content
        targetContent.style.display = 'block';
        currentlyOpen = targetId;
        console.log('Opened:', targetId);
      };
      
      button.addEventListener('click', button.clickHandler);
    });
    
    console.log('Found', toggleButtons.length, 'toggle buttons');
    console.log('Found', contentSections.length, 'content sections');
  }

  // Initialize immediately
  initializeCollapsibles();
  
  // Also initialize after a short delay to catch any late-loading content
  setTimeout(initializeCollapsibles, 1000);
});

// Fallback for non-MediaWiki environments
document.addEventListener('DOMContentLoaded', function() {
  // Wait a bit more for MediaWiki processing
  setTimeout(function() {
    const toggleButtons = document.querySelectorAll('.toggle-button');
    if (toggleButtons.length > 0) {
      console.log('Fallback initialization');
      // Same initialization code as above
      // ... (you can copy the initializeCollapsibles function content here if needed)
    }
  }, 2000);
});