Aktionen

Benutzer

Theo/common.js: Unterschied zwischen den Versionen

Aus exmediawiki

Theo (Diskussion | Beiträge)
Keine Bearbeitungszusammenfassung
Theo (Diskussion | Beiträge)
Keine Bearbeitungszusammenfassung
Zeile 1: Zeile 1:
document.addEventListener('DOMContentLoaded', function() {
console.log('User script loaded!');
  // Get all toggle buttons
  const toggleButtons = document.querySelectorAll('.toggle-button');
  const contentSections = document.querySelectorAll('.content-section');
  let currentlyOpen = null;


  toggleButtons.forEach(function(button) {
mw.hook('wikipage.content').add(function() {
    button.addEventListener('click', function() {
  console.log('Page content loaded!');
      const targetId = this.getAttribute('data-target');
 
      const targetContent = document.getElementById(targetId);
  // Simple test - add click event to all elements with toggle-button class
     
  document.querySelectorAll('.toggle-button').forEach(function(btn, index) {
      // If clicking the same button that's already open, close it
    console.log('Found toggle button', index);
      if (currentlyOpen === targetId) {
    btn.addEventListener('click', function() {
        targetContent.style.display = 'none';
       alert('Button ' + index + ' clicked!');
        currentlyOpen = null;
        return;
      }
     
      // Hide all content sections
      contentSections.forEach(function(section) {
        section.style.display = 'none';
      });
     
      // Show the target content
      targetContent.style.display = 'block';
       currentlyOpen = targetId;
     });
     });
   });
   });
});
});

Version vom 26. Mai 2025, 13:42 Uhr

console.log('User script loaded!');

mw.hook('wikipage.content').add(function() {
  console.log('Page content loaded!');
  
  // Simple test - add click event to all elements with toggle-button class
  document.querySelectorAll('.toggle-button').forEach(function(btn, index) {
    console.log('Found toggle button', index);
    btn.addEventListener('click', function() {
      alert('Button ' + index + ' clicked!');
    });
  });
});