1.1 KiB · text History 25c4237
// Bundled to f/js/app.js by esbuild (see the Justfile). Importing htmx here
// registers it globally and processes hx-* attributes on load, which is what
// powers hx-boost navigation and the partial updates (ranks, plans, lookups).
import htmx from "htmx.org";
import { installMaps } from "./map.js";

// map.js and inline handlers use the global; esbuild's bundle doesn't set it.
window.htmx = htmx;
installMaps();

// Small toast helper available as window.toast(msg, {kind}) for ad-hoc use.
window.toast = (msg, opts = {}) => {
  let host = document.getElementById("toast-host");
  if (!host) {
    host = document.createElement("div");
    host.id = "toast-host";
    host.className = "toast toast-end z-50";
    document.body.appendChild(host);
  }
  const alert = document.createElement("div");
  alert.className = `alert alert-${opts.kind || "info"} shadow-lg`;
  const span = document.createElement("span");
  span.textContent = msg;
  alert.appendChild(span);
  host.appendChild(alert);
  const ttl = opts.ttl ?? 4000;
  if (ttl > 0) setTimeout(() => alert.remove(), ttl);
  return alert;
};