Files
ad/molodetz/static/js/Application.js
T

56 lines
1.8 KiB
JavaScript

// retoor <retoor@molodetz.nl>
import "./components/index.js";
import { ContentEnhancer } from "./utils/ContentEnhancer.js";
import { FormManager } from "./utils/FormManager.js";
import { Http } from "./utils/Http.js";
import { LocalTime } from "./utils/LocalTime.js";
import { MobileNav } from "./utils/MobileNav.js";
import { ModalManager } from "./utils/ModalManager.js";
import { PresenceManager } from "./utils/PresenceManager.js";
import { ScrollMemory } from "./utils/ScrollMemory.js";
import { Tabs } from "./utils/Tabs.js";
import { TermsGate } from "./utils/TermsGate.js";
import { Toast } from "./utils/Toast.js";
export class Application {
constructor() {
this.dialog = document.querySelector("dp-dialog") || document.body.appendChild(document.createElement("dp-dialog"));
this.toastHost = document.querySelector("dp-toast");
this.http = Http;
this.termsGate = new TermsGate(this.dialog);
Http.termsGate = this.termsGate;
this.forms = new FormManager(this.dialog);
this.modals = new ModalManager();
this.time = new LocalTime();
this.nav = new MobileNav();
this.tabs = new Tabs();
this.scroll = new ScrollMemory();
this.presence = new PresenceManager();
this.enhancer = new ContentEnhancer();
this.wireCopy();
}
toast(message, kind = "info") {
if (this.toastHost?.show) {
this.toastHost.show(message, kind);
}
}
wireCopy() {
document.querySelectorAll("[data-copy]").forEach((node) => {
node.title = "Click to copy";
node.addEventListener("click", async () => {
try {
await navigator.clipboard.writeText(node.textContent.trim());
this.toast("Copied");
} catch {
Toast.flash(node, "Copy failed", 1500);
}
});
});
}
}
window.app = new Application();
document.documentElement.dataset.app = "ready";