menu.js 764 B

1234567891011121314151617181920212223242526272829303132
  1. app.views.Menu = class Menu extends app.View {
  2. static el = "._menu";
  3. static activeClass = "active";
  4. static events = { click: "onClick" };
  5. init() {
  6. $.on(document.body, "click", (event) => this.onGlobalClick(event));
  7. }
  8. onClick(event) {
  9. const target = $.eventTarget(event);
  10. if (target.tagName === "A") {
  11. target.blur();
  12. }
  13. }
  14. onGlobalClick(event) {
  15. if (event.which !== 1) {
  16. return;
  17. }
  18. if (
  19. typeof event.target.hasAttribute === "function"
  20. ? event.target.hasAttribute("data-toggle-menu")
  21. : undefined
  22. ) {
  23. this.toggleClass(this.constructor.activeClass);
  24. } else if (this.hasClass(this.constructor.activeClass)) {
  25. this.removeClass(this.constructor.activeClass);
  26. }
  27. }
  28. };