global startup script

This commit is contained in:
Simon Martens
2025-05-21 09:47:01 +02:00
parent 79f1d706eb
commit fca2b0dd5e
4 changed files with 42 additions and 38 deletions

View File

@@ -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 };