Add a message when downloading to make people think more about mentionning LENS and photographer
This commit is contained in:
parent
4eed7b6876
commit
50921c82ab
8 changed files with 314 additions and 235 deletions
|
|
@ -2,9 +2,54 @@
|
|||
// 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
|
||||
}
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue