mirror of
https://github.com/Theodor-Springmann-Stiftung/lenz-web.git
synced 2025-10-29 01:05:32 +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;
|
||||
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(() => {
|
||||
document.body.classList.add("previewing");
|
||||
}), window.addEventListener("popstate", (Kr) => {
|
||||
window.location.reload();
|
||||
});
|
||||
}
|
||||
new URL(window.location).searchParams.get("print") === "true" && ze();
|
||||
function Wr() {
|
||||
function Yr() {
|
||||
Qr(".count", ".page", ".eanchor-page"), Qr(".notes", ".note-hand", ".hand"), Qr(".notes", ".note-sidenote-meta", ".sidenote");
|
||||
}
|
||||
const Yr = [];
|
||||
function Qr(Kr, Zr, en) {
|
||||
const tn = document.querySelector(".fulltext"), rn = document.querySelector(Kr);
|
||||
if (!rn) return;
|
||||
@@ -15580,7 +15584,7 @@ function Letter() {
|
||||
let un = xn, mn;
|
||||
do {
|
||||
mn = !1;
|
||||
for (const cn of Yr) {
|
||||
for (const cn of ze) {
|
||||
const Cn = cn.top, yn = cn.bottom;
|
||||
un < yn && un + gn > Cn && (console.log("Collision detected", {
|
||||
top: un,
|
||||
@@ -15591,20 +15595,15 @@ function Letter() {
|
||||
}), un = yn + an, mn = !0);
|
||||
}
|
||||
} while (mn);
|
||||
Yr.push({ top: un, bottom: un + gn }), dn.style.top = `${un}px`;
|
||||
}), console.log("Aligned sidenotes", Yr);
|
||||
ze.push({ top: un, bottom: un + gn }), dn.style.top = `${un}px`;
|
||||
});
|
||||
}
|
||||
window.htmx && htmx.on("htmx:afterSettle", (Kr) => {
|
||||
Wr();
|
||||
}), window.addEventListener("load", () => {
|
||||
Wr();
|
||||
}), window.addEventListener("resize", Wr);
|
||||
}
|
||||
customElements.define(SCROLL_BUTTON_ELEMENT, ScrollButton);
|
||||
customElements.define(TOOLTIP_ELEMENT, ToolTip);
|
||||
export {
|
||||
Letter,
|
||||
Previewer,
|
||||
ScrollButton,
|
||||
Startup,
|
||||
XSLTParseProcess
|
||||
};
|
||||
|
||||
@@ -29,6 +29,11 @@
|
||||
</head>
|
||||
|
||||
<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">
|
||||
<header class="container-normal pb-0" id="header">
|
||||
{{ 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">
|
||||
{{ template "_lettertrad" $model.meta -}}
|
||||
</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;
|
||||
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() {
|
||||
if (!pagedPreviewer) {
|
||||
@@ -315,23 +334,19 @@ function Letter() {
|
||||
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();
|
||||
});
|
||||
}
|
||||
|
||||
// On initial page load, check if ?print=true is set
|
||||
if (new URL(window.location).searchParams.get("print") === "true") {
|
||||
showPreview();
|
||||
}
|
||||
|
||||
function alignSidenotes() {
|
||||
_alignSidenotes(".count", ".page", ".eanchor-page");
|
||||
_alignSidenotes(".notes", ".note-hand", ".hand");
|
||||
_alignSidenotes(".notes", ".note-sidenote-meta", ".sidenote");
|
||||
}
|
||||
|
||||
const positionedIntervals = [];
|
||||
function _alignSidenotes(container, align, alignto) {
|
||||
const fulltext = document.querySelector(".fulltext");
|
||||
const cont = document.querySelector(container);
|
||||
@@ -389,19 +404,10 @@ function Letter() {
|
||||
|
||||
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(TOOLTIP_ELEMENT, ToolTip);
|
||||
|
||||
export { XSLTParseProcess, ScrollButton, Previewer, Letter };
|
||||
export { XSLTParseProcess, ScrollButton, Previewer, Startup };
|
||||
|
||||
Reference in New Issue
Block a user