mirror of
https://codeberg.org/vegvisir/website.git
synced 2025-09-13 16:33:42 +02:00
Brand new design for the website following the new design language I used for [version 2.0 of my personal website](https://codeberg.org/vlw/vlw.se/releases/tag/2.0.0). Reviewed-on: https://codeberg.org/vegvisir/website/pulls/2 Co-authored-by: vlw <victor@vlw.se> Co-committed-by: vlw <victor@vlw.se>
36 lines
No EOL
871 B
JavaScript
36 lines
No EOL
871 B
JavaScript
import { CustomElement } from "../CustomElement.mjs";
|
|
|
|
export const TAG_NAME = "nav-menu";
|
|
|
|
class HTMLNavMenuElement extends CustomElement {
|
|
constructor() {
|
|
super();
|
|
|
|
this.importElementStylesheet(this.constructor.name);
|
|
}
|
|
|
|
open() {
|
|
document.body.classList.add("menu-open");
|
|
this.classList.add("active");
|
|
}
|
|
|
|
close() {
|
|
this.classList.remove("active");
|
|
|
|
// Remove classname from body tag if this was the last menu that was open
|
|
if (!document.querySelector(TAG_NAME + ".active")) {
|
|
document.body.classList.remove("menu-open");
|
|
}
|
|
}
|
|
|
|
toggle() {
|
|
this.classList.contains("active") ? this.close() : this.open();
|
|
}
|
|
|
|
connected() {
|
|
// Close menu when a link is clicked
|
|
[...document.querySelectorAll("a")].forEach(element => element.addEventListener("click", () => this.close()));
|
|
}
|
|
}
|
|
|
|
globalThis.customElements.define(TAG_NAME, HTMLNavMenuElement); |