From d3ced6cd703bb1149051fe3262f09a3d1abd61d0 Mon Sep 17 00:00:00 2001 From: ivar Date: Wed, 8 Oct 2025 10:29:40 +0200 Subject: n --- VegaData/wwwroot/index.js | 37 +++++++++++++++++++++++++++---------- 1 file changed, 27 insertions(+), 10 deletions(-) (limited to 'VegaData/wwwroot/index.js') diff --git a/VegaData/wwwroot/index.js b/VegaData/wwwroot/index.js index ec27f4d..cad938d 100644 --- a/VegaData/wwwroot/index.js +++ b/VegaData/wwwroot/index.js @@ -42,22 +42,24 @@ function dateString(date, small = false) { }); } -function copyLink(e) { +function copyLink(t, e) { + const initialInnerText = t.target.innerText; if ("clipboard" in navigator) { navigator.clipboard.writeText(`${location.origin}/index.html#${urlId(e)}`) + t.target.innerText = `${initialInnerText} ✓` + setTimeout(() => { + t.target.innerText = initialInnerText + }, 1000) } } function vegascene(e) { - if (e.movieVersion.startsWith("KUL")) return `https://www.vegascene.no/teater/${e.movieVersion}` - return `https://www.vegascene.no/film/${e.movieVersion}` + if (e.movieMainVersion.startsWith("KUL")) return `https://www.vegascene.no/teater/${e.movieMainVersion}` + return `https://www.vegascene.no/film/${e.movieMainVersion}` } -if (gqp("q")) search.value = gqp("q") -search.addEventListener("input", e => renderShows(e.currentTarget.value)); - function urlId(e) { - return encodeURIComponent(`${e.movieVersion}-${e.startDateTime}`) + return `${e.movieVersion}${e.startDateTime}`.replaceAll("-", "").replaceAll(" ", "").replaceAll(":", "") } async function renderShows(query = search.value) { @@ -101,7 +103,8 @@ async function renderShows(query = search.value) { t("ul", undefined, [ t("li", undefined, times.filter(e => e.ticketUrl !== "").map(e => { - const tagLine = `${e.scene} - ${[e.type, ...e.tags].join(", ")}` + let tagLine = `${e.scene} - ${[e.type, ...e.tags].join(", ")}` + tagLine = tagLine[0].toUpperCase() + tagLine.slice(1) return t("li", { class: `time time-${e.id}`, id: urlId(e) }, [ t("div", undefined, [ t("span", { title: e.startDateTime }, dateString(e.startDateTime)), @@ -109,7 +112,7 @@ async function renderShows(query = search.value) { t("div", { class: "actions" }, [ t("a", { href: e.ticketUrl }, "Billetter"), "share" in navigator ? t("button", { onclick: () => share(e) }, "Del tid") : null, - t("button", { onclick: () => copyLink(e) }, "Kopier lenke"), + t("button", { onclick: (t) => copyLink(t, e) }, "Kopier lenke"), t("a", { href: vegascene(e) }, "Åpne på vegascene.no") ]) ]) @@ -122,6 +125,20 @@ async function renderShows(query = search.value) { if (!lis.length) ulShows.replaceChildren(...[t("i", undefined, "Dessverre")]) else ulShows.replaceChildren(...lis); + } -renderShows(); +document.addEventListener("DOMContentLoaded", () => { + if (gqp("q")) search.value = gqp("q") + search.addEventListener("input", e => renderShows(e.currentTarget.value)); + renderShows(); + const id = location.href.indexOf("#") !== -1 ? location.href.substring(location.href.indexOf("#")) : "" + document.querySelectorAll(".time").forEach(el => el.classList.remove("activeShow")) + if (id !== "") { + setTimeout(() => { + const target = document.querySelector(id) + target.scrollIntoView({ behavior: "smooth", block: "center" }) + target.classList.add("activeShow") + }, 50) + } +}) -- cgit v1.3