This commit is contained in:
KONE SOREL 2026-01-12 15:22:30 +00:00
parent fdcff1a6ac
commit aa0821ab1c

View File

@ -130,17 +130,19 @@
<script>
document.addEventListener('DOMContentLoaded', function() {
function getCollapseInstance(el) {
return bootstrap.Collapse.getInstance(el) || new bootstrap.Collapse(el, { toggle: false });
}
document.querySelectorAll('.accordion-button').forEach(btn => {
btn.addEventListener('click', function(e) {
const targetSel = this.getAttribute('data-bs-target') || this.dataset.bsTarget;
const target = document.querySelector(targetSel);
if (!target) return;
e.preventDefault(); // on prend la main
const instance = bootstrap.Collapse.getInstance(target)
|| new bootstrap.Collapse(target, { toggle: false });
e.preventDefault();
const instance = getCollapseInstance(target);
// Toggle explicite : si ouvert => fermer, sinon => ouvrir
if (target.classList.contains('collapsing') || target.classList.contains('show')) {
console.log('Click', targetSel, '=> fermeture');
instance.hide();
@ -150,5 +152,26 @@ document.addEventListener('DOMContentLoaded', function() {
}
});
});
// Gestion des icônes et callbacks
document.querySelectorAll('.accordion-collapse').forEach(collapse => {
collapse.addEventListener('shown.bs.collapse', function () {
const btn = document.querySelector('[data-bs-target="#' + this.id + '"]');
const icon = btn?.querySelector('.accordion-icon');
if (icon) icon.classList.replace('bi-chevron-down', 'bi-chevron-up');
const fnName = this.dataset.openFn;
if (fnName && typeof window[fnName] === 'function') window[fnName]();
});
collapse.addEventListener('hidden.bs.collapse', function () {
const btn = document.querySelector('[data-bs-target="#' + this.id + '"]');
const icon = btn?.querySelector('.accordion-icon');
if (icon) icon.classList.replace('bi-chevron-up', 'bi-chevron-down');
const fnName = this.dataset.closeFn;
if (fnName && typeof window[fnName] === 'function') window[fnName]();
});
});
});
</script>