fr
This commit is contained in:
parent
aa0821ab1c
commit
d8fd488e83
|
|
@ -130,47 +130,37 @@
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
document.addEventListener('DOMContentLoaded', function() {
|
document.addEventListener('DOMContentLoaded', function() {
|
||||||
function getCollapseInstance(el) {
|
|
||||||
return bootstrap.Collapse.getInstance(el) || new bootstrap.Collapse(el, { toggle: false });
|
// 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 => {
|
||||||
document.querySelectorAll('.accordion-button').forEach(btn => {
|
|
||||||
btn.addEventListener('click', function(e) {
|
// Événement déclenché au début de l'ouverture
|
||||||
const targetSel = this.getAttribute('data-bs-target') || this.dataset.bsTarget;
|
collapseEl.addEventListener('show.bs.collapse', function () {
|
||||||
const target = document.querySelector(targetSel);
|
// Changer l'icône en "Haut"
|
||||||
if (!target) return;
|
const btn = document.querySelector(`[data-bs-target="#${this.id}"]`);
|
||||||
|
|
||||||
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 + '"]');
|
|
||||||
const icon = btn?.querySelector('.accordion-icon');
|
const icon = btn?.querySelector('.accordion-icon');
|
||||||
if (icon) icon.classList.replace('bi-chevron-down', 'bi-chevron-up');
|
if (icon) icon.classList.replace('bi-chevron-down', 'bi-chevron-up');
|
||||||
|
|
||||||
|
// Appeler la fonction de chargement (ex: charger_contrats)
|
||||||
const fnName = this.dataset.openFn;
|
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 () {
|
// Événement déclenché au début de la fermeture
|
||||||
const btn = document.querySelector('[data-bs-target="#' + this.id + '"]');
|
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');
|
const icon = btn?.querySelector('.accordion-icon');
|
||||||
if (icon) icon.classList.replace('bi-chevron-up', 'bi-chevron-down');
|
if (icon) icon.classList.replace('bi-chevron-up', 'bi-chevron-down');
|
||||||
|
|
||||||
|
// Appeler la fonction de reset (ex: reset_contrats)
|
||||||
const fnName = this.dataset.closeFn;
|
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