za
This commit is contained in:
parent
fdcff1a6ac
commit
aa0821ab1c
|
|
@ -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>
|
||||
Loading…
Reference in New Issue
Block a user