// Script Partage document.getElementById('shareButton').addEventListener('click', async () => { if (navigator.share) { try { await navigator.share({ title: document.title, text: 'Retrouvez tous les liens et événements de Vélo Boom Boom !', url: window.location.href }); } catch (err) { console.log('Partage annulé ou erreur:', err); } } else { try { await navigator.clipboard.writeText(window.location.href); alert('Lien copié dans le presse-papier !'); } catch (err) { console.error('Impossible de copier le lien:', err); } } }); // Script Galerie avec Carrousel Modal const modal = document.getElementById('imageModal'); const modalImg = document.getElementById('modalImage'); const galleryGrid = document.querySelector('.gallery-grid'); const prevBtn = document.getElementById('prevBtn'); const nextBtn = document.getElementById('nextBtn'); let images = []; let currentIndex = 0; if (galleryGrid && modal && modalImg) { images = Array.from(galleryGrid.querySelectorAll('img')); const updateModalImage = (index) => { currentIndex = index; modalImg.src = images[currentIndex].dataset.full; }; galleryGrid.addEventListener('click', (e) => { if (e.target.tagName === 'IMG') { const index = images.indexOf(e.target); updateModalImage(index); // Aligne la modale sur le scroll vertical actuel modal.style.top = window.scrollY + 'px'; modal.setAttribute('style', 'display: flex !important; top: ' + window.scrollY + 'px;'); document.body.style.overflow = 'hidden'; } }); prevBtn.addEventListener('click', (e) => { e.stopPropagation(); let newIndex = currentIndex - 1; if (newIndex < 0) newIndex = images.length - 1; updateModalImage(newIndex); }); nextBtn.addEventListener('click', (e) => { e.stopPropagation(); let newIndex = currentIndex + 1; if (newIndex >= images.length) newIndex = 0; updateModalImage(newIndex); }); // OPTIMISATION : Fermeture uniquement lors du clic sur le fond sombre (et non sur l'image elle-même) modal.addEventListener('click', (e) => { if (e.target === modal || e.target.id === 'imageModal') { modal.style.display = 'none'; modal.removeAttribute('style'); document.body.style.overflow = ''; } }); // OPTIMISATION : Gestion du balayage (Swipe) sur écran tactile let touchStartX = 0; let touchEndX = 0; modal.addEventListener('touchstart', (e) => { touchStartX = e.changedTouches[0].screenX; }, { passive: true }); modal.addEventListener('touchend', (e) => { touchEndX = e.changedTouches[0].screenX; const swipeDistance = touchStartX - touchEndX; if (swipeDistance > 50) { nextBtn.click(); // Glissement vers la gauche -> Image suivante } else if (swipeDistance < -50) { prevBtn.click(); // Glissement vers la droite -> Image précédente } }, { passive: true }); document.addEventListener('keydown', (e) => { if (modal.style.display === 'flex' || modal.style.getPropertyValue('display') === 'flex') { if (e.key === 'ArrowLeft') prevBtn.click(); if (e.key === 'ArrowRight') nextBtn.click(); if (e.key === 'Escape') { modal.style.display = 'none'; document.body.style.overflow = ''; } } }); }