Single page view

This commit is contained in:
Simon Martens
2025-09-19 12:40:44 +02:00
parent 7b4e9498a0
commit 5bfba49101
5 changed files with 779 additions and 201 deletions

View File

@@ -1,39 +1,39 @@
const S = "script[xslt-onload]", w = "xslt-template", T = "xslt-transformed", f = /* @__PURE__ */ new Map();
function b() {
let n = htmx.findAll(S);
for (let t of n)
A(t);
const L = "script[xslt-onload]", w = "xslt-template", E = "xslt-transformed", y = /* @__PURE__ */ new Map();
function v() {
let i = htmx.findAll(L);
for (let t of i)
k(t);
}
function A(n) {
if (n.getAttribute(T) === "true" || !n.hasAttribute(w))
function k(i) {
if (i.getAttribute(E) === "true" || !i.hasAttribute(w))
return;
let t = "#" + n.getAttribute(w), e = f.get(t);
let t = "#" + i.getAttribute(w), e = y.get(t);
if (!e) {
let a = htmx.find(t);
if (a) {
let s = a.innerHTML ? new DOMParser().parseFromString(a.innerHTML, "application/xml") : a.contentDocument;
e = new XSLTProcessor(), e.importStylesheet(s), f.set(t, e);
e = new XSLTProcessor(), e.importStylesheet(s), y.set(t, e);
} else
throw new Error("Unknown XSLT template: " + t);
}
let o = new DOMParser().parseFromString(n.innerHTML, "application/xml"), i = e.transformToFragment(o, document), r = new XMLSerializer().serializeToString(i);
n.outerHTML = r;
let n = new DOMParser().parseFromString(i.innerHTML, "application/xml"), o = e.transformToFragment(n, document), r = new XMLSerializer().serializeToString(o);
i.outerHTML = r;
}
function L() {
function q() {
document.querySelectorAll("template[simple]").forEach((t) => {
let e = t.getAttribute("id"), o = t.content;
let e = t.getAttribute("id"), n = t.content;
customElements.define(
e,
class extends HTMLElement {
constructor() {
super(), this.appendChild(o.cloneNode(!0)), this.slots = this.querySelectorAll("slot");
super(), this.appendChild(n.cloneNode(!0)), this.slots = this.querySelectorAll("slot");
}
connectedCallback() {
let i = [];
let o = [];
this.slots.forEach((r) => {
let a = r.getAttribute("name"), s = this.querySelector(`[slot="${a}"]`);
s && (r.replaceWith(s.cloneNode(!0)), i.push(s));
}), i.forEach((r) => {
s && (r.replaceWith(s.cloneNode(!0)), o.push(s));
}), o.forEach((r) => {
r.remove();
});
}
@@ -48,61 +48,61 @@ window.pageObserver = window.pageObserver || null;
window.scrollTimeout = window.scrollTimeout || null;
function B() {
window.highlightObserver && (window.highlightObserver.disconnect(), window.highlightObserver = null);
const n = document.querySelectorAll(".newspaper-page-container");
const i = document.querySelectorAll(".newspaper-page-container");
window.highlightObserver = new IntersectionObserver(
(t) => {
x();
C();
},
{
rootMargin: "-20% 0px -70% 0px"
}
), n.forEach((t) => {
), i.forEach((t) => {
window.highlightObserver.observe(t);
});
}
function x() {
const n = [];
function C() {
const i = [];
document.querySelectorAll(".newspaper-page-container").forEach((e) => {
const o = e.getBoundingClientRect(), i = window.innerHeight, r = Math.max(o.top, 0), a = Math.min(o.bottom, i), s = Math.max(0, a - r), l = o.height, g = s / l >= 0.5, u = e.querySelector("img[data-page]"), m = u ? u.getAttribute("data-page") : "unknown";
g && u && m && !n.includes(m) && n.push(m);
}), q(n), n.length > 0 && E(n);
const n = e.getBoundingClientRect(), o = window.innerHeight, r = Math.max(n.top, 0), a = Math.min(n.bottom, o), s = Math.max(0, a - r), l = n.height, g = s / l >= 0.5, u = e.querySelector("img[data-page]"), f = u ? u.getAttribute("data-page") : "unknown";
g && u && f && !i.includes(f) && i.push(f);
}), M(i), i.length > 0 && I(i);
}
function q(n) {
function M(i) {
document.querySelectorAll(".continuation-entry").forEach((t) => {
t.style.display = "none";
}), n.forEach((t) => {
}), i.forEach((t) => {
const e = document.querySelector(`[data-page-container="${t}"]`);
e && e.querySelectorAll(".continuation-entry").forEach((i) => {
i.style.display = "";
e && e.querySelectorAll(".continuation-entry").forEach((o) => {
o.style.display = "";
});
}), k(n), M();
}), H(i), $();
}
function k(n) {
function H(i) {
document.querySelectorAll(".work-title").forEach((t) => {
const e = t.getAttribute("data-short-title");
e && (t.textContent = e);
}), n.forEach((t) => {
}), i.forEach((t) => {
const e = document.querySelector(`[data-page-container="${t}"]`);
e && e.querySelectorAll(".work-title").forEach((i) => {
const r = i.getAttribute("data-full-title");
r && r !== i.getAttribute("data-short-title") && (i.textContent = r);
e && e.querySelectorAll(".work-title").forEach((o) => {
const r = o.getAttribute("data-full-title");
r && r !== o.getAttribute("data-short-title") && (o.textContent = r);
});
});
}
function M() {
document.querySelectorAll(".page-entry").forEach((n) => {
const t = n.querySelectorAll(".inhalts-entry");
function $() {
document.querySelectorAll(".page-entry").forEach((i) => {
const t = i.querySelectorAll(".inhalts-entry");
let e = !1;
t.forEach((o) => {
window.getComputedStyle(o).display !== "none" && (e = !0);
}), e ? n.style.display = "" : n.style.display = "none";
t.forEach((n) => {
window.getComputedStyle(n).display !== "none" && (e = !0);
}), e ? i.style.display = "" : i.style.display = "none";
});
}
function C(n) {
E([n]);
function S(i) {
I([i]);
}
function E(n) {
console.log("markCurrentPagesInInhaltsverzeichnis called with:", n), document.querySelectorAll("[data-page-container]").forEach((e) => {
function I(i) {
console.log("markCurrentPagesInInhaltsverzeichnis called with:", i), document.querySelectorAll("[data-page-container]").forEach((e) => {
e.hasAttribute("data-beilage") ? (e.classList.remove("border-red-500"), e.classList.add("border-amber-400")) : (e.classList.remove("border-red-500"), e.classList.add("border-slate-300"));
}), document.querySelectorAll(".page-number-inhalts").forEach((e) => {
e.classList.remove("text-red-600", "font-bold"), e.classList.add("text-slate-700", "font-semibold"), e.style.textDecoration = "", e.style.pointerEvents = "", e.classList.contains("bg-blue-50") ? e.classList.add("hover:bg-blue-100") : e.classList.contains("bg-amber-50") && e.classList.add("hover:bg-amber-100"), !e.classList.contains("bg-amber-50") && !e.classList.contains("bg-blue-50") && e.classList.add("bg-blue-50");
@@ -112,62 +112,64 @@ function E(n) {
e.classList.remove("no-underline"), e.classList.contains("bg-blue-50") && e.classList.add("hover:bg-blue-100");
});
const t = [];
n.forEach((e) => {
const o = document.querySelector(
i.forEach((e) => {
const n = document.querySelector(
`.page-number-inhalts[data-page-number="${e}"]`
);
if (o) {
o.classList.remove(
if (n) {
n.classList.remove(
"text-slate-700",
"hover:bg-blue-100",
"hover:bg-amber-100"
), o.classList.add("text-red-600", "font-bold"), o.style.textDecoration = "none", o.style.pointerEvents = "none", t.push(o);
const i = document.querySelector(`[data-page-container="${e}"]`);
i && (i.classList.remove("border-slate-300", "border-amber-400"), i.classList.add("border-red-500"));
const r = o.closest(".page-entry");
), n.classList.add("text-red-600", "font-bold"), n.style.textDecoration = "none", n.style.pointerEvents = "none", t.push(n);
const o = document.querySelector(`[data-page-container="${e}"]`);
o && (o.classList.remove("border-slate-300", "border-amber-400"), o.classList.add("border-red-500"));
const r = n.closest(".page-entry");
r && (r.querySelectorAll(".inhalts-entry").forEach((s) => {
s.classList.remove("hover:bg-slate-100"), s.style.cursor = "default";
}), r.querySelectorAll('a[href*="/"]').forEach((s) => {
s.getAttribute("aria-current") === "page" && (s.style.textDecoration = "none", s.style.pointerEvents = "none", s.classList.add("no-underline"), s.classList.remove("hover:bg-blue-100"));
}));
}
}), t.length > 0 && H(t[0]), document.querySelectorAll(".page-indicator").forEach((e) => {
}), t.length > 0 && N(t[0]), document.querySelectorAll(".page-indicator").forEach((e) => {
e.classList.remove("text-red-600", "font-bold"), e.classList.add("text-slate-600", "font-semibold"), e.classList.contains("bg-amber-50") || e.classList.add("bg-blue-50");
}), n.forEach((e) => {
const o = document.querySelector(`.page-indicator[data-page="${e}"]`);
o && (o.classList.remove("text-slate-600"), o.classList.add("text-red-600", "font-bold"));
}), i.forEach((e) => {
const n = document.querySelector(`.page-indicator[data-page="${e}"]`);
n && (n.classList.remove("text-slate-600"), n.classList.add("text-red-600", "font-bold"));
});
}
function H(n) {
const t = n.closest(".lg\\:overflow-y-auto");
function N(i) {
const t = i.closest(".lg\\:overflow-y-auto");
if (t) {
const e = t.getBoundingClientRect(), o = n.getBoundingClientRect(), i = o.top < e.top, r = o.bottom > e.bottom;
(i || r) && n.scrollIntoView({
const e = t.getBoundingClientRect(), n = i.getBoundingClientRect(), o = n.top < e.top, r = n.bottom > e.bottom;
(o || r) && i.scrollIntoView({
behavior: "smooth",
block: "center"
});
}
}
function R(n, t, e) {
const o = document.getElementById("pageModal"), i = document.getElementById("modalImage");
i.src = n.src, i.alt = n.alt, o.classList.remove("hidden"), C(t);
function R(i, t, e) {
let n = document.querySelector("single-page-viewer");
n || (n = document.createElement("single-page-viewer"), document.body.appendChild(n));
const o = i.closest('[data-beilage="true"]') !== null;
n.show(i.src, i.alt, t, o);
}
function I() {
function T() {
document.getElementById("pageModal").classList.add("hidden");
}
function $() {
function O() {
if (window.pageObserver && (window.pageObserver.disconnect(), window.pageObserver = null), window.currentPageContainers = Array.from(
document.querySelectorAll(".newspaper-page-container")
), window.currentActiveIndex = 0, h(), document.querySelector(".newspaper-page-container")) {
), window.currentActiveIndex = 0, p(), document.querySelector(".newspaper-page-container")) {
let t = /* @__PURE__ */ new Set();
window.pageObserver = new IntersectionObserver(
(e) => {
if (e.forEach((o) => {
const i = window.currentPageContainers.indexOf(o.target);
i !== -1 && (o.isIntersecting ? t.add(i) : t.delete(i));
if (e.forEach((n) => {
const o = window.currentPageContainers.indexOf(n.target);
o !== -1 && (n.isIntersecting ? t.add(o) : t.delete(o));
}), t.size > 0) {
const i = Array.from(t).sort((r, a) => r - a)[0];
i !== window.currentActiveIndex && (window.currentActiveIndex = i, h());
const o = Array.from(t).sort((r, a) => r - a)[0];
o !== window.currentActiveIndex && (window.currentActiveIndex = o, p());
}
},
{
@@ -178,52 +180,52 @@ function $() {
});
}
}
function O() {
function V() {
if (window.currentActiveIndex > 0) {
let n = -1;
let i = -1;
const t = [];
window.currentPageContainers.forEach((o, i) => {
const r = o.getBoundingClientRect(), a = window.innerHeight, s = Math.max(r.top, 0), l = Math.min(r.bottom, a), d = Math.max(0, l - s), g = r.height;
d / g >= 0.3 && t.push(i);
window.currentPageContainers.forEach((n, o) => {
const r = n.getBoundingClientRect(), a = window.innerHeight, s = Math.max(r.top, 0), l = Math.min(r.bottom, a), c = Math.max(0, l - s), g = r.height;
c / g >= 0.3 && t.push(o);
});
const e = Math.min(...t);
for (let o = e - 1; o >= 0; o--)
if (!t.includes(o)) {
n = o;
for (let n = e - 1; n >= 0; n--)
if (!t.includes(n)) {
i = n;
break;
}
n === -1 && e > 0 && (n = e - 1), n >= 0 && (window.currentActiveIndex = n, window.currentPageContainers[window.currentActiveIndex].scrollIntoView({
i === -1 && e > 0 && (i = e - 1), i >= 0 && (window.currentActiveIndex = i, window.currentPageContainers[window.currentActiveIndex].scrollIntoView({
behavior: "smooth",
block: "start"
}), setTimeout(() => {
h();
p();
}, 100));
}
}
function K() {
if (window.currentActiveIndex < window.currentPageContainers.length - 1) {
let n = -1;
let i = -1;
const t = [];
window.currentPageContainers.forEach((o, i) => {
const r = o.getBoundingClientRect(), a = window.innerHeight, s = Math.max(r.top, 0), l = Math.min(r.bottom, a), d = Math.max(0, l - s), g = r.height;
d / g >= 0.3 && t.push(i);
window.currentPageContainers.forEach((n, o) => {
const r = n.getBoundingClientRect(), a = window.innerHeight, s = Math.max(r.top, 0), l = Math.min(r.bottom, a), c = Math.max(0, l - s), g = r.height;
c / g >= 0.3 && t.push(o);
});
const e = Math.max(...t);
for (let o = e + 1; o < window.currentPageContainers.length; o++)
if (!t.includes(o)) {
n = o;
for (let n = e + 1; n < window.currentPageContainers.length; n++)
if (!t.includes(n)) {
i = n;
break;
}
n === -1 && e < window.currentPageContainers.length - 1 && (n = e + 1), n >= 0 && n < window.currentPageContainers.length && (window.currentActiveIndex = n, window.currentPageContainers[window.currentActiveIndex].scrollIntoView({
i === -1 && e < window.currentPageContainers.length - 1 && (i = e + 1), i >= 0 && i < window.currentPageContainers.length && (window.currentActiveIndex = i, window.currentPageContainers[window.currentActiveIndex].scrollIntoView({
behavior: "smooth",
block: "start"
}), setTimeout(() => {
h();
p();
}, 100));
}
}
function V() {
if (P()) {
function z() {
if (A()) {
const t = document.querySelector("#newspaper-content .newspaper-page-container");
t && t.scrollIntoView({
behavior: "smooth",
@@ -237,87 +239,87 @@ function V() {
});
}
}
function P() {
const n = [];
function A() {
const i = [];
window.currentPageContainers.forEach((t, e) => {
const o = t.getBoundingClientRect(), i = window.innerHeight, r = Math.max(o.top, 0), a = Math.min(o.bottom, i), s = Math.max(0, a - r), l = o.height;
s / l >= 0.3 && n.push(e);
const n = t.getBoundingClientRect(), o = window.innerHeight, r = Math.max(n.top, 0), a = Math.min(n.bottom, o), s = Math.max(0, a - r), l = n.height;
s / l >= 0.3 && i.push(e);
});
for (const t of n) {
for (const t of i) {
const e = window.currentPageContainers[t];
if (e && e.id && e.id.includes("beilage-"))
return !0;
}
return !1;
}
function h() {
const n = document.getElementById("prevPageBtn"), t = document.getElementById("nextPageBtn"), e = document.getElementById("beilageBtn");
if (n && (window.currentActiveIndex <= 0 ? n.style.display = "none" : n.style.display = "flex"), t && (window.currentActiveIndex >= window.currentPageContainers.length - 1 ? t.style.display = "none" : t.style.display = "flex"), e) {
const o = P(), i = e.querySelector("i");
o ? (e.title = "Zur Hauptausgabe", e.className = "w-14 h-10 lg:w-16 lg:h-12 px-2 py-1 bg-gray-100 hover:bg-gray-200 text-gray-700 hover:text-gray-800 border border-gray-300 transition-colors duration-200 flex items-center justify-center cursor-pointer", i && (i.className = "ri-file-text-line text-lg lg:text-xl")) : (e.title = "Zu Beilage", e.className = "w-14 h-10 lg:w-16 lg:h-12 px-2 py-1 bg-amber-100 hover:bg-amber-200 text-amber-700 hover:text-amber-800 border border-amber-300 transition-colors duration-200 flex items-center justify-center cursor-pointer", i && (i.className = "ri-attachment-line text-lg lg:text-xl"));
function p() {
const i = document.getElementById("prevPageBtn"), t = document.getElementById("nextPageBtn"), e = document.getElementById("beilageBtn");
if (i && (window.currentActiveIndex <= 0 ? i.style.display = "none" : i.style.display = "flex"), t && (window.currentActiveIndex >= window.currentPageContainers.length - 1 ? t.style.display = "none" : t.style.display = "flex"), e) {
const n = A(), o = e.querySelector("i");
n ? (e.title = "Zur Hauptausgabe", e.className = "w-14 h-10 lg:w-16 lg:h-12 px-2 py-1 bg-gray-100 hover:bg-gray-200 text-gray-700 hover:text-gray-800 border border-gray-300 transition-colors duration-200 flex items-center justify-center cursor-pointer", o && (o.className = "ri-file-text-line text-lg lg:text-xl")) : (e.title = "Zu Beilage", e.className = "w-14 h-10 lg:w-16 lg:h-12 px-2 py-1 bg-amber-100 hover:bg-amber-200 text-amber-700 hover:text-amber-800 border border-amber-300 transition-colors duration-200 flex items-center justify-center cursor-pointer", o && (o.className = "ri-attachment-line text-lg lg:text-xl"));
}
}
function D() {
const n = document.getElementById("shareLinkBtn");
function j() {
const i = document.getElementById("shareLinkBtn");
let t = "";
if (window.currentActiveIndex !== void 0 && window.currentPageContainers && window.currentPageContainers[window.currentActiveIndex]) {
const i = window.currentPageContainers[window.currentActiveIndex].querySelector("[data-page]");
i && (t = `#page-${i.getAttribute("data-page")}`);
const o = window.currentPageContainers[window.currentActiveIndex].querySelector("[data-page]");
o && (t = `#page-${o.getAttribute("data-page")}`);
}
const e = window.location.origin + window.location.pathname + t;
navigator.share ? navigator.share({
title: document.title,
url: e
}).catch((o) => {
y(e, n);
}) : y(e, n);
}).catch((n) => {
x(e, i);
}) : x(e, i);
}
function y(n, t) {
function x(i, t) {
if (navigator.clipboard)
navigator.clipboard.writeText(n).then(() => {
c(t, "Link kopiert!");
navigator.clipboard.writeText(i).then(() => {
d(t, "Link kopiert!");
}).catch((e) => {
c(t, "Kopieren fehlgeschlagen");
d(t, "Kopieren fehlgeschlagen");
});
else {
const e = document.createElement("textarea");
e.value = n, document.body.appendChild(e), e.select();
e.value = i, document.body.appendChild(e), e.select();
try {
const o = document.execCommand("copy");
c(t, o ? "Link kopiert!" : "Kopieren fehlgeschlagen");
const n = document.execCommand("copy");
d(t, n ? "Link kopiert!" : "Kopieren fehlgeschlagen");
} catch {
c(t, "Kopieren fehlgeschlagen");
d(t, "Kopieren fehlgeschlagen");
} finally {
document.body.removeChild(e);
}
}
}
function Z() {
const n = document.getElementById("citationBtn"), t = document.title || "KGPZ", e = window.location.href, o = (/* @__PURE__ */ new Date()).toLocaleDateString("de-DE"), i = `Königsberger Gelehrte und Politische Zeitung (KGPZ). ${t}. Digital verfügbar unter: ${e} (Zugriff: ${o}).`;
function D() {
const i = document.getElementById("citationBtn"), t = document.title || "KGPZ", e = window.location.href, n = (/* @__PURE__ */ new Date()).toLocaleDateString("de-DE"), o = `Königsberger Gelehrte und Politische Zeitung (KGPZ). ${t}. Digital verfügbar unter: ${e} (Zugriff: ${n}).`;
if (navigator.clipboard)
navigator.clipboard.writeText(i).then(() => {
c(n, "Zitation kopiert!");
navigator.clipboard.writeText(o).then(() => {
d(i, "Zitation kopiert!");
}).catch((r) => {
c(n, "Kopieren fehlgeschlagen");
d(i, "Kopieren fehlgeschlagen");
});
else {
const r = document.createElement("textarea");
r.value = i, document.body.appendChild(r), r.select();
r.value = o, document.body.appendChild(r), r.select();
try {
const a = document.execCommand("copy");
c(n, a ? "Zitation kopiert!" : "Kopieren fehlgeschlagen");
d(i, a ? "Zitation kopiert!" : "Kopieren fehlgeschlagen");
} catch {
c(n, "Kopieren fehlgeschlagen");
d(i, "Kopieren fehlgeschlagen");
} finally {
document.body.removeChild(r);
}
}
}
function c(n, t) {
function d(i, t) {
const e = document.querySelector(".simple-popup");
e && e.remove();
const o = document.createElement("div");
o.className = "simple-popup", o.textContent = t, o.style.cssText = `
const n = document.createElement("div");
n.className = "simple-popup", n.textContent = t, n.style.cssText = `
position: fixed;
background: #374151;
color: white;
@@ -331,125 +333,319 @@ function c(n, t) {
transition: opacity 0.2s ease;
white-space: nowrap;
`;
const i = n.getBoundingClientRect(), r = window.innerHeight, a = window.innerWidth;
let s = i.left - 10, l = i.bottom + 8;
const d = 120, g = 32;
s + d > a && (s = i.right - d + 10), l + g > r && (l = i.top - g - 8), o.style.left = Math.max(5, s) + "px", o.style.top = Math.max(5, l) + "px", document.body.appendChild(o), setTimeout(() => {
o.style.opacity = "1";
const o = i.getBoundingClientRect(), r = window.innerHeight, a = window.innerWidth;
let s = o.left - 10, l = o.bottom + 8;
const c = 120, g = 32;
s + c > a && (s = o.right - c + 10), l + g > r && (l = o.top - g - 8), n.style.left = Math.max(5, s) + "px", n.style.top = Math.max(5, l) + "px", document.body.appendChild(n), setTimeout(() => {
n.style.opacity = "1";
}, 10), setTimeout(() => {
o.style.opacity = "0", setTimeout(() => {
o.parentNode && o.remove();
n.style.opacity = "0", setTimeout(() => {
n.parentNode && n.remove();
}, 200);
}, 2e3);
}
function v() {
const n = window.location.hash;
function P() {
const i = window.location.hash;
let t = "", e = null;
if (n.startsWith("#page-")) {
if (t = n.replace("#page-", ""), e = document.getElementById(`page-${t}`), !e) {
const o = document.querySelectorAll(".newspaper-page-container[data-pages]");
for (const i of o) {
const r = i.getAttribute("data-pages");
if (i.startsWith("#page-")) {
if (t = i.replace("#page-", ""), e = document.getElementById(`page-${t}`), !e) {
const n = document.querySelectorAll(".newspaper-page-container[data-pages]");
for (const o of n) {
const r = o.getAttribute("data-pages");
if (r && r.split(",").includes(t)) {
e = i;
e = o;
break;
}
}
}
e || (e = document.getElementById(`beilage-1-page-${t}`) || document.getElementById(`beilage-2-page-${t}`) || document.querySelector(`[id*="beilage"][id*="page-${t}"]`));
} else if (n.startsWith("#beilage-")) {
const o = n.match(/#beilage-(\d+)-page-(\d+)/);
if (o) {
const i = o[1];
t = o[2], e = document.getElementById(`beilage-${i}-page-${t}`);
} else if (i.startsWith("#beilage-")) {
const n = i.match(/#beilage-(\d+)-page-(\d+)/);
if (n) {
const o = n[1];
t = n[2], e = document.getElementById(`beilage-${o}-page-${t}`);
}
}
e && t && setTimeout(() => {
e.scrollIntoView({
behavior: "smooth",
block: "start"
}), C(t);
}), S(t);
}, 300);
}
function z(n, t, e = !1) {
let o = "";
e ? o = `#beilage-1-page-${n}` : o = `#page-${n}`;
const i = window.location.origin + window.location.pathname + o;
function b(i, t, e = !1) {
let n = "";
e ? n = `#beilage-1-page-${i}` : n = `#page-${i}`;
const o = window.location.origin + window.location.pathname + n;
if (navigator.clipboard)
navigator.clipboard.writeText(i).then(() => {
c(t, "Link kopiert!");
navigator.clipboard.writeText(o).then(() => {
d(t, "Link kopiert!");
}).catch((r) => {
c(t, "Kopieren fehlgeschlagen");
d(t, "Kopieren fehlgeschlagen");
});
else {
const r = document.createElement("textarea");
r.value = i, document.body.appendChild(r), r.select();
r.value = o, document.body.appendChild(r), r.select();
try {
const a = document.execCommand("copy");
c(t, a ? "Link kopiert!" : "Kopieren fehlgeschlagen");
d(t, a ? "Link kopiert!" : "Kopieren fehlgeschlagen");
} catch {
c(t, "Kopieren fehlgeschlagen");
d(t, "Kopieren fehlgeschlagen");
} finally {
document.body.removeChild(r);
}
}
}
function _(n, t) {
const e = document.title || "KGPZ", o = `${window.location.origin}${window.location.pathname}#page-${n}`, i = (/* @__PURE__ */ new Date()).toLocaleDateString("de-DE"), r = `Königsberger Gelehrte und Politische Zeitung (KGPZ). ${e}, Seite ${n}. Digital verfügbar unter: ${o} (Zugriff: ${i}).`;
function m(i, t) {
const e = document.title || "KGPZ", n = `${window.location.origin}${window.location.pathname}#page-${i}`, o = (/* @__PURE__ */ new Date()).toLocaleDateString("de-DE"), r = `Königsberger Gelehrte und Politische Zeitung (KGPZ). ${e}, Seite ${i}. Digital verfügbar unter: ${n} (Zugriff: ${o}).`;
if (navigator.clipboard)
navigator.clipboard.writeText(r).then(() => {
c(t, "Zitation kopiert!");
d(t, "Zitation kopiert!");
}).catch((a) => {
c(t, "Kopieren fehlgeschlagen");
d(t, "Kopieren fehlgeschlagen");
});
else {
const a = document.createElement("textarea");
a.value = r, document.body.appendChild(a), a.select();
try {
const s = document.execCommand("copy");
c(t, s ? "Zitation kopiert!" : "Kopieren fehlgeschlagen");
d(t, s ? "Zitation kopiert!" : "Kopieren fehlgeschlagen");
} catch {
c(t, "Kopieren fehlgeschlagen");
d(t, "Kopieren fehlgeschlagen");
} finally {
document.body.removeChild(a);
}
}
}
function p() {
B(), $(), window.addEventListener("scroll", function() {
function h() {
B(), O(), window.addEventListener("scroll", function() {
clearTimeout(window.scrollTimeout), window.scrollTimeout = setTimeout(() => {
x(), h();
C(), p();
}, 50);
}), v(), window.addEventListener("hashchange", v), document.addEventListener("keydown", function(n) {
n.key === "Escape" && I();
}), P(), window.addEventListener("hashchange", P), document.addEventListener("keydown", function(i) {
i.key === "Escape" && T();
});
}
window.enlargePage = R;
window.closeModal = I;
window.scrollToPreviousPage = O;
window.closeModal = T;
window.scrollToPreviousPage = V;
window.scrollToNextPage = K;
window.scrollToBeilage = V;
window.shareCurrentPage = D;
window.generateCitation = Z;
window.copyPagePermalink = z;
window.generatePageCitation = _;
function F() {
b(), L(), document.querySelector(".newspaper-page-container") && p(), htmx.on("htmx:load", function(n) {
b();
}), document.body.addEventListener("htmx:afterSwap", function(n) {
window.scrollToBeilage = z;
window.shareCurrentPage = j;
window.generateCitation = D;
window.copyPagePermalink = b;
window.generatePageCitation = m;
function _() {
v(), q(), document.querySelector(".newspaper-page-container") && h(), htmx.on("htmx:load", function(i) {
v();
}), document.body.addEventListener("htmx:afterSwap", function(i) {
setTimeout(() => {
document.querySelector(".newspaper-page-container") && p();
document.querySelector(".newspaper-page-container") && h();
}, 100);
}), document.body.addEventListener("htmx:afterSettle", function(n) {
}), document.body.addEventListener("htmx:afterSettle", function(i) {
setTimeout(() => {
document.querySelector(".newspaper-page-container") && p();
document.querySelector(".newspaper-page-container") && h();
}, 200);
}), document.body.addEventListener("htmx:load", function(n) {
}), document.body.addEventListener("htmx:load", function(i) {
setTimeout(() => {
document.querySelector(".newspaper-page-container") && p();
document.querySelector(".newspaper-page-container") && h();
}, 100);
});
}
class Z extends HTMLElement {
constructor() {
super();
}
connectedCallback() {
this.innerHTML = `
<div class="fixed inset-0 z-50 flex">
<!-- Keep Inhaltsverzeichnis area empty/transparent (collapsible) -->
<div id="sidebar-spacer" class="lg:w-1/4 xl:w-1/5 flex-shrink-0 transition-all duration-300"></div>
<!-- Cover the right columns with the zoomed view -->
<div class="flex-1 bg-slate-50 overflow-auto">
<div class="relative min-h-full flex flex-col">
<!-- Header with page info and buttons -->
<div class="flex items-center justify-between p-4">
<!-- Left: Sidebar toggle and page indicator -->
<div class="flex items-center gap-3">
<!-- Sidebar toggle button -->
<button
id="sidebar-toggle-btn"
onclick="this.closest('single-page-viewer').toggleSidebar()"
class="w-10 h-10 bg-slate-100 hover:bg-slate-200 text-slate-700 border border-slate-300 rounded flex items-center justify-center transition-colors duration-200 cursor-pointer"
title="Inhaltsverzeichnis ein-/ausblenden">
<i class="ri-sidebar-unfold-line text-lg font-bold"></i>
</button>
<!-- Page indicator with icon -->
<div id="page-indicator" class="text-slate-800 flex items-center gap-3">
<span id="page-icon" class="text-lg"></span>
<span id="page-number" class="text-2xl font-serif font-bold"></span>
</div>
</div>
<!-- Right: Action buttons -->
<div class="flex items-center gap-3">
<!-- Previous page button -->
<button
id="prev-page-btn"
onclick="this.closest('single-page-viewer').goToPreviousPage()"
class="w-10 h-10 bg-gray-100 hover:bg-gray-200 text-gray-700 border border-gray-300 rounded flex items-center justify-center transition-colors duration-200 cursor-pointer"
title="Vorherige Seite">
<i class="ri-arrow-left-line text-lg font-bold"></i>
</button>
<!-- Next page button -->
<button
id="next-page-btn"
onclick="this.closest('single-page-viewer').goToNextPage()"
class="w-10 h-10 bg-gray-100 hover:bg-gray-200 text-gray-700 border border-gray-300 rounded flex items-center justify-center transition-colors duration-200 cursor-pointer"
title="Nächste Seite">
<i class="ri-arrow-right-line text-lg font-bold"></i>
</button>
<!-- Separator -->
<div class="w-px h-6 bg-gray-300"></div>
<!-- Share button -->
<button
id="share-btn"
onclick="this.closest('single-page-viewer').shareCurrentPage()"
class="w-10 h-10 bg-blue-100 hover:bg-blue-200 text-blue-700 border border-blue-300 rounded flex items-center justify-center transition-colors duration-200 cursor-pointer"
title="Link zu dieser Seite kopieren">
<i class="ri-share-line text-lg font-bold"></i>
</button>
<!-- Cite button -->
<button
id="cite-btn"
onclick="this.closest('single-page-viewer').generatePageCitation()"
class="w-10 h-10 bg-green-100 hover:bg-green-200 text-green-700 border border-green-300 rounded flex items-center justify-center transition-colors duration-200 cursor-pointer"
title="Zitation für diese Seite generieren">
<i class="ri-file-text-line text-lg font-bold"></i>
</button>
<!-- Close button -->
<button
onclick="this.closest('single-page-viewer').close()"
class="w-10 h-10 bg-gray-100 hover:bg-gray-200 text-gray-700 border border-gray-300 rounded flex items-center justify-center transition-colors duration-200 cursor-pointer"
title="Schließen">
<i class="ri-close-line text-lg font-bold"></i>
</button>
</div>
</div>
<!-- Image container that can scroll -->
<div class="flex-1 flex items-center justify-center p-4 pb-8">
<img
id="single-page-image"
src=""
alt=""
class="w-full h-auto rounded-lg shadow-2xl"
/>
</div>
</div>
</div>
</div>
`;
}
show(t, e, n, o = !1) {
const r = this.querySelector("#single-page-image"), a = this.querySelector("#page-number"), s = this.querySelector("#page-icon");
this.querySelector("#page-indicator"), r.src = t, r.alt = e, this.currentPageNumber = n, this.currentIsBeilage = o, a.textContent = n;
const l = this.determinePageIconType(n, o);
s.innerHTML = this.getPageIconHTML(l), this.updateNavigationButtons(), this.style.display = "block", document.body.style.overflow = "hidden", S(n);
}
close() {
this.style.display = "none", document.body.style.overflow = "";
}
// Determine page icon type based on page position and whether it's beilage
determinePageIconType(t, e) {
const n = e ? '.newspaper-page-container[data-beilage="true"]' : ".newspaper-page-container:not([data-beilage])", r = Array.from(document.querySelectorAll(n)).map((l) => {
const c = l.getAttribute("data-page-container");
return c ? parseInt(c) : null;
}).filter((l) => l !== null).sort((l, c) => l - c);
if (r.length === 0)
return "first";
const a = r[0], s = r[r.length - 1];
return t === a ? "first" : t === s ? "last" : t === a + 1 ? "even" : t === s - 1 ? "odd" : t % 2 === 0 ? "even" : "odd";
}
// Generate page icon HTML based on type (same as Go PageIcon function)
getPageIconHTML(t) {
const e = "ri-file-text-line text-lg";
switch (t) {
case "first":
return `<i class="${e} text-black"></i>`;
case "last":
return `<i class="${e} text-black" style="transform: scaleX(-1); display: inline-block;"></i>`;
case "even":
return `<i class="${e} text-black" style="margin-left: 2px; transform: scaleX(-1); display: inline-block;"></i><i class="${e} text-slate-400"></i>`;
case "odd":
return `<i class="${e} text-slate-400" style="margin-left: 2px; transform: scaleX(-1); display: inline-block;"></i><i class="${e} text-black"></i>`;
default:
return `<i class="${e} text-black"></i>`;
}
}
// Share current page
shareCurrentPage() {
if (typeof b == "function") {
const t = this.querySelector("#share-btn");
b(this.currentPageNumber, t, this.currentIsBeilage);
}
}
// Generate citation for current page
generatePageCitation() {
if (typeof m == "function") {
const t = this.querySelector("#cite-btn");
m(this.currentPageNumber, t);
}
}
// Update navigation button visibility based on available pages
updateNavigationButtons() {
const t = this.querySelector("#prev-page-btn"), e = this.querySelector("#next-page-btn"), { prevPage: n, nextPage: o } = this.getAdjacentPages();
n !== null ? (t.disabled = !1, t.className = t.className.replace("opacity-50 cursor-not-allowed", ""), t.className = t.className.replace("bg-gray-50 text-gray-400", "bg-gray-100 text-gray-700")) : (t.disabled = !0, t.className.includes("opacity-50") || (t.className += " opacity-50 cursor-not-allowed"), t.className = t.className.replace("bg-gray-100 text-gray-700", "bg-gray-50 text-gray-400")), o !== null ? (e.disabled = !1, e.className = e.className.replace("opacity-50 cursor-not-allowed", ""), e.className = e.className.replace("bg-gray-50 text-gray-400", "bg-gray-100 text-gray-700")) : (e.disabled = !0, e.className.includes("opacity-50") || (e.className += " opacity-50 cursor-not-allowed"), e.className = e.className.replace("bg-gray-100 text-gray-700", "bg-gray-50 text-gray-400"));
}
// Get previous and next page numbers
getAdjacentPages() {
let t;
this.currentIsBeilage ? t = '.newspaper-page-container[data-beilage="true"]' : t = ".newspaper-page-container:not([data-beilage])";
const e = Array.from(document.querySelectorAll(t));
console.log("Found containers:", e.length, "for", this.currentIsBeilage ? "beilage" : "main");
const n = e.map((s) => {
const l = s.getAttribute("data-page-container"), c = l ? parseInt(l) : null;
return console.log("Container page:", l, "parsed:", c), c;
}).filter((s) => s !== null).sort((s, l) => s - l);
console.log("All pages found:", n), console.log("Current page:", this.currentPageNumber);
const o = n.indexOf(this.currentPageNumber);
console.log("Current index:", o);
let r = null, a = null;
return o > 0 && (r = n[o - 1]), o < n.length - 1 && (a = n[o + 1]), console.log("Adjacent pages - prev:", r, "next:", a), { prevPage: r, nextPage: a };
}
// Navigate to previous page
goToPreviousPage() {
const { prevPage: t } = this.getAdjacentPages();
t !== null && this.navigateToPage(t);
}
// Navigate to next page
goToNextPage() {
const { nextPage: t } = this.getAdjacentPages();
t !== null && this.navigateToPage(t);
}
// Navigate to a specific page
navigateToPage(t) {
const e = this.currentIsBeilage ? '.newspaper-page-container[data-beilage="true"]' : ".newspaper-page-container:not([data-beilage])", n = document.querySelector(`${e}[data-page-container="${t}"]`);
if (n) {
const o = n.querySelector(".newspaper-page-image");
o && this.show(o.src, o.alt, t, this.currentIsBeilage);
}
}
// Toggle sidebar visibility
toggleSidebar() {
const t = this.querySelector("#sidebar-spacer"), e = this.querySelector("#sidebar-toggle-btn"), n = e.querySelector("i"), o = t.classList.contains("w-0");
console.log("Current state - isCollapsed:", o), console.log("Current classes:", t.className), o ? (t.classList.remove("w-0"), t.classList.add("lg:w-1/4", "xl:w-1/5"), e.className = "w-10 h-10 bg-slate-100 hover:bg-slate-200 text-slate-700 border border-slate-300 rounded flex items-center justify-center transition-colors duration-200 cursor-pointer", n.className = "ri-sidebar-unfold-line text-lg font-bold", e.title = "Inhaltsverzeichnis ausblenden", console.log("Expanding sidebar")) : (t.classList.remove("lg:w-1/4", "xl:w-1/5"), t.classList.add("w-0"), e.className = "w-10 h-10 bg-orange-100 hover:bg-orange-200 text-orange-700 border border-orange-300 rounded flex items-center justify-center transition-colors duration-200 cursor-pointer", n.className = "ri-sidebar-fold-line text-lg font-bold", e.title = "Inhaltsverzeichnis einblenden", console.log("Collapsing sidebar")), console.log("New classes:", t.className);
}
}
customElements.define("single-page-viewer", Z);
export {
F as setup
_ as setup
};

File diff suppressed because one or more lines are too long

View File

@@ -248,7 +248,7 @@
{{- if (or (eq $agentref.Category "") (eq $agentref.Category "autor")) -}}
{{- $agent := GetAgent $agentref.Ref -}}
{{- if and $agent (gt (len $agent.Names) 0) -}}
<a href="/akteure/{{ $agentref.Ref }}" class="author-link text-slate-700 hover:text-slate-900 underline decoration-slate-400 hover:decoration-slate-600">{{ index $agent.Names 0 }}</a>,
{{ Safe $fortsPrefix }}<a href="/akteure/{{ $agentref.Ref }}" class="author-link text-slate-700 hover:text-slate-900 underline decoration-slate-400 hover:decoration-slate-600">{{ index $agent.Names 0 }}</a>,
{{ if $hasKommentar }}
Gedicht mit Kommentar
{{ else if $hasUebersetzung }}
@@ -264,7 +264,7 @@
{{- end -}}
{{- end -}}
{{- if not $authorFound -}}
{{ if $hasKommentar }}
{{ Safe $fortsPrefix }}{{ if $hasKommentar }}
Gedicht mit Kommentar
{{ else if $hasUebersetzung }}
Gedichtübersetzung

View File

@@ -127,7 +127,7 @@
{{ $linkPrefix = "#page-" }}
{{ end }}
<div class="newspaper-page-container" id="{{ $idPrefix }}-{{ $page.PageNumber }}">
<div class="newspaper-page-container" id="{{ $idPrefix }}-{{ $page.PageNumber }}" data-page-container="{{ $page.PageNumber }}"{{ if $isBeilage }} data-beilage="true"{{ end }}>
<!-- Page indicator row -->
<div class="flex {{ if $isLeft }}justify-end{{ else }}justify-start{{ end }} items-center gap-1 mb-2">
{{ if $isLeft }}
@@ -138,6 +138,9 @@
<button onclick="generatePageCitation('{{ $page.PageNumber }}', this)" class="w-6 h-6 bg-green-100 hover:bg-green-200 text-green-700 border border-green-300 rounded flex items-center justify-center transition-colors duration-200 cursor-pointer" title="Zitation für Seite {{ $page.PageNumber }} generieren">
<i class="ri-file-text-line text-xs"></i>
</button>
<button onclick="enlargePage(document.querySelector('#{{ $idPrefix }}-{{ $page.PageNumber }} .newspaper-page-image'), {{ $page.PageNumber }}, false)" class="w-6 h-6 bg-purple-100 hover:bg-purple-200 text-purple-700 border border-purple-300 rounded flex items-center justify-center transition-colors duration-200 cursor-pointer" title="Seite {{ $page.PageNumber }} vergrößern">
<i class="ri-zoom-in-line text-xs"></i>
</button>
<span class="page-indicator text-sm font-bold text-slate-600 {{ $bgColor }} px-2 py-1 rounded transition-all duration-300 shadow-sm flex items-center gap-1" data-page="{{ $page.PageNumber }}">
{{ $page.PageNumber }}
<i class="ri-file-text-line {{ if $isBeilage }}text-amber-600{{ else }}text-black{{ end }} text-sm scale-x-[-1]"></i>
@@ -154,10 +157,13 @@
<button onclick="generatePageCitation('{{ $page.PageNumber }}', this)" class="w-6 h-6 bg-green-100 hover:bg-green-200 text-green-700 border border-green-300 rounded flex items-center justify-center transition-colors duration-200 cursor-pointer" title="Zitation für Seite {{ $page.PageNumber }} generieren">
<i class="ri-file-text-line text-xs"></i>
</button>
<button onclick="enlargePage(document.querySelector('#{{ $idPrefix }}-{{ $page.PageNumber }} .newspaper-page-image'), {{ $page.PageNumber }}, false)" class="w-6 h-6 bg-purple-100 hover:bg-purple-200 text-purple-700 border border-purple-300 rounded flex items-center justify-center transition-colors duration-200 cursor-pointer" title="Seite {{ $page.PageNumber }} vergrößern">
<i class="ri-zoom-in-line text-xs"></i>
</button>
{{ end }}
</div>
<div class="single-page bg-white p-4 rounded border {{ $borderColor }} {{ $hoverColor }} transition-colors duration-200">
<img src="{{ $page.ImagePath }}" alt="{{ if $isBeilage }}Beilage 1, {{ end }}Seite {{ $page.PageNumber }}" class="newspaper-page-image cursor-pointer rounded-sm hover:scale-[1.02] transition-transform duration-200" onclick="enlargePage(this, {{ $page.PageNumber }}, false)" data-page="{{ $page.PageNumber }}" loading="lazy" />
<img src="{{ $page.ImagePath }}" alt="{{ if $isBeilage }}Beilage 1, {{ end }}Seite {{ $page.PageNumber }}" class="newspaper-page-image cursor-zoom-in rounded-sm hover:scale-[1.02] transition-transform duration-200" onclick="enlargePage(this, {{ $page.PageNumber }}, false)" data-page="{{ $page.PageNumber }}" loading="lazy" />
</div>
</div>
{{ end }}

View File

@@ -369,16 +369,18 @@ function scrollToHighlightedPage(element) {
// Modal functions
function enlargePage(imgElement, pageNumber, isFromSpread) {
const modal = document.getElementById("pageModal");
const modalImage = document.getElementById("modalImage");
// Get or create the single page viewer component
let viewer = document.querySelector('single-page-viewer');
if (!viewer) {
viewer = document.createElement('single-page-viewer');
document.body.appendChild(viewer);
}
modalImage.src = imgElement.src;
modalImage.alt = imgElement.alt;
// Determine if this is a beilage page
const isBeilage = imgElement.closest('[data-beilage="true"]') !== null;
modal.classList.remove("hidden");
// Mark current page when enlarged
markCurrentPageInInhaltsverzeichnis(pageNumber);
// Show the page in the viewer
viewer.show(imgElement.src, imgElement.alt, pageNumber, isBeilage);
}
function closeModal() {
@@ -1031,4 +1033,378 @@ function setup() {
});
}
// Single Page Viewer Web Component
class SinglePageViewer extends HTMLElement {
constructor() {
super();
// No shadow DOM - use regular DOM to allow Tailwind CSS
}
connectedCallback() {
this.innerHTML = `
<div class="fixed inset-0 z-50 flex">
<!-- Keep Inhaltsverzeichnis area empty/transparent (collapsible) -->
<div id="sidebar-spacer" class="lg:w-1/4 xl:w-1/5 flex-shrink-0 transition-all duration-300"></div>
<!-- Cover the right columns with the zoomed view -->
<div class="flex-1 bg-slate-50 overflow-auto">
<div class="relative min-h-full flex flex-col">
<!-- Header with page info and buttons -->
<div class="flex items-center justify-between p-4">
<!-- Left: Sidebar toggle and page indicator -->
<div class="flex items-center gap-3">
<!-- Sidebar toggle button -->
<button
id="sidebar-toggle-btn"
onclick="this.closest('single-page-viewer').toggleSidebar()"
class="w-10 h-10 bg-slate-100 hover:bg-slate-200 text-slate-700 border border-slate-300 rounded flex items-center justify-center transition-colors duration-200 cursor-pointer"
title="Inhaltsverzeichnis ein-/ausblenden">
<i class="ri-sidebar-unfold-line text-lg font-bold"></i>
</button>
<!-- Page indicator with icon -->
<div id="page-indicator" class="text-slate-800 flex items-center gap-3">
<span id="page-icon" class="text-lg"></span>
<span id="page-number" class="text-2xl font-serif font-bold"></span>
</div>
</div>
<!-- Right: Action buttons -->
<div class="flex items-center gap-3">
<!-- Previous page button -->
<button
id="prev-page-btn"
onclick="this.closest('single-page-viewer').goToPreviousPage()"
class="w-10 h-10 bg-gray-100 hover:bg-gray-200 text-gray-700 border border-gray-300 rounded flex items-center justify-center transition-colors duration-200 cursor-pointer"
title="Vorherige Seite">
<i class="ri-arrow-left-line text-lg font-bold"></i>
</button>
<!-- Next page button -->
<button
id="next-page-btn"
onclick="this.closest('single-page-viewer').goToNextPage()"
class="w-10 h-10 bg-gray-100 hover:bg-gray-200 text-gray-700 border border-gray-300 rounded flex items-center justify-center transition-colors duration-200 cursor-pointer"
title="Nächste Seite">
<i class="ri-arrow-right-line text-lg font-bold"></i>
</button>
<!-- Separator -->
<div class="w-px h-6 bg-gray-300"></div>
<!-- Share button -->
<button
id="share-btn"
onclick="this.closest('single-page-viewer').shareCurrentPage()"
class="w-10 h-10 bg-blue-100 hover:bg-blue-200 text-blue-700 border border-blue-300 rounded flex items-center justify-center transition-colors duration-200 cursor-pointer"
title="Link zu dieser Seite kopieren">
<i class="ri-share-line text-lg font-bold"></i>
</button>
<!-- Cite button -->
<button
id="cite-btn"
onclick="this.closest('single-page-viewer').generatePageCitation()"
class="w-10 h-10 bg-green-100 hover:bg-green-200 text-green-700 border border-green-300 rounded flex items-center justify-center transition-colors duration-200 cursor-pointer"
title="Zitation für diese Seite generieren">
<i class="ri-file-text-line text-lg font-bold"></i>
</button>
<!-- Close button -->
<button
onclick="this.closest('single-page-viewer').close()"
class="w-10 h-10 bg-gray-100 hover:bg-gray-200 text-gray-700 border border-gray-300 rounded flex items-center justify-center transition-colors duration-200 cursor-pointer"
title="Schließen">
<i class="ri-close-line text-lg font-bold"></i>
</button>
</div>
</div>
<!-- Image container that can scroll -->
<div class="flex-1 flex items-center justify-center p-4 pb-8">
<img
id="single-page-image"
src=""
alt=""
class="w-full h-auto rounded-lg shadow-2xl"
/>
</div>
</div>
</div>
</div>
`;
}
show(imgSrc, imgAlt, pageNumber, isBeilage = false) {
const img = this.querySelector('#single-page-image');
const pageNumberSpan = this.querySelector('#page-number');
const pageIconSpan = this.querySelector('#page-icon');
const pageIndicator = this.querySelector('#page-indicator');
img.src = imgSrc;
img.alt = imgAlt;
// Store current page info for button actions
this.currentPageNumber = pageNumber;
this.currentIsBeilage = isBeilage;
// Set page number
pageNumberSpan.textContent = pageNumber;
// Set page icon based on position and type
const iconType = this.determinePageIconType(pageNumber, isBeilage);
pageIconSpan.innerHTML = this.getPageIconHTML(iconType);
// Page indicator styling is now consistent (white background)
// Update navigation button visibility
this.updateNavigationButtons();
this.style.display = 'block';
// Prevent background scrolling but allow scrolling within the viewer
document.body.style.overflow = 'hidden';
// Mark current page in Inhaltsverzeichnis
markCurrentPageInInhaltsverzeichnis(pageNumber);
}
close() {
this.style.display = 'none';
// Restore background scrolling
document.body.style.overflow = '';
}
// Determine page icon type based on page position and whether it's beilage
determinePageIconType(pageNumber, isBeilage) {
// Get all page containers to determine position
const containerSelector = isBeilage ? '.newspaper-page-container[data-beilage="true"]' : '.newspaper-page-container:not([data-beilage])';
const pageContainers = Array.from(document.querySelectorAll(containerSelector));
// Extract page numbers and sort them
const allPages = pageContainers
.map(container => {
const pageAttr = container.getAttribute('data-page-container');
return pageAttr ? parseInt(pageAttr) : null;
})
.filter(p => p !== null)
.sort((a, b) => a - b);
if (allPages.length === 0) {
return "first";
}
const firstPage = allPages[0];
const lastPage = allPages[allPages.length - 1];
// Same logic as Go determinePageIcon function
if (pageNumber === firstPage) {
return "first"; // Front page - normal icon
} else if (pageNumber === lastPage) {
return "last"; // Back page - mirrored icon
} else {
// For middle pages in newspaper layout
if (pageNumber === firstPage + 1) {
return "even"; // Page 2 - black + mirrored grey
} else if (pageNumber === lastPage - 1) {
return "odd"; // Page 3 - grey + black
} else {
// For newspapers with more than 4 pages, use alternating pattern
if (pageNumber % 2 === 0) {
return "even";
} else {
return "odd";
}
}
}
}
// Generate page icon HTML based on type (same as Go PageIcon function)
getPageIconHTML(iconType) {
const baseClass = "ri-file-text-line text-lg";
switch (iconType) {
case "first":
return `<i class="${baseClass} text-black"></i>`;
case "last":
return `<i class="${baseClass} text-black" style="transform: scaleX(-1); display: inline-block;"></i>`;
case "even":
return `<i class="${baseClass} text-black" style="margin-left: 2px; transform: scaleX(-1); display: inline-block;"></i><i class="${baseClass} text-slate-400"></i>`;
case "odd":
return `<i class="${baseClass} text-slate-400" style="margin-left: 2px; transform: scaleX(-1); display: inline-block;"></i><i class="${baseClass} text-black"></i>`;
default:
return `<i class="${baseClass} text-black"></i>`;
}
}
// Share current page
shareCurrentPage() {
if (typeof copyPagePermalink === 'function') {
// Use the actual button element
const shareBtn = this.querySelector('#share-btn');
copyPagePermalink(this.currentPageNumber, shareBtn, this.currentIsBeilage);
}
}
// Generate citation for current page
generatePageCitation() {
if (typeof generatePageCitation === 'function') {
// Use the actual button element
const citeBtn = this.querySelector('#cite-btn');
generatePageCitation(this.currentPageNumber, citeBtn);
}
}
// Update navigation button visibility based on available pages
updateNavigationButtons() {
const prevBtn = this.querySelector('#prev-page-btn');
const nextBtn = this.querySelector('#next-page-btn');
const { prevPage, nextPage } = this.getAdjacentPages();
// Enable/disable previous page button
if (prevPage !== null) {
prevBtn.disabled = false;
prevBtn.className = prevBtn.className.replace('opacity-50 cursor-not-allowed', '');
prevBtn.className = prevBtn.className.replace('bg-gray-50 text-gray-400', 'bg-gray-100 text-gray-700');
} else {
prevBtn.disabled = true;
if (!prevBtn.className.includes('opacity-50')) {
prevBtn.className += ' opacity-50 cursor-not-allowed';
}
prevBtn.className = prevBtn.className.replace('bg-gray-100 text-gray-700', 'bg-gray-50 text-gray-400');
}
// Enable/disable next page button
if (nextPage !== null) {
nextBtn.disabled = false;
nextBtn.className = nextBtn.className.replace('opacity-50 cursor-not-allowed', '');
nextBtn.className = nextBtn.className.replace('bg-gray-50 text-gray-400', 'bg-gray-100 text-gray-700');
} else {
nextBtn.disabled = true;
if (!nextBtn.className.includes('opacity-50')) {
nextBtn.className += ' opacity-50 cursor-not-allowed';
}
nextBtn.className = nextBtn.className.replace('bg-gray-100 text-gray-700', 'bg-gray-50 text-gray-400');
}
}
// Get previous and next page numbers
getAdjacentPages() {
// Get all page containers of the same type (main or beilage)
let containerSelector;
if (this.currentIsBeilage) {
containerSelector = '.newspaper-page-container[data-beilage="true"]';
} else {
containerSelector = '.newspaper-page-container:not([data-beilage])';
}
const pageContainers = Array.from(document.querySelectorAll(containerSelector));
console.log('Found containers:', pageContainers.length, 'for', this.currentIsBeilage ? 'beilage' : 'main');
// Extract page numbers and sort them
const allPages = pageContainers
.map(container => {
const pageAttr = container.getAttribute('data-page-container');
const pageNum = pageAttr ? parseInt(pageAttr) : null;
console.log('Container page:', pageAttr, 'parsed:', pageNum);
return pageNum;
})
.filter(p => p !== null)
.sort((a, b) => a - b);
console.log('All pages found:', allPages);
console.log('Current page:', this.currentPageNumber);
const currentIndex = allPages.indexOf(this.currentPageNumber);
console.log('Current index:', currentIndex);
let prevPage = null;
let nextPage = null;
if (currentIndex > 0) {
prevPage = allPages[currentIndex - 1];
}
if (currentIndex < allPages.length - 1) {
nextPage = allPages[currentIndex + 1];
}
console.log('Adjacent pages - prev:', prevPage, 'next:', nextPage);
return { prevPage, nextPage };
}
// Navigate to previous page
goToPreviousPage() {
const { prevPage } = this.getAdjacentPages();
if (prevPage !== null) {
this.navigateToPage(prevPage);
}
}
// Navigate to next page
goToNextPage() {
const { nextPage } = this.getAdjacentPages();
if (nextPage !== null) {
this.navigateToPage(nextPage);
}
}
// Navigate to a specific page
navigateToPage(pageNumber) {
// Find the image element for the target page
const containerSelector = this.currentIsBeilage ? '.newspaper-page-container[data-beilage="true"]' : '.newspaper-page-container:not([data-beilage])';
const targetContainer = document.querySelector(`${containerSelector}[data-page-container="${pageNumber}"]`);
if (targetContainer) {
const imgElement = targetContainer.querySelector('.newspaper-page-image');
if (imgElement) {
// Update the current view with the new page
this.show(imgElement.src, imgElement.alt, pageNumber, this.currentIsBeilage);
}
}
}
// Toggle sidebar visibility
toggleSidebar() {
const sidebarSpacer = this.querySelector('#sidebar-spacer');
const toggleBtn = this.querySelector('#sidebar-toggle-btn');
const toggleIcon = toggleBtn.querySelector('i');
// Check if sidebar is currently collapsed by looking at classes
const isCollapsed = sidebarSpacer.classList.contains('w-0');
console.log('Current state - isCollapsed:', isCollapsed);
console.log('Current classes:', sidebarSpacer.className);
if (isCollapsed) {
// Sidebar is collapsed, expand it
sidebarSpacer.classList.remove('w-0');
sidebarSpacer.classList.add('lg:w-1/4', 'xl:w-1/5');
// Update button to normal state (sidebar visible)
toggleBtn.className = 'w-10 h-10 bg-slate-100 hover:bg-slate-200 text-slate-700 border border-slate-300 rounded flex items-center justify-center transition-colors duration-200 cursor-pointer';
toggleIcon.className = 'ri-sidebar-unfold-line text-lg font-bold';
toggleBtn.title = 'Inhaltsverzeichnis ausblenden';
console.log('Expanding sidebar');
} else {
// Sidebar is expanded, collapse it
sidebarSpacer.classList.remove('lg:w-1/4', 'xl:w-1/5');
sidebarSpacer.classList.add('w-0');
// Update button to active state (sidebar hidden - orange highlight)
toggleBtn.className = 'w-10 h-10 bg-orange-100 hover:bg-orange-200 text-orange-700 border border-orange-300 rounded flex items-center justify-center transition-colors duration-200 cursor-pointer';
toggleIcon.className = 'ri-sidebar-fold-line text-lg font-bold';
toggleBtn.title = 'Inhaltsverzeichnis einblenden';
console.log('Collapsing sidebar');
}
console.log('New classes:', sidebarSpacer.className);
}
}
// Register the web component
customElements.define('single-page-viewer', SinglePageViewer);
export { setup };