diff --git a/wwwroot/app.js b/wwwroot/app.js index 94c34b0..e30ba76 100644 --- a/wwwroot/app.js +++ b/wwwroot/app.js @@ -128,7 +128,7 @@ function renderVotes() { const footer = document.createElement("div"); footer.className = "vote-controls"; footer.innerHTML = ` - + ${current}`; li.querySelector(".card-body").appendChild(footer); list.appendChild(li); @@ -263,8 +263,11 @@ function buildCard(s, { showAuthor }) { const card = document.createElement("article"); card.className = "game-card"; const hasImage = !!s.screenshotUrl; + const visual = hasImage + ? `` + : `
`; card.innerHTML = ` -
+ ${visual}

${s.name}

@@ -275,9 +278,31 @@ function buildCard(s, { showAuthor }) { ${s.youtubeUrl ? `YouTube ↗` : ""}
`; + if (hasImage) { + const btn = card.querySelector(".card-visual"); + btn.addEventListener("click", () => openLightbox(s.screenshotUrl, s.name)); + } return card; } +function openLightbox(url, title) { + const overlay = document.createElement("div"); + overlay.className = "lightbox"; + overlay.innerHTML = ` + + `; + overlay.addEventListener("click", (e) => { + if (e.target.classList.contains("lightbox") || e.target.classList.contains("lightbox-close")) { + overlay.remove(); + } + }); + document.body.appendChild(overlay); +} + async function main() { setupHandlers(); try { diff --git a/wwwroot/index.html b/wwwroot/index.html index c4af251..82576ce 100644 --- a/wwwroot/index.html +++ b/wwwroot/index.html @@ -16,7 +16,7 @@