photo26/photologue/static/gallery_detail.js
2026-03-05 17:32:06 +01:00

73 lines
2.8 KiB
JavaScript

// 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
lightGallery(document.getElementById('lightgallery'), {
plugins: [lgAdmin, lgHash, lgThumbnail, lgZoom],
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');
// 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);
});