equipe panel toggle en js

This commit is contained in:
2025-12-01 10:02:04 +01:00
parent 02231b8e17
commit cbc0053467
5 changed files with 204 additions and 51 deletions

View File

@@ -595,42 +595,120 @@ $(document).ready(function () {
////////////// start toggle page node projet //////////////////
// document.addEventListener('DOMContentLoaded', function () {
// const photo = document.querySelector('.field_field_equipe_photo');
// const pres = document.querySelector('.field_field_equipe_presentation');
// if (!pres) return;
// // Création du bouton
// const btn = document.createElement('button');
// btn.className = 'btn-equipe-toggle';
// btn.textContent = "EN SAVOIR PLUS SUR L'ÉQUIPE";
// btn.setAttribute('aria-expanded', false);
// // Insertion du bouton juste après le bloc présentation
// pres.insertAdjacentElement('afterend', btn);
// // 3. Ajout de la ligne après le bouton
// const separator = document.createElement('div');
// separator.className = 'equipe-separator';
// btn.insertAdjacentElement('afterend', separator);
// // Toggle
// btn.addEventListener('click', function () {
// const isOpen = pres.classList.toggle('is-open');
// if (photo) photo.classList.toggle('is-open');
// btn.textContent = isOpen
// ? "FERMER LA PRÉSENTATION DE L'ÉQUIPE"
// : "EN SAVOIR PLUS SUR L'ÉQUIPE";
// btn.setAttribute('aria-expanded', isOpen);
// });
// });
document.addEventListener('DOMContentLoaded', function () {
const photo = document.querySelector('.field_field_equipe_photo');
const pres = document.querySelector('.field_field_equipe_presentation');
if (!pres) return;
if (!photo || !pres) return;
// Création du bouton
// 1. Créer un wrapper autour de photo + présentation
const panel = document.createElement('div');
panel.className = 'equipe-panel';
// Insérer le panel avant la photo, puis y déplacer photo + pres
photo.parentNode.insertBefore(panel, photo);
panel.appendChild(photo);
panel.appendChild(pres);
// 2. Préparer le panel pour l'animation
panel.style.overflow = 'hidden';
panel.style.maxHeight = '0px';
// 3. Création du bouton
const btn = document.createElement('button');
btn.className = 'btn-equipe-toggle';
btn.textContent = "EN SAVOIR PLUS SUR L'ÉQUIPE";
btn.setAttribute('aria-expanded', false);
btn.setAttribute('aria-expanded', 'false');
// Insertion du bouton juste après le bloc présentation
pres.insertAdjacentElement('afterend', btn);
// Insertion du bouton juste après le panel (et plus après "pres")
panel.insertAdjacentElement('afterend', btn);
// 3. Ajout de la ligne après le bouton
const separator = document.createElement('div');
separator.className = 'equipe-separator';
btn.insertAdjacentElement('afterend', separator);
// Ligne de séparation après le bouton
const separator = document.createElement('div');
separator.className = 'equipe-separator';
btn.insertAdjacentElement('afterend', separator);
// Toggle
// --- Fonctions ouverture / fermeture ---
function openPanel() {
panel.classList.add('is-open');
photo.classList.add('is-open');
pres.classList.add('is-open');
const fullHeight = panel.scrollHeight; // inclut photo + texte
panel.style.maxHeight = fullHeight + 'px';
btn.textContent = "FERMER LA PRÉSENTATION DE L'ÉQUIPE";
btn.setAttribute('aria-expanded', 'true');
}
function closePanel() {
const fullHeight = panel.scrollHeight;
panel.style.maxHeight = fullHeight + 'px';
requestAnimationFrame(() => {
panel.style.maxHeight = '0px';
panel.classList.remove('is-open');
photo.classList.remove('is-open');
pres.classList.remove('is-open');
});
btn.textContent = "EN SAVOIR PLUS SUR L'ÉQUIPE";
btn.setAttribute('aria-expanded', 'false');
}
// --- Toggle bouton ---
btn.addEventListener('click', function () {
const isOpen = pres.classList.toggle('is-open');
if (photo) photo.classList.toggle('is-open');
btn.textContent = isOpen
? "FERMER LA PRÉSENTATION DE L'ÉQUIPE"
: "EN SAVOIR PLUS SUR L'ÉQUIPE";
btn.setAttribute('aria-expanded', isOpen);
const isOpen = btn.getAttribute('aria-expanded') === 'true';
if (isOpen) {
closePanel();
} else {
openPanel();
}
});
});
//////////////end toggle page node projet //////////////////

File diff suppressed because one or more lines are too long

View File

@@ -4469,16 +4469,14 @@ body {
font-family: "gilroy-light";
font-size: 0.6rem;
}
.node-type-projet .layout--threecol-25-50-25 .layout__region--second .block-region-second .field_field_equipe_photo,
.node-type-projet .layout--threecol-25-50-25 .layout__region--second .block-region-second .field_field_equipe_presentation {
.node-type-projet .layout--threecol-25-50-25 .layout__region--second .block-region-second .equipe-panel {
overflow: hidden;
max-height: 0;
opacity: 0;
margin-top: 1rem;
transition: max-height 1s ease, opacity 0.8s ease;
}
.node-type-projet .layout--threecol-25-50-25 .layout__region--second .block-region-second .field_field_equipe_photo.is-open,
.node-type-projet .layout--threecol-25-50-25 .layout__region--second .block-region-second .field_field_equipe_presentation.is-open {
max-height: 1500px;
.node-type-projet .layout--threecol-25-50-25 .layout__region--second .block-region-second .equipe-panel.is-open {
opacity: 1;
}
.node-type-projet .layout--threecol-25-50-25 .layout__region--second .block-region-second .btn-equipe-toggle {
@@ -4492,7 +4490,6 @@ body {
margin: auto;
display: flex;
border: none;
margin-top: 1rem;
margin-bottom: 1rem;
}
.node-type-projet .layout--threecol-25-50-25 .layout__region--second .block-region-second .btn-equipe-toggle svg {

View File

@@ -537,42 +537,120 @@ $(document).ready(function () {
////////////// start toggle page node projet //////////////////
// document.addEventListener('DOMContentLoaded', function () {
// const photo = document.querySelector('.field_field_equipe_photo');
// const pres = document.querySelector('.field_field_equipe_presentation');
// if (!pres) return;
// // Création du bouton
// const btn = document.createElement('button');
// btn.className = 'btn-equipe-toggle';
// btn.textContent = "EN SAVOIR PLUS SUR L'ÉQUIPE";
// btn.setAttribute('aria-expanded', false);
// // Insertion du bouton juste après le bloc présentation
// pres.insertAdjacentElement('afterend', btn);
// // 3. Ajout de la ligne après le bouton
// const separator = document.createElement('div');
// separator.className = 'equipe-separator';
// btn.insertAdjacentElement('afterend', separator);
// // Toggle
// btn.addEventListener('click', function () {
// const isOpen = pres.classList.toggle('is-open');
// if (photo) photo.classList.toggle('is-open');
// btn.textContent = isOpen
// ? "FERMER LA PRÉSENTATION DE L'ÉQUIPE"
// : "EN SAVOIR PLUS SUR L'ÉQUIPE";
// btn.setAttribute('aria-expanded', isOpen);
// });
// });
document.addEventListener('DOMContentLoaded', function () {
const photo = document.querySelector('.field_field_equipe_photo');
const pres = document.querySelector('.field_field_equipe_presentation');
if (!pres) return;
if (!photo || !pres) return;
// Création du bouton
// 1. Créer un wrapper autour de photo + présentation
const panel = document.createElement('div');
panel.className = 'equipe-panel';
// Insérer le panel avant la photo, puis y déplacer photo + pres
photo.parentNode.insertBefore(panel, photo);
panel.appendChild(photo);
panel.appendChild(pres);
// 2. Préparer le panel pour l'animation
panel.style.overflow = 'hidden';
panel.style.maxHeight = '0px';
// 3. Création du bouton
const btn = document.createElement('button');
btn.className = 'btn-equipe-toggle';
btn.textContent = "EN SAVOIR PLUS SUR L'ÉQUIPE";
btn.setAttribute('aria-expanded', false);
btn.setAttribute('aria-expanded', 'false');
// Insertion du bouton juste après le bloc présentation
pres.insertAdjacentElement('afterend', btn);
// Insertion du bouton juste après le panel (et plus après "pres")
panel.insertAdjacentElement('afterend', btn);
// 3. Ajout de la ligne après le bouton
const separator = document.createElement('div');
separator.className = 'equipe-separator';
btn.insertAdjacentElement('afterend', separator);
// Ligne de séparation après le bouton
const separator = document.createElement('div');
separator.className = 'equipe-separator';
btn.insertAdjacentElement('afterend', separator);
// Toggle
// --- Fonctions ouverture / fermeture ---
function openPanel() {
panel.classList.add('is-open');
photo.classList.add('is-open');
pres.classList.add('is-open');
const fullHeight = panel.scrollHeight; // inclut photo + texte
panel.style.maxHeight = fullHeight + 'px';
btn.textContent = "FERMER LA PRÉSENTATION DE L'ÉQUIPE";
btn.setAttribute('aria-expanded', 'true');
}
function closePanel() {
const fullHeight = panel.scrollHeight;
panel.style.maxHeight = fullHeight + 'px';
requestAnimationFrame(() => {
panel.style.maxHeight = '0px';
panel.classList.remove('is-open');
photo.classList.remove('is-open');
pres.classList.remove('is-open');
});
btn.textContent = "EN SAVOIR PLUS SUR L'ÉQUIPE";
btn.setAttribute('aria-expanded', 'false');
}
// --- Toggle bouton ---
btn.addEventListener('click', function () {
const isOpen = pres.classList.toggle('is-open');
if (photo) photo.classList.toggle('is-open');
btn.textContent = isOpen
? "FERMER LA PRÉSENTATION DE L'ÉQUIPE"
: "EN SAVOIR PLUS SUR L'ÉQUIPE";
btn.setAttribute('aria-expanded', isOpen);
const isOpen = btn.getAttribute('aria-expanded') === 'true';
if (isOpen) {
closePanel();
} else {
openPanel();
}
});
});
//////////////end toggle page node projet //////////////////

View File

@@ -195,20 +195,20 @@
font-size: 0.6rem;
}
}
.field_field_equipe_photo,
.field_field_equipe_presentation {
.equipe-panel {
overflow: hidden;
max-height: 0;
opacity: 0;
margin-top: 1rem;
transition:
max-height 1s ease,
opacity 0.8s ease;
}
.field_field_equipe_photo.is-open,
.field_field_equipe_presentation.is-open {
max-height: 1500px;
.equipe-panel.is-open {
// max-height: 1500px;
opacity: 1;
}
.btn-equipe-toggle{
@@ -222,7 +222,7 @@
margin: auto;
display: flex;
border: none;
margin-top: 1rem;
// margin-top: 1rem;
svg{
display: none;