orion/cmd/server/static/src/controllers/menu_controller.js

21 lines
434 B
JavaScript

import { Controller } from "stimulus"
export default class extends Controller {
connect() {
this.updateLinkStatus();
}
updateLinkStatus() {
const href = window.location.href;
const links = Array.from(this.element.querySelectorAll("a[href]"));
links.forEach(l => {
if (l.href === href) {
l.classList.add("is-active");
} else {
l.classList.remove("is-active");
}
});
}
}