MediaWiki:Common.js: Unterschied zwischen den Versionen
Erscheinungsbild
Gerard (Diskussion | Beiträge) Keine Bearbeitungszusammenfassung |
Gerard (Diskussion | Beiträge) Keine Bearbeitungszusammenfassung |
||
| Zeile 39: | Zeile 39: | ||
}); | }); | ||
}); | |||
/* Sidebar-Zustände speichern und wiederherstellen (Vector-2022) */ | |||
mw.hook('wikipage.content').add(function () { | |||
const sections = document.querySelectorAll('.vector-menu'); | |||
sections.forEach(section => { | |||
const heading = section.querySelector('.vector-menu-heading'); | |||
if (!heading) return; | |||
const id = section.id; | |||
const key = 'sidebar-state-' + id; | |||
// Zustand wiederherstellen | |||
const saved = localStorage.getItem(key); | |||
if (saved === 'collapsed') { | |||
section.classList.add('vector-menu-collapsed'); | |||
} | |||
// Klick-Event zum Speichern | |||
heading.addEventListener('click', () => { | |||
const isCollapsed = section.classList.contains('vector-menu-collapsed'); | |||
localStorage.setItem(key, isCollapsed ? 'collapsed' : 'expanded'); | |||
}); | |||
}); | |||
}); | }); | ||
Version vom 25. Mai 2026, 13:49 Uhr
/* ============================================================
Sidebar einklappbar – Vector‑2011 + Vector‑2022
============================================================ */
$(document).ready(function() {
/* Vector‑2022 */
$('.mw-portlet .vector-menu-heading').each(function() {
const heading = $(this);
// Vector‑2022: Inhalt liegt in .vector-menu-content-list
const content = heading.closest('.mw-portlet').find('.vector-menu-content-list');
if (content.length) {
heading.css('cursor', 'pointer');
heading.on('click', function(e) {
e.preventDefault();
e.stopPropagation();
content.slideToggle(200);
heading.toggleClass('collapsed');
});
}
});
/* Vector‑2011 */
$('.mw-portlet h3').each(function() {
const heading = $(this);
const content = heading.next('.body');
if (content.length) {
heading.css('cursor', 'pointer');
heading.on('click', function() {
content.slideToggle(200);
heading.toggleClass('collapsed');
});
}
});
});
/* Sidebar-Zustände speichern und wiederherstellen (Vector-2022) */
mw.hook('wikipage.content').add(function () {
const sections = document.querySelectorAll('.vector-menu');
sections.forEach(section => {
const heading = section.querySelector('.vector-menu-heading');
if (!heading) return;
const id = section.id;
const key = 'sidebar-state-' + id;
// Zustand wiederherstellen
const saved = localStorage.getItem(key);
if (saved === 'collapsed') {
section.classList.add('vector-menu-collapsed');
}
// Klick-Event zum Speichern
heading.addEventListener('click', () => {
const isCollapsed = section.classList.contains('vector-menu-collapsed');
localStorage.setItem(key, isCollapsed ? 'collapsed' : 'expanded');
});
});
});