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: | ||
// Wait for MediaWiki to finish loading | |||
// | mw.hook('wikipage.content').add(function($content) { | ||
const toggleButtons = document.querySelectorAll('.toggle-button'); | // 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); | |||
}); | }); | ||
Version vom 26. Mai 2025, 13:39 Uhr
// 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);
});