fr
This commit is contained in:
parent
aa0821ab1c
commit
d8fd488e83
|
|
@ -130,47 +130,37 @@
|
|||
|
||||
<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();
|
||||
const instance = getCollapseInstance(target);
|
||||
|
||||
if (target.classList.contains('collapsing') || target.classList.contains('show')) {
|
||||
console.log('Click', targetSel, '=> fermeture');
|
||||
instance.hide();
|
||||
} else {
|
||||
console.log('Click', targetSel, '=> ouverture');
|
||||
instance.show();
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
// 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 + '"]');
|
||||
|
||||
// 1. On ne touche pas au clic (Bootstrap s'en occupe via data-bs-toggle)
|
||||
// On gère uniquement ce qui doit se passer AU MOMENT de l'ouverture
|
||||
document.querySelectorAll('.accordion-collapse').forEach(collapseEl => {
|
||||
|
||||
// Événement déclenché au début de l'ouverture
|
||||
collapseEl.addEventListener('show.bs.collapse', function () {
|
||||
// Changer l'icône en "Haut"
|
||||
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');
|
||||
|
||||
|
||||
// Appeler la fonction de chargement (ex: charger_contrats)
|
||||
const fnName = this.dataset.openFn;
|
||||
if (fnName && typeof window[fnName] === 'function') window[fnName]();
|
||||
if (fnName && typeof window[fnName] === 'function') {
|
||||
window[fnName]();
|
||||
}
|
||||
});
|
||||
|
||||
collapse.addEventListener('hidden.bs.collapse', function () {
|
||||
const btn = document.querySelector('[data-bs-target="#' + this.id + '"]');
|
||||
// Événement déclenché au début de la fermeture
|
||||
collapseEl.addEventListener('hide.bs.collapse', function () {
|
||||
// Changer l'icône en "Bas"
|
||||
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');
|
||||
|
||||
|
||||
// Appeler la fonction de reset (ex: reset_contrats)
|
||||
const fnName = this.dataset.closeFn;
|
||||
if (fnName && typeof window[fnName] === 'function') window[fnName]();
|
||||
if (fnName && typeof window[fnName] === 'function') {
|
||||
window[fnName]();
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user