victorwesterlund.com/public/assets/js/script.mjs
2022-02-16 00:48:09 +00:00

29 lines
No EOL
877 B
JavaScript

import { default as Glitch } from "./modules/Glitch.mjs";
const logging = "https://victorwesterlund-logging-dnzfgzf6za-lz.a.run.app";
async function openModal(name) {
const module = await import("./modules/Modal.mjs");
if(!module) {
alert("Failed to import module.");
return;
}
const modal = new module.default();
modal.assetsRoot = window.location.href;
}
// Bind click listerners to all links
for(let link of document.getElementsByTagName("a")) {
link.addEventListener("click", event => {
event.preventDefault();
navigator?.sendBeacon(logging, event); // Log link click
// Treat tag without func data attribute as a normal link
if(!"func" in event.target.dataset) window.location.href = event.target.href;
openModal(event.target.getAttribute("href"));
});
}
new Glitch(document.body);