2024-01-06 12:00:52 +01:00
|
|
|
app.views.Menu = class Menu extends app.View {
|
2024-01-06 14:52:41 +01:00
|
|
|
static el = "._menu";
|
|
|
|
|
static activeClass = "active";
|
2024-01-06 11:51:57 +01:00
|
|
|
|
2024-01-06 14:52:41 +01:00
|
|
|
static events = { click: "onClick" };
|
2017-02-20 15:50:15 -05:00
|
|
|
|
2024-01-06 11:47:09 +01:00
|
|
|
init() {
|
2024-01-06 12:54:13 +01:00
|
|
|
$.on(document.body, "click", (event) => this.onGlobalClick(event));
|
2024-01-06 11:47:09 +01:00
|
|
|
}
|
2017-02-20 15:50:15 -05:00
|
|
|
|
2024-01-06 11:47:09 +01:00
|
|
|
onClick(event) {
|
|
|
|
|
const target = $.eventTarget(event);
|
2024-01-06 11:51:57 +01:00
|
|
|
if (target.tagName === "A") {
|
|
|
|
|
target.blur();
|
|
|
|
|
}
|
2024-01-06 11:47:09 +01:00
|
|
|
}
|
2017-02-20 15:50:15 -05:00
|
|
|
|
2024-01-06 11:47:09 +01:00
|
|
|
onGlobalClick(event) {
|
2024-01-06 11:51:57 +01:00
|
|
|
if (event.which !== 1) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if (
|
|
|
|
|
typeof event.target.hasAttribute === "function"
|
|
|
|
|
? event.target.hasAttribute("data-toggle-menu")
|
|
|
|
|
: undefined
|
|
|
|
|
) {
|
2024-01-06 11:47:09 +01:00
|
|
|
this.toggleClass(this.constructor.activeClass);
|
|
|
|
|
} else if (this.hasClass(this.constructor.activeClass)) {
|
|
|
|
|
this.removeClass(this.constructor.activeClass);
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-01-06 12:00:52 +01:00
|
|
|
};
|