za
This commit is contained in:
parent
fdcff1a6ac
commit
aa0821ab1c
|
|
@ -130,17 +130,19 @@
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
document.addEventListener('DOMContentLoaded', function() {
|
document.addEventListener('DOMContentLoaded', function() {
|
||||||
|
function getCollapseInstance(el) {
|
||||||
|
return bootstrap.Collapse.getInstance(el) || new bootstrap.Collapse(el, { toggle: false });
|
||||||
|
}
|
||||||
|
|
||||||
document.querySelectorAll('.accordion-button').forEach(btn => {
|
document.querySelectorAll('.accordion-button').forEach(btn => {
|
||||||
btn.addEventListener('click', function(e) {
|
btn.addEventListener('click', function(e) {
|
||||||
const targetSel = this.getAttribute('data-bs-target') || this.dataset.bsTarget;
|
const targetSel = this.getAttribute('data-bs-target') || this.dataset.bsTarget;
|
||||||
const target = document.querySelector(targetSel);
|
const target = document.querySelector(targetSel);
|
||||||
if (!target) return;
|
if (!target) return;
|
||||||
|
|
||||||
e.preventDefault(); // on prend la main
|
e.preventDefault();
|
||||||
const instance = bootstrap.Collapse.getInstance(target)
|
const instance = getCollapseInstance(target);
|
||||||
|| new bootstrap.Collapse(target, { toggle: false });
|
|
||||||
|
|
||||||
// Toggle explicite : si ouvert => fermer, sinon => ouvrir
|
|
||||||
if (target.classList.contains('collapsing') || target.classList.contains('show')) {
|
if (target.classList.contains('collapsing') || target.classList.contains('show')) {
|
||||||
console.log('Click', targetSel, '=> fermeture');
|
console.log('Click', targetSel, '=> fermeture');
|
||||||
instance.hide();
|
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>
|
</script>
|
||||||
Loading…
Reference in New Issue
Block a user