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 | ||
(function() { | |||
'use strict'; | |||
var | 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 ( | 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(); | |||
} | |||
})(); | |||
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();
}
})();