mirror of
https://github.com/Theodor-Springmann-Stiftung/kgpz_web.git
synced 2025-10-29 09:05:30 +00:00
Vieweradvanced start impl
This commit is contained in:
@@ -27,8 +27,8 @@ class E extends HTMLElement {
|
||||
}, window.addEventListener("scroll", this.scrollHandler), this.navLinks.forEach((e) => {
|
||||
const t = (i) => {
|
||||
i.preventDefault();
|
||||
const n = e.getAttribute("data-target"), r = document.getElementById(n);
|
||||
r && (this.updateActiveLinkImmediate(n), this.manualNavigation = !0, r.scrollIntoView({
|
||||
const n = e.getAttribute("data-target"), s = document.getElementById(n);
|
||||
s && (this.updateActiveLinkImmediate(n), this.manualNavigation = !0, s.scrollIntoView({
|
||||
behavior: "smooth",
|
||||
block: "start"
|
||||
}), setTimeout(() => {
|
||||
@@ -42,9 +42,9 @@ class E extends HTMLElement {
|
||||
const e = document.getElementById("scrollspy-slider"), t = document.getElementById("scrollspy-nav");
|
||||
if (!e || !t || e.style.opacity === "0")
|
||||
return;
|
||||
const i = t.getBoundingClientRect(), n = parseFloat(e.style.top), r = parseFloat(e.style.height), s = n + r, a = t.scrollTop, l = a + i.height;
|
||||
if (s > l) {
|
||||
const c = s - i.height + 20;
|
||||
const i = t.getBoundingClientRect(), n = parseFloat(e.style.top), s = parseFloat(e.style.height), r = n + s, a = t.scrollTop, l = a + i.height;
|
||||
if (r > l) {
|
||||
const c = r - i.height + 20;
|
||||
t.scrollTo({
|
||||
top: c,
|
||||
behavior: "smooth"
|
||||
@@ -64,24 +64,24 @@ class E extends HTMLElement {
|
||||
try {
|
||||
this.sections.forEach((n) => {
|
||||
if (!n || !n.getAttribute) return;
|
||||
const r = n.getAttribute("id"), s = n.querySelector(".akteur-werke-section"), a = n.querySelector(".akteur-beitraege-section");
|
||||
const s = n.getAttribute("id"), r = n.querySelector(".akteur-werke-section"), a = n.querySelector(".akteur-beitraege-section");
|
||||
let l = !1;
|
||||
if (s) {
|
||||
const c = s.getBoundingClientRect(), d = c.top < window.innerHeight, u = c.bottom > 0;
|
||||
if (r) {
|
||||
const c = r.getBoundingClientRect(), d = c.top < window.innerHeight, u = c.bottom > 0;
|
||||
d && u && (l = !0);
|
||||
}
|
||||
if (a && !l) {
|
||||
const c = a.getBoundingClientRect(), d = c.top < window.innerHeight, u = c.bottom > 0;
|
||||
d && u && (l = !0);
|
||||
}
|
||||
if (!s && !a) {
|
||||
if (!r && !a) {
|
||||
const c = n.querySelector("div:first-child");
|
||||
if (c) {
|
||||
const d = c.getBoundingClientRect(), u = d.top >= 0, g = d.bottom <= window.innerHeight;
|
||||
u && g && (l = !0);
|
||||
}
|
||||
}
|
||||
l && e.push(r);
|
||||
l && e.push(s);
|
||||
});
|
||||
} catch {
|
||||
return;
|
||||
@@ -89,17 +89,17 @@ class E extends HTMLElement {
|
||||
const t = [], i = document.getElementById("scrollspy-slider");
|
||||
if (this.navLinks.forEach((n) => {
|
||||
n.classList.remove("font-medium");
|
||||
const r = n.getAttribute("data-target");
|
||||
e.includes(r) && (n.classList.add("font-medium"), t.push(n));
|
||||
const s = n.getAttribute("data-target");
|
||||
e.includes(s) && (n.classList.add("font-medium"), t.push(n));
|
||||
}), t.length > 0 && i) {
|
||||
const n = document.getElementById("scrollspy-nav"), r = n.getBoundingClientRect();
|
||||
let s = 1 / 0, a = -1 / 0;
|
||||
const n = document.getElementById("scrollspy-nav"), s = n.getBoundingClientRect();
|
||||
let r = 1 / 0, a = -1 / 0;
|
||||
t.forEach((c) => {
|
||||
const d = c.getBoundingClientRect(), u = d.top - r.top + n.scrollTop, g = u + d.height;
|
||||
s = Math.min(s, u), a = Math.max(a, g);
|
||||
const d = c.getBoundingClientRect(), u = d.top - s.top + n.scrollTop, g = u + d.height;
|
||||
r = Math.min(r, u), a = Math.max(a, g);
|
||||
});
|
||||
let l = a - s;
|
||||
i.style.top = `${s}px`, i.style.height = `${l}px`, i.style.opacity = "1", setTimeout(() => this.ensureMarkerVisibility(), 100);
|
||||
let l = a - r;
|
||||
i.style.top = `${r}px`, i.style.height = `${l}px`, i.style.opacity = "1", setTimeout(() => this.ensureMarkerVisibility(), 100);
|
||||
} else i && (i.style.opacity = "0");
|
||||
t.length > 0 && this.updateSidebarScroll(t);
|
||||
}
|
||||
@@ -117,8 +117,8 @@ class E extends HTMLElement {
|
||||
if (i && (i.classList.add("font-medium"), t)) {
|
||||
const n = document.getElementById("scrollspy-nav");
|
||||
if (n) {
|
||||
const r = n.getBoundingClientRect(), s = i.getBoundingClientRect(), a = s.top - r.top + n.scrollTop;
|
||||
t.style.top = `${a}px`, t.style.height = `${s.height}px`, t.style.opacity = "1";
|
||||
const s = n.getBoundingClientRect(), r = i.getBoundingClientRect(), a = r.top - s.top + n.scrollTop;
|
||||
t.style.top = `${a}px`, t.style.height = `${r.height}px`, t.style.opacity = "1";
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -132,10 +132,10 @@ class E extends HTMLElement {
|
||||
document.documentElement.clientHeight,
|
||||
document.documentElement.scrollHeight,
|
||||
document.documentElement.offsetHeight
|
||||
), r = window.innerHeight, s = n - r, a = s > 0 ? window.scrollY / s : 0, l = t.clientHeight, d = t.scrollHeight - l;
|
||||
), s = window.innerHeight, r = n - s, a = r > 0 ? window.scrollY / r : 0, l = t.clientHeight, d = t.scrollHeight - l;
|
||||
if (d > 0) {
|
||||
const u = a * d, g = i.getBoundingClientRect(), h = t.getBoundingClientRect(), m = g.top - h.top + t.scrollTop, f = l / 2, I = m - f, v = 0.7, L = v * u + (1 - v) * I, x = Math.max(0, Math.min(d, L)), H = t.scrollTop;
|
||||
Math.abs(x - H) > 10 && t.scrollTo({
|
||||
const u = a * d, g = i.getBoundingClientRect(), p = t.getBoundingClientRect(), f = g.top - p.top + t.scrollTop, m = l / 2, H = f - m, v = 0.7, I = v * u + (1 - v) * H, x = Math.max(0, Math.min(d, I)), T = t.scrollTop;
|
||||
Math.abs(x - T) > 10 && t.scrollTo({
|
||||
top: x,
|
||||
behavior: "smooth"
|
||||
});
|
||||
@@ -158,7 +158,7 @@ class E extends HTMLElement {
|
||||
customElements.define("akteure-scrollspy", E);
|
||||
class B extends HTMLElement {
|
||||
constructor() {
|
||||
super(), this.resizeObserver = null;
|
||||
super(), this.resizeObserver = null, this.zoomLevel = 1, this.minZoom = 1, this.maxZoom = 3, this.zoomStep = 0.1, this.isPanning = !1, this.panStart = { x: 0, y: 0 }, this.panOffset = { x: 0, y: 0 }, this.dragDistance = 0;
|
||||
}
|
||||
// Dynamically detect sidebar width in pixels
|
||||
detectSidebarWidth() {
|
||||
@@ -181,7 +181,7 @@ class B extends HTMLElement {
|
||||
<div class="flex-1 bg-slate-50 overflow-auto pointer-events-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">
|
||||
<div class="flex items-center justify-between p-4 bg-slate-50 relative z-10 border-b border-slate-200">
|
||||
<!-- Left: Sidebar toggle and page indicator -->
|
||||
<div class="flex items-center gap-3">
|
||||
<!-- Sidebar toggle button -->
|
||||
@@ -198,6 +198,18 @@ class B extends HTMLElement {
|
||||
<span id="page-icon" class="text-lg"></span>
|
||||
<span id="page-number" class="text-lg font-bold bg-blue-50 px-2 py-1 rounded flex items-center gap-1"></span>
|
||||
</div>
|
||||
|
||||
<!-- Zoom indicator and reset -->
|
||||
<div class="flex items-center gap-2">
|
||||
<span id="zoom-indicator" class="text-sm font-medium text-slate-600 bg-slate-100 px-2 py-1 rounded">100%</span>
|
||||
<button
|
||||
id="zoom-reset-btn"
|
||||
onclick="this.closest('single-page-viewer').resetZoom()"
|
||||
class="w-8 h-8 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 text-xs"
|
||||
title="Zoom zurücksetzen (1:1)">
|
||||
<i class="ri-zoom-out-line text-sm"></i>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Right: Action buttons -->
|
||||
@@ -257,15 +269,15 @@ class B extends HTMLElement {
|
||||
id="single-page-image"
|
||||
src=""
|
||||
alt=""
|
||||
class="w-full h-auto rounded-lg shadow-2xl cursor-zoom-out"
|
||||
onclick="this.closest('single-page-viewer').close()"
|
||||
title="Klicken zum Schließen"
|
||||
class="w-full h-auto rounded-lg shadow-2xl cursor-zoom-in"
|
||||
onclick="this.closest('single-page-viewer').handleImageClick()"
|
||||
title="Klicken zum Vergrößern oder Schließen"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
`, this.setupResizeObserver(), this.setupKeyboardNavigation();
|
||||
`, this.setupResizeObserver(), this.setupKeyboardNavigation(), this.setupZoomAndPan();
|
||||
}
|
||||
// Set up resize observer to dynamically update sidebar width
|
||||
setupResizeObserver() {
|
||||
@@ -281,32 +293,34 @@ class B extends HTMLElement {
|
||||
e.style.width = t, console.log("Updated sidebar width to:", t);
|
||||
}
|
||||
}
|
||||
show(e, t, i, n = !1, r = 0, s = null, a = null, l = null) {
|
||||
show(e, t, i, n = !1, s = 0, r = null, a = null, l = null) {
|
||||
const c = this.querySelector("#single-page-image"), d = this.querySelector("#page-number"), u = this.querySelector("#page-icon");
|
||||
this.querySelector("#page-indicator"), c.src = e, c.alt = t, this.currentPageNumber = i, this.currentIsBeilage = n, this.currentPartNumber = s;
|
||||
this.querySelector("#page-indicator"), c.src = e, c.alt = t, this.currentPageNumber = i, this.currentIsBeilage = n, this.currentPartNumber = r;
|
||||
let g;
|
||||
if (l)
|
||||
g = l;
|
||||
else {
|
||||
const m = this.getIssueContext(i);
|
||||
g = m ? `${m}, ${i}` : `${i}`;
|
||||
const f = this.getIssueContext(i);
|
||||
g = f ? `${f}, ${i}` : `${i}`;
|
||||
}
|
||||
if (d.innerHTML = g, r && i === r) {
|
||||
if (d.innerHTML = g, s && i === s) {
|
||||
d.style.position = "relative";
|
||||
const m = d.querySelector(".target-page-dot");
|
||||
m && m.remove();
|
||||
const f = document.createElement("span");
|
||||
f.className = "target-page-dot absolute -top-1 -right-1 w-3 h-3 bg-red-500 rounded-full z-10", f.title = "verlinkte Seite", d.appendChild(f);
|
||||
const f = d.querySelector(".target-page-dot");
|
||||
f && f.remove();
|
||||
const m = document.createElement("span");
|
||||
m.className = "target-page-dot absolute -top-1 -right-1 w-3 h-3 bg-red-500 rounded-full z-10", m.title = "verlinkte Seite", d.appendChild(m);
|
||||
}
|
||||
a ? a === "part-number" && s !== null ? u.innerHTML = `<span class="part-number bg-slate-100 text-slate-800 font-bold px-1.5 py-0.5 rounded border border-slate-400 flex items-center justify-center">${s}. Teil</span>` : u.innerHTML = this.generateIconFromType(a) : u.innerHTML = this.generateFallbackIcon(i, n, s), this.updateNavigationButtons(), this.style.display = "block";
|
||||
const h = this.querySelector(".flex-1.overflow-auto");
|
||||
h && (h.scrollTop = 0), document.body.style.overflow = "hidden";
|
||||
a ? a === "part-number" && r !== null ? u.innerHTML = `<span class="part-number bg-slate-100 text-slate-800 font-bold px-1.5 py-0.5 rounded border border-slate-400 flex items-center justify-center">${r}. Teil</span>` : u.innerHTML = this.generateIconFromType(a) : u.innerHTML = this.generateFallbackIcon(i, n, r), this.updateNavigationButtons(), this.style.display = "block", this.resetZoom();
|
||||
const p = this.querySelector(".flex-1.overflow-auto");
|
||||
p && (p.scrollTop = 0), document.body.style.overflow = "hidden";
|
||||
}
|
||||
close() {
|
||||
this.style.display = "none", document.body.style.overflow = "";
|
||||
}
|
||||
disconnectedCallback() {
|
||||
this.resizeObserver && (this.resizeObserver.disconnect(), this.resizeObserver = null), this.keyboardHandler && (document.removeEventListener("keydown", this.keyboardHandler), this.keyboardHandler = null), document.body.style.overflow = "";
|
||||
this.resizeObserver && (this.resizeObserver.disconnect(), this.resizeObserver = null), this.keyboardHandler && (document.removeEventListener("keydown", this.keyboardHandler), this.keyboardHandler = null);
|
||||
const e = this.querySelector(".flex-1.flex.items-center.justify-center"), t = this.querySelector("#single-page-image");
|
||||
e && this.wheelHandler && e.removeEventListener("wheel", this.wheelHandler), t && (this.mouseDownHandler && t.removeEventListener("mousedown", this.mouseDownHandler), this.doubleClickHandler && t.removeEventListener("dblclick", this.doubleClickHandler)), this.mouseMoveHandler && document.removeEventListener("mousemove", this.mouseMoveHandler), this.mouseUpHandler && document.removeEventListener("mouseup", this.mouseUpHandler), document.body.style.overflow = "";
|
||||
}
|
||||
// Generate icon HTML from Go icon type - matches templating/engine.go PageIcon function
|
||||
generateIconFromType(e) {
|
||||
@@ -339,9 +353,87 @@ class B extends HTMLElement {
|
||||
case "Escape":
|
||||
e.preventDefault(), this.close();
|
||||
break;
|
||||
case "+":
|
||||
case "=":
|
||||
e.preventDefault(), this.adjustZoom(this.zoomStep, { clientX: window.innerWidth / 2, clientY: window.innerHeight / 2 });
|
||||
break;
|
||||
case "-":
|
||||
e.preventDefault(), this.adjustZoom(-this.zoomStep, { clientX: window.innerWidth / 2, clientY: window.innerHeight / 2 });
|
||||
break;
|
||||
case "0":
|
||||
e.preventDefault(), this.resetZoom();
|
||||
break;
|
||||
}
|
||||
}, document.addEventListener("keydown", this.keyboardHandler);
|
||||
}
|
||||
// Set up zoom and pan functionality
|
||||
setupZoomAndPan() {
|
||||
const e = this.querySelector(".flex-1.flex.items-center.justify-center"), t = this.querySelector("#single-page-image");
|
||||
!e || !t || (this.wheelHandler = (i) => {
|
||||
if (!i.ctrlKey) return;
|
||||
i.preventDefault();
|
||||
const n = i.deltaY > 0 ? -this.zoomStep : this.zoomStep;
|
||||
this.adjustZoom(n, i);
|
||||
}, this.mouseDownHandler = (i) => {
|
||||
this.zoomLevel <= 1 || (i.preventDefault(), this.isPanning = !0, this.dragDistance = 0, this.panStart.x = i.clientX - this.panOffset.x, this.panStart.y = i.clientY - this.panOffset.y, t.style.cursor = "grabbing");
|
||||
}, this.mouseMoveHandler = (i) => {
|
||||
if (!this.isPanning || this.zoomLevel <= 1) return;
|
||||
i.preventDefault();
|
||||
const n = i.clientX - this.panStart.x, s = i.clientY - this.panStart.y, r = n - this.panOffset.x, a = s - this.panOffset.y;
|
||||
this.dragDistance += Math.sqrt(r * r + a * a), this.panOffset.x = n, this.panOffset.y = s, this.updateImageTransform();
|
||||
}, this.mouseUpHandler = (i) => {
|
||||
this.isPanning && (this.isPanning = !1, this.updateImageCursor());
|
||||
}, this.doubleClickHandler = (i) => {
|
||||
i.preventDefault(), this.resetZoom();
|
||||
}, e.addEventListener("wheel", this.wheelHandler, { passive: !1 }), t.addEventListener("mousedown", this.mouseDownHandler), document.addEventListener("mousemove", this.mouseMoveHandler), document.addEventListener("mouseup", this.mouseUpHandler), t.addEventListener("dblclick", this.doubleClickHandler));
|
||||
}
|
||||
// Adjust zoom level
|
||||
adjustZoom(e, t) {
|
||||
const i = Math.max(this.minZoom, Math.min(this.maxZoom, this.zoomLevel + e));
|
||||
if (i === this.zoomLevel) return;
|
||||
const s = this.querySelector("#single-page-image").getBoundingClientRect(), r = (t.clientX - s.left) / s.width, a = (t.clientY - s.top) / s.height, l = i / this.zoomLevel;
|
||||
this.panOffset.x = r * s.width * (1 - l) + this.panOffset.x * l, this.panOffset.y = a * s.height * (1 - l) + this.panOffset.y * l, this.zoomLevel = i, this.updateImageTransform(), this.updateImageCursor(), this.updateZoomIndicator();
|
||||
}
|
||||
// Reset zoom to fit
|
||||
resetZoom() {
|
||||
this.zoomLevel = 1, this.panOffset.x = 0, this.panOffset.y = 0, this.updateImageTransform(), this.updateImageCursor(), this.updateZoomIndicator();
|
||||
}
|
||||
// Update image transform with boundaries
|
||||
updateImageTransform() {
|
||||
const e = this.querySelector("#single-page-image");
|
||||
e && (this.constrainPanOffset(), this.zoomLevel === 1 && this.panOffset.x === 0 && this.panOffset.y === 0 ? e.style.transform = "" : e.style.transform = `scale(${this.zoomLevel}) translate(${this.panOffset.x / this.zoomLevel}px, ${this.panOffset.y / this.zoomLevel}px)`, e.style.transformOrigin = "center center");
|
||||
}
|
||||
// Constrain pan offset to keep image within container bounds
|
||||
constrainPanOffset() {
|
||||
const e = this.querySelector("#single-page-image"), t = this.querySelector(".flex-1.flex.items-center.justify-center");
|
||||
if (!e || !t) return;
|
||||
const i = e.getBoundingClientRect(), n = t.getBoundingClientRect(), s = i.width * this.zoomLevel, r = i.height * this.zoomLevel, a = Math.max(0, (s - n.width) / 2), l = Math.max(0, (r - n.height) / 2);
|
||||
this.panOffset.x = Math.max(-a, Math.min(a, this.panOffset.x)), this.panOffset.y = Math.max(-l, Math.min(l, this.panOffset.y));
|
||||
}
|
||||
// Update cursor based on zoom state
|
||||
updateImageCursor() {
|
||||
const e = this.querySelector("#single-page-image");
|
||||
e && (this.zoomLevel > 1 ? (e.className = e.className.replace("cursor-zoom-in", "cursor-grab"), e.title = "Ziehen zum Verschieben") : (e.className = e.className.replace("cursor-grab", "cursor-zoom-in"), e.title = "Klicken zum Vergrößern oder Schließen"));
|
||||
}
|
||||
// Update zoom level indicator
|
||||
updateZoomIndicator() {
|
||||
const e = this.querySelector("#zoom-indicator"), t = this.querySelector("#zoom-reset-btn");
|
||||
if (!(!e || !t))
|
||||
if (this.zoomLevel === 1)
|
||||
e.textContent = "Strg + Mausrad oder +/- für Zoom", e.className = "text-xs font-medium text-slate-500 bg-slate-100 px-2 py-1 rounded", t.style.display = "none";
|
||||
else {
|
||||
const i = Math.round(this.zoomLevel * 100);
|
||||
e.textContent = `${i}%`, e.className = "text-sm font-medium text-blue-700 bg-blue-100 px-2 py-1 rounded", t.style.display = "flex";
|
||||
}
|
||||
}
|
||||
// Handle image click (always close viewer)
|
||||
handleImageClick(e) {
|
||||
if (this.dragDistance >= 5) {
|
||||
this.dragDistance = 0;
|
||||
return;
|
||||
}
|
||||
this.close(), this.dragDistance = 0;
|
||||
}
|
||||
// Share current page
|
||||
shareCurrentPage() {
|
||||
if (typeof copyPagePermalink == "function") {
|
||||
@@ -391,8 +483,8 @@ class B extends HTMLElement {
|
||||
console.log("All pages found:", i), console.log("Current page:", this.currentPageNumber);
|
||||
const n = i.indexOf(this.currentPageNumber);
|
||||
console.log("Current index:", n);
|
||||
let r = null, s = null;
|
||||
return n > 0 && (r = i[n - 1]), n < i.length - 1 && (s = i[n + 1]), console.log("Adjacent pages - prev:", r, "next:", s), { prevPage: r, nextPage: s };
|
||||
let s = null, r = null;
|
||||
return n > 0 && (s = i[n - 1]), n < i.length - 1 && (r = i[n + 1]), console.log("Adjacent pages - prev:", s, "next:", r), { prevPage: s, nextPage: r };
|
||||
}
|
||||
// Navigate to previous page
|
||||
goToPreviousPage() {
|
||||
@@ -412,16 +504,16 @@ class B extends HTMLElement {
|
||||
if (i) {
|
||||
const n = i.querySelector(".newspaper-page-image, .piece-page-image");
|
||||
if (n) {
|
||||
let r = null;
|
||||
this.currentPartNumber !== null && (r = this.getPartNumberForPage(e));
|
||||
let s = null, a = null;
|
||||
s = i.getAttribute("data-page-icon-type"), i.querySelector(".part-number") && (s = "part-number");
|
||||
let s = null;
|
||||
this.currentPartNumber !== null && (s = this.getPartNumberForPage(e));
|
||||
let r = null, a = null;
|
||||
r = i.getAttribute("data-page-icon-type"), i.querySelector(".part-number") && (r = "part-number");
|
||||
const c = i.querySelector(".page-indicator");
|
||||
if (c) {
|
||||
const d = c.cloneNode(!0);
|
||||
d.querySelectorAll("i").forEach((h) => h.remove()), d.querySelectorAll(
|
||||
d.querySelectorAll("i").forEach((p) => p.remove()), d.querySelectorAll(
|
||||
'[class*="target-page-dot"], .target-page-indicator'
|
||||
).forEach((h) => h.remove()), a = d.textContent.trim();
|
||||
).forEach((p) => p.remove()), a = d.textContent.trim();
|
||||
}
|
||||
this.show(
|
||||
n.src,
|
||||
@@ -429,8 +521,8 @@ class B extends HTMLElement {
|
||||
e,
|
||||
this.currentIsBeilage,
|
||||
0,
|
||||
r,
|
||||
s,
|
||||
r,
|
||||
a
|
||||
);
|
||||
}
|
||||
@@ -455,10 +547,10 @@ class B extends HTMLElement {
|
||||
}
|
||||
// Toggle sidebar visibility
|
||||
toggleSidebar() {
|
||||
const e = this.querySelector("#sidebar-spacer"), t = this.querySelector("#sidebar-toggle-btn"), i = t.querySelector("i"), n = e.style.width, r = n === "0px" || n === "0";
|
||||
if (console.log("Current state - isCollapsed:", r), console.log("Current width:", n), r) {
|
||||
const s = this.detectSidebarWidth();
|
||||
e.style.width = s, t.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", i.className = "ri-sidebar-fold-line text-lg font-bold", t.title = "Inhaltsverzeichnis ausblenden", console.log("Expanding sidebar to:", s);
|
||||
const e = this.querySelector("#sidebar-spacer"), t = this.querySelector("#sidebar-toggle-btn"), i = t.querySelector("i"), n = e.style.width, s = n === "0px" || n === "0";
|
||||
if (console.log("Current state - isCollapsed:", s), console.log("Current width:", n), s) {
|
||||
const r = this.detectSidebarWidth();
|
||||
e.style.width = r, t.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", i.className = "ri-sidebar-fold-line text-lg font-bold", t.title = "Inhaltsverzeichnis ausblenden", console.log("Expanding sidebar to:", r);
|
||||
} else
|
||||
e.style.width = "0px", t.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", i.className = "ri-sidebar-unfold-line text-lg font-bold", t.title = "Inhaltsverzeichnis einblenden", console.log("Collapsing sidebar");
|
||||
console.log("New width:", e.style.width);
|
||||
@@ -467,9 +559,9 @@ class B extends HTMLElement {
|
||||
getIssueContext(e) {
|
||||
const t = window.location.pathname, i = t.includes("/beitrag/");
|
||||
if (i) {
|
||||
const s = document.querySelector(`[data-page-container="${e}"]`);
|
||||
if (s) {
|
||||
const c = s.querySelector(".page-indicator");
|
||||
const r = document.querySelector(`[data-page-container="${e}"]`);
|
||||
if (r) {
|
||||
const c = r.querySelector(".page-indicator");
|
||||
if (c) {
|
||||
const d = c.textContent.trim(), u = d.match(/(\d{1,2}\.\d{1,2}\.\d{4}\s+Nr\.\s+\d+)/);
|
||||
if (u)
|
||||
@@ -487,9 +579,9 @@ class B extends HTMLElement {
|
||||
const n = t.match(/\/(\d{4})\/(\d+)/);
|
||||
if (n)
|
||||
return i ? `${n[1]} Nr. ${n[2]}` : "";
|
||||
const r = document.querySelector(".page-indicator");
|
||||
if (r) {
|
||||
const a = r.textContent.trim().match(/(\d{4})\s+Nr\.\s+(\d+)/);
|
||||
const s = document.querySelector(".page-indicator");
|
||||
if (s) {
|
||||
const a = s.textContent.trim().match(/(\d{4})\s+Nr\.\s+(\d+)/);
|
||||
if (a)
|
||||
return `${a[1]} Nr. ${a[2]}`;
|
||||
}
|
||||
@@ -550,25 +642,25 @@ customElements.define("scroll-to-top-button", A);
|
||||
window.currentPageContainers = window.currentPageContainers || [];
|
||||
window.currentActiveIndex = window.currentActiveIndex || 0;
|
||||
window.pageObserver = window.pageObserver || null;
|
||||
function N(o, e, t, i = null) {
|
||||
function q(o, e, t, i = null) {
|
||||
let n = document.querySelector("single-page-viewer");
|
||||
n || (n = document.createElement("single-page-viewer"), document.body.appendChild(n));
|
||||
const r = o.closest('[data-beilage="true"]') !== null, s = window.templateData && window.templateData.targetPage ? window.templateData.targetPage : 0, a = o.closest(".newspaper-page-container, .piece-page-container");
|
||||
const s = o.closest('[data-beilage="true"]') !== null, r = window.templateData && window.templateData.targetPage ? window.templateData.targetPage : 0, a = o.closest(".newspaper-page-container, .piece-page-container");
|
||||
let l = null, c = null;
|
||||
if (a) {
|
||||
l = a.getAttribute("data-page-icon-type"), a.querySelector(".part-number") && (l = "part-number");
|
||||
const u = a.querySelector(".page-indicator");
|
||||
if (u) {
|
||||
const g = u.cloneNode(!0);
|
||||
g.querySelectorAll("i").forEach((f) => f.remove()), g.querySelectorAll('[class*="target-page-dot"], .target-page-indicator').forEach((f) => f.remove()), c = g.textContent.trim();
|
||||
g.querySelectorAll("i").forEach((m) => m.remove()), g.querySelectorAll('[class*="target-page-dot"], .target-page-indicator').forEach((m) => m.remove()), c = g.textContent.trim();
|
||||
}
|
||||
}
|
||||
n.show(o.src, o.alt, e, r, s, i, l, c);
|
||||
n.show(o.src, o.alt, e, s, r, i, l, c);
|
||||
}
|
||||
function C() {
|
||||
function P() {
|
||||
document.getElementById("pageModal").classList.add("hidden");
|
||||
}
|
||||
function q() {
|
||||
function N() {
|
||||
if (window.pageObserver && (window.pageObserver.disconnect(), window.pageObserver = null), window.currentPageContainers = Array.from(document.querySelectorAll(".newspaper-page-container")), window.currentActiveIndex = 0, b(), document.querySelector(".newspaper-page-container")) {
|
||||
let e = /* @__PURE__ */ new Set();
|
||||
window.pageObserver = new IntersectionObserver(
|
||||
@@ -577,7 +669,7 @@ function q() {
|
||||
const n = window.currentPageContainers.indexOf(i.target);
|
||||
n !== -1 && (i.isIntersecting ? e.add(n) : e.delete(n));
|
||||
}), e.size > 0) {
|
||||
const n = Array.from(e).sort((r, s) => r - s)[0];
|
||||
const n = Array.from(e).sort((s, r) => s - r)[0];
|
||||
n !== window.currentActiveIndex && (window.currentActiveIndex = n, b());
|
||||
}
|
||||
},
|
||||
@@ -589,12 +681,12 @@ function q() {
|
||||
});
|
||||
}
|
||||
}
|
||||
function $() {
|
||||
function z() {
|
||||
if (window.currentActiveIndex > 0) {
|
||||
let o = -1;
|
||||
const e = [];
|
||||
window.currentPageContainers.forEach((i, n) => {
|
||||
const r = i.getBoundingClientRect(), s = window.innerHeight, a = Math.max(r.top, 0), l = Math.min(r.bottom, s), c = Math.max(0, l - a), d = r.height;
|
||||
const s = i.getBoundingClientRect(), r = window.innerHeight, a = Math.max(s.top, 0), l = Math.min(s.bottom, r), c = Math.max(0, l - a), d = s.height;
|
||||
c / d >= 0.3 && e.push(n);
|
||||
});
|
||||
const t = Math.min(...e);
|
||||
@@ -615,7 +707,7 @@ function M() {
|
||||
let o = -1;
|
||||
const e = [];
|
||||
window.currentPageContainers.forEach((i, n) => {
|
||||
const r = i.getBoundingClientRect(), s = window.innerHeight, a = Math.max(r.top, 0), l = Math.min(r.bottom, s), c = Math.max(0, l - a), d = r.height;
|
||||
const s = i.getBoundingClientRect(), r = window.innerHeight, a = Math.max(s.top, 0), l = Math.min(s.bottom, r), c = Math.max(0, l - a), d = s.height;
|
||||
c / d >= 0.3 && e.push(n);
|
||||
});
|
||||
const t = Math.max(...e);
|
||||
@@ -631,8 +723,8 @@ function M() {
|
||||
}, 100));
|
||||
}
|
||||
}
|
||||
function R() {
|
||||
if (T()) {
|
||||
function $() {
|
||||
if (L()) {
|
||||
const e = document.querySelector("#newspaper-content .newspaper-page-container");
|
||||
e && e.scrollIntoView({
|
||||
block: "start"
|
||||
@@ -644,10 +736,10 @@ function R() {
|
||||
});
|
||||
}
|
||||
}
|
||||
function T() {
|
||||
function L() {
|
||||
const o = [];
|
||||
window.currentPageContainers.forEach((e, t) => {
|
||||
const i = e.getBoundingClientRect(), n = window.innerHeight, r = Math.max(i.top, 0), s = Math.min(i.bottom, n), a = Math.max(0, s - r), l = i.height;
|
||||
const i = e.getBoundingClientRect(), n = window.innerHeight, s = Math.max(i.top, 0), r = Math.min(i.bottom, n), a = Math.max(0, r - s), l = i.height;
|
||||
a / l >= 0.3 && o.push(t);
|
||||
});
|
||||
for (const e of o) {
|
||||
@@ -660,11 +752,11 @@ function T() {
|
||||
function b() {
|
||||
const o = document.getElementById("prevPageBtn"), e = document.getElementById("nextPageBtn"), t = document.getElementById("beilageBtn");
|
||||
if (o && (o.style.display = "flex", window.currentActiveIndex <= 0 ? (o.disabled = !0, o.classList.add("opacity-50", "cursor-not-allowed"), o.classList.remove("hover:bg-gray-200")) : (o.disabled = !1, o.classList.remove("opacity-50", "cursor-not-allowed"), o.classList.add("hover:bg-gray-200"))), e && (e.style.display = "flex", window.currentActiveIndex >= window.currentPageContainers.length - 1 ? (e.disabled = !0, e.classList.add("opacity-50", "cursor-not-allowed"), e.classList.remove("hover:bg-gray-200")) : (e.disabled = !1, e.classList.remove("opacity-50", "cursor-not-allowed"), e.classList.add("hover:bg-gray-200"))), t) {
|
||||
const i = T(), n = t.querySelector("i");
|
||||
const i = L(), n = t.querySelector("i");
|
||||
i ? (t.title = "Zur Hauptausgabe", t.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", n && (n.className = "ri-file-text-line text-lg lg:text-xl")) : (t.title = "Zu Beilage", t.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", n && (n.className = "ri-attachment-line text-lg lg:text-xl"));
|
||||
}
|
||||
}
|
||||
function z() {
|
||||
function R() {
|
||||
const o = document.getElementById("shareLinkBtn");
|
||||
let e = "";
|
||||
if (window.currentActiveIndex !== void 0 && window.currentPageContainers && window.currentPageContainers[window.currentActiveIndex]) {
|
||||
@@ -682,48 +774,48 @@ function z() {
|
||||
function S(o, e) {
|
||||
if (navigator.clipboard)
|
||||
navigator.clipboard.writeText(o).then(() => {
|
||||
p(e, "Link kopiert!");
|
||||
h(e, "Link kopiert!");
|
||||
}).catch((t) => {
|
||||
p(e, "Kopieren fehlgeschlagen");
|
||||
h(e, "Kopieren fehlgeschlagen");
|
||||
});
|
||||
else {
|
||||
const t = document.createElement("textarea");
|
||||
t.value = o, document.body.appendChild(t), t.select();
|
||||
try {
|
||||
const i = document.execCommand("copy");
|
||||
p(e, i ? "Link kopiert!" : "Kopieren fehlgeschlagen");
|
||||
h(e, i ? "Link kopiert!" : "Kopieren fehlgeschlagen");
|
||||
} catch {
|
||||
p(e, "Kopieren fehlgeschlagen");
|
||||
h(e, "Kopieren fehlgeschlagen");
|
||||
} finally {
|
||||
document.body.removeChild(t);
|
||||
}
|
||||
}
|
||||
}
|
||||
function V() {
|
||||
function O() {
|
||||
const o = document.getElementById("citationBtn"), e = document.title || "KGPZ";
|
||||
let t = window.location.origin + window.location.pathname;
|
||||
t.includes("#") && (t = t.split("#")[0]);
|
||||
const i = (/* @__PURE__ */ new Date()).toLocaleDateString("de-DE"), n = `Königsberger Gelehrte und Politische Zeitung (KGPZ). ${e}. Digital verfügbar unter: ${t} (Zugriff: ${i}).`;
|
||||
if (navigator.clipboard)
|
||||
navigator.clipboard.writeText(n).then(() => {
|
||||
p(o, "Zitation kopiert!");
|
||||
}).catch((r) => {
|
||||
p(o, "Kopieren fehlgeschlagen");
|
||||
h(o, "Zitation kopiert!");
|
||||
}).catch((s) => {
|
||||
h(o, "Kopieren fehlgeschlagen");
|
||||
});
|
||||
else {
|
||||
const r = document.createElement("textarea");
|
||||
r.value = n, document.body.appendChild(r), r.select();
|
||||
const s = document.createElement("textarea");
|
||||
s.value = n, document.body.appendChild(s), s.select();
|
||||
try {
|
||||
const s = document.execCommand("copy");
|
||||
p(o, s ? "Zitation kopiert!" : "Kopieren fehlgeschlagen");
|
||||
const r = document.execCommand("copy");
|
||||
h(o, r ? "Zitation kopiert!" : "Kopieren fehlgeschlagen");
|
||||
} catch {
|
||||
p(o, "Kopieren fehlgeschlagen");
|
||||
h(o, "Kopieren fehlgeschlagen");
|
||||
} finally {
|
||||
document.body.removeChild(r);
|
||||
document.body.removeChild(s);
|
||||
}
|
||||
}
|
||||
}
|
||||
function p(o, e) {
|
||||
function h(o, e) {
|
||||
const t = document.querySelector(".simple-popup");
|
||||
t && t.remove();
|
||||
const i = document.createElement("div");
|
||||
@@ -741,10 +833,10 @@ function p(o, e) {
|
||||
transition: opacity 0.2s ease;
|
||||
white-space: nowrap;
|
||||
`;
|
||||
const n = o.getBoundingClientRect(), r = window.innerHeight, s = window.innerWidth;
|
||||
const n = o.getBoundingClientRect(), s = window.innerHeight, r = window.innerWidth;
|
||||
let a = n.left - 10, l = n.bottom + 8;
|
||||
const c = 120, d = 32;
|
||||
a + c > s && (a = n.right - c + 10), l + d > r && (l = n.top - d - 8), i.style.left = Math.max(5, a) + "px", i.style.top = Math.max(5, l) + "px", document.body.appendChild(i), setTimeout(() => {
|
||||
a + c > r && (a = n.right - c + 10), l + d > s && (l = n.top - d - 8), i.style.left = Math.max(5, a) + "px", i.style.top = Math.max(5, l) + "px", document.body.appendChild(i), setTimeout(() => {
|
||||
i.style.opacity = "1";
|
||||
}, 10), setTimeout(() => {
|
||||
i.style.opacity = "0", setTimeout(() => {
|
||||
@@ -752,39 +844,39 @@ function p(o, e) {
|
||||
}, 200);
|
||||
}, 2e3);
|
||||
}
|
||||
function O(o, e, t = !1) {
|
||||
function D(o, e, t = !1) {
|
||||
let i = "";
|
||||
if (t)
|
||||
i = window.location.origin + window.location.pathname + `#beilage-1-page-${o}`;
|
||||
else {
|
||||
const r = window.location.pathname.split("/");
|
||||
if (r.length >= 3) {
|
||||
const s = r[1], a = r[2];
|
||||
i = `${window.location.origin}/${s}/${a}/${o}`;
|
||||
const s = window.location.pathname.split("/");
|
||||
if (s.length >= 3) {
|
||||
const r = s[1], a = s[2];
|
||||
i = `${window.location.origin}/${r}/${a}/${o}`;
|
||||
} else
|
||||
i = window.location.origin + window.location.pathname + `/${o}`;
|
||||
}
|
||||
const n = i;
|
||||
if (navigator.clipboard)
|
||||
navigator.clipboard.writeText(n).then(() => {
|
||||
p(e, "Link kopiert!");
|
||||
}).catch((r) => {
|
||||
p(e, "Kopieren fehlgeschlagen");
|
||||
h(e, "Link kopiert!");
|
||||
}).catch((s) => {
|
||||
h(e, "Kopieren fehlgeschlagen");
|
||||
});
|
||||
else {
|
||||
const r = document.createElement("textarea");
|
||||
r.value = n, document.body.appendChild(r), r.select();
|
||||
const s = document.createElement("textarea");
|
||||
s.value = n, document.body.appendChild(s), s.select();
|
||||
try {
|
||||
const s = document.execCommand("copy");
|
||||
p(e, s ? "Link kopiert!" : "Kopieren fehlgeschlagen");
|
||||
const r = document.execCommand("copy");
|
||||
h(e, r ? "Link kopiert!" : "Kopieren fehlgeschlagen");
|
||||
} catch {
|
||||
p(e, "Kopieren fehlgeschlagen");
|
||||
h(e, "Kopieren fehlgeschlagen");
|
||||
} finally {
|
||||
document.body.removeChild(r);
|
||||
document.body.removeChild(s);
|
||||
}
|
||||
}
|
||||
}
|
||||
function D(o, e) {
|
||||
function Z(o, e) {
|
||||
const t = document.title || "KGPZ", i = window.location.pathname.split("/");
|
||||
let n;
|
||||
if (i.length >= 3) {
|
||||
@@ -792,33 +884,33 @@ function D(o, e) {
|
||||
n = `${window.location.origin}/${l}/${c}/${o}`;
|
||||
} else
|
||||
n = `${window.location.origin}${window.location.pathname}/${o}`;
|
||||
const r = n, s = (/* @__PURE__ */ new Date()).toLocaleDateString("de-DE"), a = `Königsberger Gelehrte und Politische Zeitung (KGPZ). ${t}, Seite ${o}. Digital verfügbar unter: ${r} (Zugriff: ${s}).`;
|
||||
const s = n, r = (/* @__PURE__ */ new Date()).toLocaleDateString("de-DE"), a = `Königsberger Gelehrte und Politische Zeitung (KGPZ). ${t}, Seite ${o}. Digital verfügbar unter: ${s} (Zugriff: ${r}).`;
|
||||
if (navigator.clipboard)
|
||||
navigator.clipboard.writeText(a).then(() => {
|
||||
p(e, "Zitation kopiert!");
|
||||
h(e, "Zitation kopiert!");
|
||||
}).catch((l) => {
|
||||
p(e, "Kopieren fehlgeschlagen");
|
||||
h(e, "Kopieren fehlgeschlagen");
|
||||
});
|
||||
else {
|
||||
const l = document.createElement("textarea");
|
||||
l.value = a, document.body.appendChild(l), l.select();
|
||||
try {
|
||||
const c = document.execCommand("copy");
|
||||
p(e, c ? "Zitation kopiert!" : "Kopieren fehlgeschlagen");
|
||||
h(e, c ? "Zitation kopiert!" : "Kopieren fehlgeschlagen");
|
||||
} catch {
|
||||
p(e, "Kopieren fehlgeschlagen");
|
||||
h(e, "Kopieren fehlgeschlagen");
|
||||
} finally {
|
||||
document.body.removeChild(l);
|
||||
}
|
||||
}
|
||||
}
|
||||
function k() {
|
||||
q(), window.addEventListener("scroll", function() {
|
||||
N(), window.addEventListener("scroll", function() {
|
||||
clearTimeout(window.scrollTimeout), window.scrollTimeout = setTimeout(() => {
|
||||
b();
|
||||
}, 50);
|
||||
}), document.addEventListener("keydown", function(o) {
|
||||
o.key === "Escape" && C();
|
||||
o.key === "Escape" && P();
|
||||
});
|
||||
}
|
||||
function w() {
|
||||
@@ -829,16 +921,16 @@ function w() {
|
||||
if (i === o)
|
||||
n = !0;
|
||||
else {
|
||||
const r = o.match(/^\/(\d{4})\/(\d+)(?:\/(\d+))?$/), s = i.match(/^\/(\d{4})\/(\d+)$/);
|
||||
if (r && s) {
|
||||
const [, a, l, c] = r, [, d, u] = s;
|
||||
const s = o.match(/^\/(\d{4})\/(\d+)(?:\/(\d+))?$/), r = i.match(/^\/(\d{4})\/(\d+)$/);
|
||||
if (s && r) {
|
||||
const [, a, l, c] = s, [, d, u] = r;
|
||||
a === d && l === u && (n = !0);
|
||||
}
|
||||
}
|
||||
n ? (t.classList.add("text-red-700", "pointer-events-none"), t.setAttribute("aria-current", "page")) : (t.classList.remove("text-red-700", "pointer-events-none"), t.removeAttribute("aria-current"));
|
||||
});
|
||||
}
|
||||
function P() {
|
||||
function C() {
|
||||
const o = window.location.pathname, e = document.body;
|
||||
e.classList.remove(
|
||||
"page-akteure",
|
||||
@@ -854,7 +946,7 @@ let y = [];
|
||||
window.ExecuteNextSettle = function(o) {
|
||||
typeof o == "function" && y.push(o);
|
||||
};
|
||||
function K() {
|
||||
function V() {
|
||||
for (; y.length > 0; ) {
|
||||
const o = y.shift();
|
||||
try {
|
||||
@@ -864,19 +956,19 @@ function K() {
|
||||
}
|
||||
}
|
||||
}
|
||||
window.enlargePage = N;
|
||||
window.closeModal = C;
|
||||
window.scrollToPreviousPage = $;
|
||||
window.enlargePage = q;
|
||||
window.closeModal = P;
|
||||
window.scrollToPreviousPage = z;
|
||||
window.scrollToNextPage = M;
|
||||
window.scrollToBeilage = R;
|
||||
window.shareCurrentPage = z;
|
||||
window.generateCitation = V;
|
||||
window.copyPagePermalink = O;
|
||||
window.generatePageCitation = D;
|
||||
function W() {
|
||||
P(), w(), document.querySelector(".newspaper-page-container") && k();
|
||||
window.scrollToBeilage = $;
|
||||
window.shareCurrentPage = R;
|
||||
window.generateCitation = O;
|
||||
window.copyPagePermalink = D;
|
||||
window.generatePageCitation = Z;
|
||||
function K() {
|
||||
C(), w(), document.querySelector(".newspaper-page-container") && k();
|
||||
let o = function(t) {
|
||||
P(), w(), K(), setTimeout(() => {
|
||||
C(), w(), V(), setTimeout(() => {
|
||||
document.querySelector(".newspaper-page-container") && k();
|
||||
}, 50);
|
||||
}, e = function(t) {
|
||||
@@ -884,5 +976,5 @@ function W() {
|
||||
document.body.addEventListener("htmx:afterSettle", o), document.body.addEventListener("htmx:afterSettle", w), document.body.addEventListener("htmx:beforeRequest", e);
|
||||
}
|
||||
export {
|
||||
W as setup
|
||||
K as setup
|
||||
};
|
||||
|
||||
File diff suppressed because one or more lines are too long
@@ -8,6 +8,16 @@ export class SinglePageViewer extends HTMLElement {
|
||||
super();
|
||||
// No shadow DOM - use regular DOM to allow Tailwind CSS
|
||||
this.resizeObserver = null;
|
||||
|
||||
// Zoom and pan state
|
||||
this.zoomLevel = 1;
|
||||
this.minZoom = 1; // No zoom below 100%
|
||||
this.maxZoom = 3;
|
||||
this.zoomStep = 0.1;
|
||||
this.isPanning = false;
|
||||
this.panStart = { x: 0, y: 0 };
|
||||
this.panOffset = { x: 0, y: 0 };
|
||||
this.dragDistance = 0;
|
||||
}
|
||||
|
||||
// Dynamically detect sidebar width in pixels
|
||||
@@ -50,7 +60,7 @@ export class SinglePageViewer extends HTMLElement {
|
||||
<div class="flex-1 bg-slate-50 overflow-auto pointer-events-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">
|
||||
<div class="flex items-center justify-between p-4 bg-slate-50 relative z-10 border-b border-slate-200">
|
||||
<!-- Left: Sidebar toggle and page indicator -->
|
||||
<div class="flex items-center gap-3">
|
||||
<!-- Sidebar toggle button -->
|
||||
@@ -67,6 +77,18 @@ export class SinglePageViewer extends HTMLElement {
|
||||
<span id="page-icon" class="text-lg"></span>
|
||||
<span id="page-number" class="text-lg font-bold bg-blue-50 px-2 py-1 rounded flex items-center gap-1"></span>
|
||||
</div>
|
||||
|
||||
<!-- Zoom indicator and reset -->
|
||||
<div class="flex items-center gap-2">
|
||||
<span id="zoom-indicator" class="text-sm font-medium text-slate-600 bg-slate-100 px-2 py-1 rounded">100%</span>
|
||||
<button
|
||||
id="zoom-reset-btn"
|
||||
onclick="this.closest('single-page-viewer').resetZoom()"
|
||||
class="w-8 h-8 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 text-xs"
|
||||
title="Zoom zurücksetzen (1:1)">
|
||||
<i class="ri-zoom-out-line text-sm"></i>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Right: Action buttons -->
|
||||
@@ -126,9 +148,9 @@ export class SinglePageViewer extends HTMLElement {
|
||||
id="single-page-image"
|
||||
src=""
|
||||
alt=""
|
||||
class="w-full h-auto rounded-lg shadow-2xl cursor-zoom-out"
|
||||
onclick="this.closest('single-page-viewer').close()"
|
||||
title="Klicken zum Schließen"
|
||||
class="w-full h-auto rounded-lg shadow-2xl cursor-zoom-in"
|
||||
onclick="this.closest('single-page-viewer').handleImageClick()"
|
||||
title="Klicken zum Vergrößern oder Schließen"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
@@ -141,6 +163,9 @@ export class SinglePageViewer extends HTMLElement {
|
||||
|
||||
// Set up keyboard navigation
|
||||
this.setupKeyboardNavigation();
|
||||
|
||||
// Set up zoom and pan functionality
|
||||
this.setupZoomAndPan();
|
||||
}
|
||||
|
||||
// Set up resize observer to dynamically update sidebar width
|
||||
@@ -243,6 +268,9 @@ export class SinglePageViewer extends HTMLElement {
|
||||
|
||||
this.style.display = "block";
|
||||
|
||||
// Reset zoom and pan state for new page
|
||||
this.resetZoom();
|
||||
|
||||
// Scroll to top of the single page viewer (no smooth scrolling)
|
||||
const scrollContainer = this.querySelector(".flex-1.overflow-auto");
|
||||
if (scrollContainer) {
|
||||
@@ -273,6 +301,20 @@ export class SinglePageViewer extends HTMLElement {
|
||||
this.keyboardHandler = null;
|
||||
}
|
||||
|
||||
// Clean up zoom and pan event listeners
|
||||
const imageContainer = this.querySelector('.flex-1.flex.items-center.justify-center');
|
||||
const image = this.querySelector('#single-page-image');
|
||||
|
||||
if (imageContainer && this.wheelHandler) {
|
||||
imageContainer.removeEventListener('wheel', this.wheelHandler);
|
||||
}
|
||||
if (image) {
|
||||
if (this.mouseDownHandler) image.removeEventListener('mousedown', this.mouseDownHandler);
|
||||
if (this.doubleClickHandler) image.removeEventListener('dblclick', this.doubleClickHandler);
|
||||
}
|
||||
if (this.mouseMoveHandler) document.removeEventListener('mousemove', this.mouseMoveHandler);
|
||||
if (this.mouseUpHandler) document.removeEventListener('mouseup', this.mouseUpHandler);
|
||||
|
||||
// Restore background scrolling
|
||||
document.body.style.overflow = "";
|
||||
}
|
||||
@@ -320,6 +362,19 @@ export class SinglePageViewer extends HTMLElement {
|
||||
event.preventDefault();
|
||||
this.close();
|
||||
break;
|
||||
case '+':
|
||||
case '=':
|
||||
event.preventDefault();
|
||||
this.adjustZoom(this.zoomStep, { clientX: window.innerWidth / 2, clientY: window.innerHeight / 2 });
|
||||
break;
|
||||
case '-':
|
||||
event.preventDefault();
|
||||
this.adjustZoom(-this.zoomStep, { clientX: window.innerWidth / 2, clientY: window.innerHeight / 2 });
|
||||
break;
|
||||
case '0':
|
||||
event.preventDefault();
|
||||
this.resetZoom();
|
||||
break;
|
||||
}
|
||||
};
|
||||
|
||||
@@ -327,6 +382,201 @@ export class SinglePageViewer extends HTMLElement {
|
||||
document.addEventListener('keydown', this.keyboardHandler);
|
||||
}
|
||||
|
||||
// Set up zoom and pan functionality
|
||||
setupZoomAndPan() {
|
||||
const imageContainer = this.querySelector('.flex-1.flex.items-center.justify-center');
|
||||
const image = this.querySelector('#single-page-image');
|
||||
|
||||
if (!imageContainer || !image) return;
|
||||
|
||||
// Mouse wheel zoom
|
||||
this.wheelHandler = (event) => {
|
||||
// Only zoom with Ctrl+scroll for better UX
|
||||
if (!event.ctrlKey) return;
|
||||
|
||||
event.preventDefault();
|
||||
|
||||
const delta = event.deltaY > 0 ? -this.zoomStep : this.zoomStep;
|
||||
this.adjustZoom(delta, event);
|
||||
};
|
||||
|
||||
// Pan functionality
|
||||
this.mouseDownHandler = (event) => {
|
||||
if (this.zoomLevel <= 1) return; // Only pan when zoomed in
|
||||
|
||||
event.preventDefault();
|
||||
this.isPanning = true;
|
||||
this.dragDistance = 0;
|
||||
this.panStart.x = event.clientX - this.panOffset.x;
|
||||
this.panStart.y = event.clientY - this.panOffset.y;
|
||||
|
||||
image.style.cursor = 'grabbing';
|
||||
};
|
||||
|
||||
this.mouseMoveHandler = (event) => {
|
||||
if (!this.isPanning || this.zoomLevel <= 1) return;
|
||||
|
||||
event.preventDefault();
|
||||
|
||||
const newX = event.clientX - this.panStart.x;
|
||||
const newY = event.clientY - this.panStart.y;
|
||||
|
||||
// Track drag distance to determine if it was a real drag
|
||||
const deltaX = newX - this.panOffset.x;
|
||||
const deltaY = newY - this.panOffset.y;
|
||||
this.dragDistance += Math.sqrt(deltaX * deltaX + deltaY * deltaY);
|
||||
|
||||
this.panOffset.x = newX;
|
||||
this.panOffset.y = newY;
|
||||
|
||||
this.updateImageTransform();
|
||||
};
|
||||
|
||||
this.mouseUpHandler = (event) => {
|
||||
if (this.isPanning) {
|
||||
this.isPanning = false;
|
||||
this.updateImageCursor();
|
||||
}
|
||||
};
|
||||
|
||||
// Double click to reset zoom
|
||||
this.doubleClickHandler = (event) => {
|
||||
event.preventDefault();
|
||||
this.resetZoom();
|
||||
};
|
||||
|
||||
// Add event listeners
|
||||
imageContainer.addEventListener('wheel', this.wheelHandler, { passive: false });
|
||||
image.addEventListener('mousedown', this.mouseDownHandler);
|
||||
document.addEventListener('mousemove', this.mouseMoveHandler);
|
||||
document.addEventListener('mouseup', this.mouseUpHandler);
|
||||
image.addEventListener('dblclick', this.doubleClickHandler);
|
||||
}
|
||||
|
||||
// Adjust zoom level
|
||||
adjustZoom(delta, event) {
|
||||
const newZoom = Math.max(this.minZoom, Math.min(this.maxZoom, this.zoomLevel + delta));
|
||||
|
||||
if (newZoom === this.zoomLevel) return;
|
||||
|
||||
// Calculate zoom center point relative to image
|
||||
const image = this.querySelector('#single-page-image');
|
||||
const rect = image.getBoundingClientRect();
|
||||
const centerX = (event.clientX - rect.left) / rect.width;
|
||||
const centerY = (event.clientY - rect.top) / rect.height;
|
||||
|
||||
// Adjust pan offset to zoom around mouse position
|
||||
const zoomRatio = newZoom / this.zoomLevel;
|
||||
this.panOffset.x = centerX * rect.width * (1 - zoomRatio) + this.panOffset.x * zoomRatio;
|
||||
this.panOffset.y = centerY * rect.height * (1 - zoomRatio) + this.panOffset.y * zoomRatio;
|
||||
|
||||
this.zoomLevel = newZoom;
|
||||
this.updateImageTransform();
|
||||
this.updateImageCursor();
|
||||
this.updateZoomIndicator();
|
||||
}
|
||||
|
||||
// Reset zoom to fit
|
||||
resetZoom() {
|
||||
this.zoomLevel = 1;
|
||||
this.panOffset.x = 0;
|
||||
this.panOffset.y = 0;
|
||||
this.updateImageTransform();
|
||||
this.updateImageCursor();
|
||||
this.updateZoomIndicator();
|
||||
}
|
||||
|
||||
// Update image transform with boundaries
|
||||
updateImageTransform() {
|
||||
const image = this.querySelector('#single-page-image');
|
||||
if (!image) return;
|
||||
|
||||
// Apply pan boundaries to keep image within view
|
||||
this.constrainPanOffset();
|
||||
|
||||
if (this.zoomLevel === 1 && this.panOffset.x === 0 && this.panOffset.y === 0) {
|
||||
image.style.transform = '';
|
||||
} else {
|
||||
image.style.transform = `scale(${this.zoomLevel}) translate(${this.panOffset.x / this.zoomLevel}px, ${this.panOffset.y / this.zoomLevel}px)`;
|
||||
}
|
||||
|
||||
// Update transform origin for better zoom behavior
|
||||
image.style.transformOrigin = 'center center';
|
||||
}
|
||||
|
||||
// Constrain pan offset to keep image within container bounds
|
||||
constrainPanOffset() {
|
||||
const image = this.querySelector('#single-page-image');
|
||||
const container = this.querySelector('.flex-1.flex.items-center.justify-center');
|
||||
if (!image || !container) return;
|
||||
|
||||
const imageRect = image.getBoundingClientRect();
|
||||
const containerRect = container.getBoundingClientRect();
|
||||
|
||||
// Calculate the scaled image dimensions
|
||||
const scaledWidth = imageRect.width * this.zoomLevel;
|
||||
const scaledHeight = imageRect.height * this.zoomLevel;
|
||||
|
||||
// Calculate maximum allowed pan offsets
|
||||
const maxPanX = Math.max(0, (scaledWidth - containerRect.width) / 2);
|
||||
const maxPanY = Math.max(0, (scaledHeight - containerRect.height) / 2);
|
||||
|
||||
// Constrain pan offsets
|
||||
this.panOffset.x = Math.max(-maxPanX, Math.min(maxPanX, this.panOffset.x));
|
||||
this.panOffset.y = Math.max(-maxPanY, Math.min(maxPanY, this.panOffset.y));
|
||||
}
|
||||
|
||||
// Update cursor based on zoom state
|
||||
updateImageCursor() {
|
||||
const image = this.querySelector('#single-page-image');
|
||||
if (!image) return;
|
||||
|
||||
if (this.zoomLevel > 1) {
|
||||
// When zoomed in: show grab cursor for panning
|
||||
image.className = image.className.replace('cursor-zoom-in', 'cursor-grab');
|
||||
image.title = 'Ziehen zum Verschieben';
|
||||
} else {
|
||||
// At 100%: show zoom-in cursor for zooming in
|
||||
image.className = image.className.replace('cursor-grab', 'cursor-zoom-in');
|
||||
image.title = 'Klicken zum Vergrößern oder Schließen';
|
||||
}
|
||||
}
|
||||
|
||||
// Update zoom level indicator
|
||||
updateZoomIndicator() {
|
||||
const indicator = this.querySelector('#zoom-indicator');
|
||||
const resetBtn = this.querySelector('#zoom-reset-btn');
|
||||
if (!indicator || !resetBtn) return;
|
||||
|
||||
if (this.zoomLevel === 1) {
|
||||
// At 100%: Show helpful text and hide reset button
|
||||
indicator.textContent = 'Strg + Mausrad oder +/- für Zoom';
|
||||
indicator.className = 'text-xs font-medium text-slate-500 bg-slate-100 px-2 py-1 rounded';
|
||||
resetBtn.style.display = 'none';
|
||||
} else {
|
||||
// Zoomed: Show percentage and reset button
|
||||
const percentage = Math.round(this.zoomLevel * 100);
|
||||
indicator.textContent = `${percentage}%`;
|
||||
indicator.className = 'text-sm font-medium text-blue-700 bg-blue-100 px-2 py-1 rounded';
|
||||
resetBtn.style.display = 'flex';
|
||||
}
|
||||
}
|
||||
|
||||
// Handle image click (always close viewer)
|
||||
handleImageClick(event) {
|
||||
// If it was a drag, don't do anything
|
||||
if (this.dragDistance >= 5) {
|
||||
this.dragDistance = 0;
|
||||
return;
|
||||
}
|
||||
|
||||
// Always close the viewer when clicking
|
||||
this.close();
|
||||
|
||||
// Reset drag distance for next interaction
|
||||
this.dragDistance = 0;
|
||||
}
|
||||
|
||||
// Share current page
|
||||
shareCurrentPage() {
|
||||
if (typeof copyPagePermalink === "function") {
|
||||
|
||||
Reference in New Issue
Block a user