f
This commit is contained in:
parent
87d45b61d9
commit
f3ba93f252
|
|
@ -130,36 +130,6 @@
|
|||
|
||||
<script>
|
||||
document.addEventListener('DOMContentLoaded', function() {
|
||||
// Utilitaire : récupérer ou créer l'instance Collapse sans toggle auto
|
||||
function getCollapseInstance(el) {
|
||||
return bootstrap.Collapse.getInstance(el) || new bootstrap.Collapse(el, { toggle: false });
|
||||
}
|
||||
|
||||
// Synchroniser les icônes une fois l'animation terminée
|
||||
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');
|
||||
});
|
||||
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');
|
||||
});
|
||||
|
||||
// Tes callbacks open/close sécurisés
|
||||
collapse.addEventListener('show.bs.collapse', function () {
|
||||
const fnName = this.dataset.openFn;
|
||||
try { if (fnName && typeof window[fnName] === 'function') window[fnName](); } catch(e) { /* no-op */ }
|
||||
});
|
||||
collapse.addEventListener('hide.bs.collapse', function () {
|
||||
const fnName = this.dataset.closeFn;
|
||||
try { if (fnName && typeof window[fnName] === 'function') window[fnName](); } catch(e) { /* no-op */ }
|
||||
});
|
||||
});
|
||||
|
||||
// Toggle explicite au clic, même avec data-bs-parent
|
||||
document.querySelectorAll('.accordion-button').forEach(btn => {
|
||||
btn.addEventListener('click', function(e) {
|
||||
const targetSel = this.getAttribute('data-bs-target') || this.dataset.bsTarget;
|
||||
|
|
@ -167,16 +137,15 @@ document.addEventListener('DOMContentLoaded', function() {
|
|||
if (!target) return;
|
||||
|
||||
e.preventDefault(); // on prend la main
|
||||
const isOpen = target.classList.contains('show');
|
||||
const instance = bootstrap.Collapse.getInstance(target)
|
||||
|| new bootstrap.Collapse(target, { toggle: false });
|
||||
|
||||
console.log('Click', targetSel, 'isOpen:', isOpen);
|
||||
|
||||
// Déclare instance UNE seule fois
|
||||
const instance = getCollapseInstance(target);
|
||||
|
||||
if (isOpen) {
|
||||
// Toggle explicite
|
||||
if (target.classList.contains('show')) {
|
||||
console.log('Click', targetSel, '=> fermeture');
|
||||
instance.hide();
|
||||
} else {
|
||||
console.log('Click', targetSel, '=> ouverture');
|
||||
instance.show();
|
||||
}
|
||||
});
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user