// This file is part of photo21 // Copyright (C) 2022 Amicale des élèves de l'ENS Paris-Saclay // SPDX-License-Identifier: GPL-3.0-or-later // Init gallery const lgInstance = lightGallery(document.getElementById('lightgallery'), { selector: 'a.photo-item', plugins: [lgAdmin, lgHash, lgThumbnail, lgZoom, lgVideo], autoplayFirstVideo: true, autoplayVideoOnSlide: true, gotoNextSlideOnVideoEnd: false, download: true, customSlideName: true, licenseKey: '94ED9732-30284A12-B88B0137-4FF9CEE6', appendDownloadAttributesToAnchor: true, // Crucial pour le mobile mobileSettings: { controls: true, showCloseIcon: true, download: true // On force l'activation ici aussi } }); //Add download warning code const lgContainer = document.getElementById('lightgallery'); // Change photo with a two-finger horizontal swipe on a trackpad. Without this the // browser reads the gesture as "go back" and leaves the gallery. const SWIPE_DISTANCE = 80; // horizontal pixels before switching photo const SWIPE_COOLDOWN = 400; // ms, so the inertia of one swipe moves one photo const SWIPE_GAP = 200; // ms of quiet that starts a new gesture let swipeOuter = null; let swipeAmount = 0; let swipeLastWheel = 0; let swipeLastMove = 0; function onTrackpadSwipe(e) { // Leave vertical scrolling, and zoomed in photos, alone. if (Math.abs(e.deltaX) <= Math.abs(e.deltaY)) return; e.preventDefault(); if (swipeOuter.classList.contains('lg-zoomed')) return; const now = performance.now(); if (now - swipeLastWheel > SWIPE_GAP) swipeAmount = 0; swipeLastWheel = now; if (now - swipeLastMove < SWIPE_COOLDOWN) return; swipeAmount += e.deltaX; if (Math.abs(swipeAmount) < SWIPE_DISTANCE) return; if (swipeAmount > 0) lgInstance.goToNextSlide(); else lgInstance.goToPrevSlide(); swipeAmount = 0; swipeLastMove = now; } lgContainer.addEventListener('lgAfterOpen', () => { swipeOuter = document.querySelector('.lg-outer'); swipeAmount = 0; swipeOuter.addEventListener('wheel', onTrackpadSwipe, { passive: false }); }); // On attend que la galerie soit ouverte pour cibler le bouton lgContainer.addEventListener('lgAfterOpen', () => { const downloadBtn = document.querySelector('.lg-download'); if (downloadBtn) { downloadBtn.addEventListener('click', function(e) { // On stoppe l'action par défaut du navigateur e.preventDefault(); e.stopImmediatePropagation(); const downloadUrl = this.getAttribute('href'); // // Affichage de la modale stylisée // Swal.fire({ // title: gettext('Download'), // text: gettext("This image is free to download, but permission from the photographer and the people in the photo is required before republishing it on another website. Furthermore, it is good practice to credit L[ENS] and the photographers in any republications."), // icon: 'info', // showCancelButton: true, // confirmButtonColor: '#3085d6', // cancelButtonColor: '#d33', // confirmButtonText: gettext('Download'), // cancelButtonText: gettext('Cancel'), // background: '#1a1a1a', // Optionnel : pour matcher le thème sombre de LightGallery // color: '#fff' // }).then((result) => { // if (result.isConfirmed) { // Si validé, on déclenche le téléchargement const link = document.createElement('a'); link.href = downloadUrl; link.download = ''; // Force le téléchargement document.body.appendChild(link); link.click(); document.body.removeChild(link); // } // }); }, true); // Utilisation du mode capture pour intercepter avant le script interne } }); //disable downloading with the context menue lgContainer.addEventListener('lgAfterOpen', () => { // On cible le conteneur de la galerie qui vient de s'afficher const lgOuter = document.querySelector('.lg-outer'); lgOuter.addEventListener('contextmenu', (e) => { e.preventDefault(); }, false); });