diff --git a/public/assets/js/modules/Modal.mjs b/public/assets/js/modules/Modal.mjs new file mode 100644 index 0000000..497b670 --- /dev/null +++ b/public/assets/js/modules/Modal.mjs @@ -0,0 +1,16 @@ +export default class Modal { + constructor() { + this.assetsRoot = "/"; + + this.importStyleSheet(); + console.log("post", Symbol.for("modal.style")); + } + + importStyleSheet() { + const style = document.createElement("link"); + style.setAttribute("rel", "stylesheet"); + style.setAttribute("href", this.assetsRoot + "css/modal.css"); + + document.head.appendChild(style); + } +} \ No newline at end of file diff --git a/public/assets/js/script.mjs b/public/assets/js/script.mjs new file mode 100644 index 0000000..b4e9830 --- /dev/null +++ b/public/assets/js/script.mjs @@ -0,0 +1,29 @@ +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); \ No newline at end of file diff --git a/public/index.html b/public/index.html index 9110a04..87bb9a0 100755 --- a/public/index.html +++ b/public/index.html @@ -20,7 +20,7 @@
from Sweden
- contact me + contact meI create things with code. When I'm not creating things with code, I enjoy skiing, watching movies and some occasional gaming
-Beyond computer science, I'm also a armchair rabbit-holer for engineering, astronomy and physics
+Beyond computer science, I'm also an armchair rabbit-holer for engineering, physics and astronomy
...and ☕, full-time