feat(sidebar): replier en haut à droite de la recherche, accordéon exclusif
- Bouton replier : icône seule dans l'en-tête, gabarit du bouton recherche ; le pied garde version + fraîcheur + Sortir. - Une seule section ouverte à la fois (kanbante-nav-open), amorce serveur selon la page courante, plus de kanbante-nav-closed.
This commit is contained in:
+18
-31
@@ -43,46 +43,33 @@
|
||||
});
|
||||
}
|
||||
|
||||
/* Accordion sections: the closed set lives in body classes
|
||||
(applied pre-paint by the bootstrap script in _header.html)
|
||||
and is persisted here on every toggle. */
|
||||
/* Accordéon EXCLUSIF (0.22.0) : une seule section ouverte
|
||||
à la fois. Ouvrir une section ferme les autres ; cliquer
|
||||
la section ouverte la referme. L'état initial vient du
|
||||
script d'amorce de _header.html (section de la page
|
||||
courante ou choix mémorisé dans kanbante-nav-open). */
|
||||
var groupBtns = document.querySelectorAll('[data-group-btn]');
|
||||
function persistClosedGroups() {
|
||||
var closed = [];
|
||||
groupBtns.forEach(function (btn) {
|
||||
if (document.body.classList.contains('nav-closed-' + btn.getAttribute('data-group-btn'))) {
|
||||
closed.push(btn.getAttribute('data-group-btn'));
|
||||
}
|
||||
});
|
||||
try {
|
||||
localStorage.setItem('kanbante-nav-closed', JSON.stringify(closed));
|
||||
} catch (e) { /* non-fatal */ }
|
||||
}
|
||||
function syncGroupBtn(btn) {
|
||||
var closed = document.body.classList.contains(
|
||||
'nav-closed-' + btn.getAttribute('data-group-btn'));
|
||||
btn.setAttribute('aria-expanded', closed ? 'false' : 'true');
|
||||
}
|
||||
function setOpenGroup(openKey) {
|
||||
groupBtns.forEach(function (btn) {
|
||||
var key = btn.getAttribute('data-group-btn');
|
||||
document.body.classList.toggle('nav-closed-' + key, key !== openKey);
|
||||
syncGroupBtn(btn);
|
||||
});
|
||||
try {
|
||||
localStorage.setItem('kanbante-nav-open', openKey);
|
||||
} catch (e) { /* non-fatal */ }
|
||||
}
|
||||
groupBtns.forEach(function (btn) {
|
||||
syncGroupBtn(btn);
|
||||
btn.addEventListener('click', function () {
|
||||
document.body.classList.toggle(
|
||||
'nav-closed-' + btn.getAttribute('data-group-btn'));
|
||||
syncGroupBtn(btn);
|
||||
persistClosedGroups();
|
||||
var key = btn.getAttribute('data-group-btn');
|
||||
var isOpen = !document.body.classList.contains('nav-closed-' + key);
|
||||
setOpenGroup(isOpen ? '' : key);
|
||||
});
|
||||
});
|
||||
/* The section holding the current page is always opened. */
|
||||
var activeLink = document.querySelector('.sidebar .side-link.active');
|
||||
if (activeLink) {
|
||||
var section = activeLink.closest('.side-section');
|
||||
if (section) {
|
||||
var key = section.getAttribute('data-group');
|
||||
if (document.body.classList.contains('nav-closed-' + key)) {
|
||||
document.body.classList.remove('nav-closed-' + key);
|
||||
groupBtns.forEach(syncGroupBtn);
|
||||
persistClosedGroups();
|
||||
}
|
||||
}
|
||||
}
|
||||
})();
|
||||
|
||||
Reference in New Issue
Block a user