mirror of
https://github.com/Theodor-Springmann-Stiftung/lenz-web.git
synced 2025-10-29 09:15:33 +00:00
global startup script
This commit is contained in:
@@ -15548,20 +15548,24 @@ class ToolTip extends HTMLElement {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
function Letter() {
|
function Startup() {
|
||||||
let Gr = null;
|
let Gr = null;
|
||||||
function ze() {
|
const ze = [];
|
||||||
|
new URL(window.location).searchParams.get("print") === "true" && Wr(), window.addEventListener("load", () => {
|
||||||
|
Yr();
|
||||||
|
}), window.addEventListener("resize", Yr), htmx && window.addEventListener("htmx:afterSettle", (Kr) => {
|
||||||
|
Yr();
|
||||||
|
});
|
||||||
|
function Wr() {
|
||||||
Gr || (Gr = new Previewer()), Gr.preview().then(() => {
|
Gr || (Gr = new Previewer()), Gr.preview().then(() => {
|
||||||
document.body.classList.add("previewing");
|
document.body.classList.add("previewing");
|
||||||
}), window.addEventListener("popstate", (Kr) => {
|
}), window.addEventListener("popstate", (Kr) => {
|
||||||
window.location.reload();
|
window.location.reload();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
new URL(window.location).searchParams.get("print") === "true" && ze();
|
function Yr() {
|
||||||
function Wr() {
|
|
||||||
Qr(".count", ".page", ".eanchor-page"), Qr(".notes", ".note-hand", ".hand"), Qr(".notes", ".note-sidenote-meta", ".sidenote");
|
Qr(".count", ".page", ".eanchor-page"), Qr(".notes", ".note-hand", ".hand"), Qr(".notes", ".note-sidenote-meta", ".sidenote");
|
||||||
}
|
}
|
||||||
const Yr = [];
|
|
||||||
function Qr(Kr, Zr, en) {
|
function Qr(Kr, Zr, en) {
|
||||||
const tn = document.querySelector(".fulltext"), rn = document.querySelector(Kr);
|
const tn = document.querySelector(".fulltext"), rn = document.querySelector(Kr);
|
||||||
if (!rn) return;
|
if (!rn) return;
|
||||||
@@ -15580,7 +15584,7 @@ function Letter() {
|
|||||||
let un = xn, mn;
|
let un = xn, mn;
|
||||||
do {
|
do {
|
||||||
mn = !1;
|
mn = !1;
|
||||||
for (const cn of Yr) {
|
for (const cn of ze) {
|
||||||
const Cn = cn.top, yn = cn.bottom;
|
const Cn = cn.top, yn = cn.bottom;
|
||||||
un < yn && un + gn > Cn && (console.log("Collision detected", {
|
un < yn && un + gn > Cn && (console.log("Collision detected", {
|
||||||
top: un,
|
top: un,
|
||||||
@@ -15591,20 +15595,15 @@ function Letter() {
|
|||||||
}), un = yn + an, mn = !0);
|
}), un = yn + an, mn = !0);
|
||||||
}
|
}
|
||||||
} while (mn);
|
} while (mn);
|
||||||
Yr.push({ top: un, bottom: un + gn }), dn.style.top = `${un}px`;
|
ze.push({ top: un, bottom: un + gn }), dn.style.top = `${un}px`;
|
||||||
}), console.log("Aligned sidenotes", Yr);
|
});
|
||||||
}
|
}
|
||||||
window.htmx && htmx.on("htmx:afterSettle", (Kr) => {
|
|
||||||
Wr();
|
|
||||||
}), window.addEventListener("load", () => {
|
|
||||||
Wr();
|
|
||||||
}), window.addEventListener("resize", Wr);
|
|
||||||
}
|
}
|
||||||
customElements.define(SCROLL_BUTTON_ELEMENT, ScrollButton);
|
customElements.define(SCROLL_BUTTON_ELEMENT, ScrollButton);
|
||||||
customElements.define(TOOLTIP_ELEMENT, ToolTip);
|
customElements.define(TOOLTIP_ELEMENT, ToolTip);
|
||||||
export {
|
export {
|
||||||
Letter,
|
|
||||||
Previewer,
|
Previewer,
|
||||||
ScrollButton,
|
ScrollButton,
|
||||||
|
Startup,
|
||||||
XSLTParseProcess
|
XSLTParseProcess
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -29,6 +29,11 @@
|
|||||||
</head>
|
</head>
|
||||||
|
|
||||||
<body class="w-full text-lg" hx-ext="response-targets" hx-boost="true">
|
<body class="w-full text-lg" hx-ext="response-targets" hx-boost="true">
|
||||||
|
<script type="module">
|
||||||
|
import { Startup } from "/assets/scripts.js";
|
||||||
|
Startup();
|
||||||
|
</script>
|
||||||
|
|
||||||
<div class="flex flex-col min-h-screen w-full">
|
<div class="flex flex-col min-h-screen w-full">
|
||||||
<header class="container-normal pb-0" id="header">
|
<header class="container-normal pb-0" id="header">
|
||||||
{{ block "_menu" . }}
|
{{ block "_menu" . }}
|
||||||
|
|||||||
@@ -36,9 +36,3 @@
|
|||||||
<div class="traditions mt-12 pt-3 border-t-gray-200 border-t-1 max-w-[90ch] print:border-none">
|
<div class="traditions mt-12 pt-3 border-t-gray-200 border-t-1 max-w-[90ch] print:border-none">
|
||||||
{{ template "_lettertrad" $model.meta -}}
|
{{ template "_lettertrad" $model.meta -}}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<script type="module">
|
|
||||||
import { Letter } from "/assets/scripts.js";
|
|
||||||
Letter();
|
|
||||||
console.log("Letter script run");
|
|
||||||
</script>
|
|
||||||
|
|||||||
@@ -303,8 +303,27 @@ class ToolTip extends HTMLElement {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function Letter() {
|
function Startup() {
|
||||||
let pagedPreviewer = null;
|
let pagedPreviewer = null;
|
||||||
|
const positionedIntervals = [];
|
||||||
|
|
||||||
|
// INFO: Generate a print preview of the page if the URL has ?print=true
|
||||||
|
if (new URL(window.location).searchParams.get("print") === "true") {
|
||||||
|
showPreview();
|
||||||
|
}
|
||||||
|
|
||||||
|
// INFO: Listeners for sidenotes
|
||||||
|
window.addEventListener("load", () => {
|
||||||
|
alignSidenotes();
|
||||||
|
});
|
||||||
|
|
||||||
|
window.addEventListener("resize", alignSidenotes);
|
||||||
|
|
||||||
|
if (htmx) {
|
||||||
|
window.addEventListener("htmx:afterSettle", (_) => {
|
||||||
|
alignSidenotes();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
function showPreview() {
|
function showPreview() {
|
||||||
if (!pagedPreviewer) {
|
if (!pagedPreviewer) {
|
||||||
@@ -315,23 +334,19 @@ function Letter() {
|
|||||||
document.body.classList.add("previewing");
|
document.body.classList.add("previewing");
|
||||||
});
|
});
|
||||||
|
|
||||||
window.addEventListener("popstate", (event) => {
|
// INFO: this is probably not neccessary since we open the preview in a new window
|
||||||
|
// but just in case.
|
||||||
|
window.addEventListener("popstate", (_) => {
|
||||||
window.location.reload();
|
window.location.reload();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// On initial page load, check if ?print=true is set
|
|
||||||
if (new URL(window.location).searchParams.get("print") === "true") {
|
|
||||||
showPreview();
|
|
||||||
}
|
|
||||||
|
|
||||||
function alignSidenotes() {
|
function alignSidenotes() {
|
||||||
_alignSidenotes(".count", ".page", ".eanchor-page");
|
_alignSidenotes(".count", ".page", ".eanchor-page");
|
||||||
_alignSidenotes(".notes", ".note-hand", ".hand");
|
_alignSidenotes(".notes", ".note-hand", ".hand");
|
||||||
_alignSidenotes(".notes", ".note-sidenote-meta", ".sidenote");
|
_alignSidenotes(".notes", ".note-sidenote-meta", ".sidenote");
|
||||||
}
|
}
|
||||||
|
|
||||||
const positionedIntervals = [];
|
|
||||||
function _alignSidenotes(container, align, alignto) {
|
function _alignSidenotes(container, align, alignto) {
|
||||||
const fulltext = document.querySelector(".fulltext");
|
const fulltext = document.querySelector(".fulltext");
|
||||||
const cont = document.querySelector(container);
|
const cont = document.querySelector(container);
|
||||||
@@ -389,19 +404,10 @@ function Letter() {
|
|||||||
|
|
||||||
note.style.top = `${top}px`;
|
note.style.top = `${top}px`;
|
||||||
});
|
});
|
||||||
console.log("Aligned sidenotes", positionedIntervals);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
window.addEventListener("load", () => {
|
|
||||||
alignSidenotes();
|
|
||||||
});
|
|
||||||
|
|
||||||
window.addEventListener("resize", alignSidenotes);
|
|
||||||
|
|
||||||
alignSidenotes();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
customElements.define(SCROLL_BUTTON_ELEMENT, ScrollButton);
|
customElements.define(SCROLL_BUTTON_ELEMENT, ScrollButton);
|
||||||
customElements.define(TOOLTIP_ELEMENT, ToolTip);
|
customElements.define(TOOLTIP_ELEMENT, ToolTip);
|
||||||
|
|
||||||
export { XSLTParseProcess, ScrollButton, Previewer, Letter };
|
export { XSLTParseProcess, ScrollButton, Previewer, Startup };
|
||||||
|
|||||||
Reference in New Issue
Block a user