mirror of
https://codeberg.org/vlw/victorwesterlund.com.git
synced 2025-09-14 11:33:41 +02:00
29 lines
No EOL
877 B
JavaScript
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); |