photo26/photologue/static/gallery_detail.js

55 lines
2.2 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],
customSlideName: true,
licenseKey: '94ED9732-30284A12-B88B0137-4FF9CEE6',
});
//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 LENS 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
}
});