my_gallery/js/gallery.js
2026-02-21 17:48:12 +01:00

40 lines
1 KiB
JavaScript

// ===============================
// RENDER GALLERIA
// ===============================
function renderGallery(photos) {
const gallery = document.getElementById('gallery');
gallery.innerHTML = '';
photos.forEach(photo => {
const thumbDiv = document.createElement('div');
thumbDiv.className = 'thumb';
const img = document.createElement('img');
img.src = `https://prova.patachina.it/${photo.thub1}`;
img.alt = photo.name || '';
img.loading = "lazy";
thumbDiv.appendChild(img);
if (photo.mime_type.startsWith("video/")) {
const play = document.createElement("div");
play.className = "play-icon";
play.textContent = "▶";
thumbDiv.appendChild(play);
}
const preview = photo.thub2
? `https://prova.patachina.it/${photo.thub2}`
: `https://prova.patachina.it/${photo.thub1}`;
thumbDiv.addEventListener('click', () => {
openModal(
`https://prova.patachina.it/${photo.path}`,
preview,
photo
);
});
gallery.appendChild(thumbDiv);
});
}