// =============================== // CONFIG // =============================== const API_URL = 'https://prova.patachina.it/photos'; let photosData = []; let currentPhoto = null; // =============================== // DEBUG INIZIALE // =============================== console.log("app.js caricato correttamente"); // =============================== // FETCH DELLE FOTO // =============================== async function loadPhotos() { console.log("Inizio fetch:", API_URL); let res; try { res = await fetch(API_URL); } catch (e) { console.error("Errore fetch:", e); return; } console.log("Status fetch:", res.status); const text = await res.text(); console.log("Risposta grezza (prime 200 chars):", text.substring(0, 200)); try { photosData = JSON.parse(text); console.log("JSON parse OK, numero foto:", photosData.length); } catch (e) { console.error("Errore nel parse JSON:", e); return; } renderGallery(photosData); } // =============================== // RENDER GALLERIA // =============================== function renderGallery(photos) { console.log("Render gallery, foto:", photos.length); 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); // ICONA PLAY SE È VIDEO if (photo.mime_type.startsWith("video/")) { const play = document.createElement("div"); play.className = "play-icon"; play.textContent = "▶"; thumbDiv.appendChild(play); } // Fallback se thub2 manca 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); }); } // =============================== // MODALE (FOTO + VIDEO) // =============================== const modal = document.getElementById('modal'); const modalImg = document.getElementById('modalImage'); // NON USATO PIÙ const modalClose = document.getElementById('modalClose'); function openModal(srcOriginal, srcPreview, photo) { currentPhoto = photo; const container = document.getElementById("modalMediaContainer"); container.innerHTML = ""; // pulizia if (photo.mime_type.startsWith("video/")) { // VIDEO const video = document.createElement("video"); video.src = srcOriginal; video.controls = true; video.autoplay = true; video.style.maxWidth = "100%"; video.style.maxHeight = "100%"; container.appendChild(video); } else { // FOTO const img = document.createElement("img"); img.src = srcPreview; img.style.maxWidth = "100%"; img.style.maxHeight = "100%"; container.appendChild(img); const full = new Image(); full.src = srcOriginal; full.onload = () => { img.src = srcOriginal; }; } modal.classList.add('open'); } function closeModal() { modal.classList.remove('open'); document.getElementById("modalMediaContainer").innerHTML = ""; } modalClose.addEventListener('click', closeModal); modal.addEventListener('click', (e) => { if (e.target === modal) closeModal(); }); // =============================== // PANNELLO INFO + MAPPA // =============================== const infoPanel = document.getElementById('infoPanel'); const infoBtn = document.getElementById('modalInfoBtn'); infoBtn.addEventListener('click', () => { if (!currentPhoto) return; const gps = currentPhoto.gps || { lat: '-', lng: '-', alt: '-' }; const folder = currentPhoto.path.split('/').slice(2, -1).join('/'); infoPanel.innerHTML = `