mirror of
https://codeberg.org/vlw/victorwesterlund.com.git
synced 2025-09-14 03:23:41 +02:00
34 lines
No EOL
895 B
JavaScript
34 lines
No EOL
895 B
JavaScript
import { Logging } from "./Logging.mjs";
|
|
|
|
const interactions = {
|
|
toggleMenu: () => {
|
|
const speed = 200;
|
|
const menu = document.getElementsByTagName("main")[0];
|
|
|
|
menu.style.setProperty("transition",`${speed}ms`);
|
|
menu.classList.toggle("active");
|
|
setTimeout(() => menu.style.removeProperty("transition"),speed + 1);
|
|
}
|
|
}
|
|
|
|
export class Interaction extends Logging {
|
|
constructor() {
|
|
super();
|
|
this.attribute = "data-action";
|
|
|
|
const elements = document.querySelectorAll(`[${this.attribute}]`);
|
|
for(const element of elements) {
|
|
element.addEventListener("click",event => this.clickHandler(event));
|
|
}
|
|
}
|
|
|
|
clickHandler(event) {
|
|
const target = event.target.closest(`[${this.attribute}]`);
|
|
const action = target?.getAttribute(this.attribute) ?? null;
|
|
|
|
if(!target || !action || !Object.keys(interactions).includes(action)) {
|
|
return false;
|
|
}
|
|
interactions[action]();
|
|
}
|
|
} |