menu.js 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. // TODO: This file was created by bulk-decaffeinate.
  2. // Sanity-check the conversion and remove this comment.
  3. /*
  4. * decaffeinate suggestions:
  5. * DS206: Consider reworking classes to avoid initClass
  6. * Full docs: https://github.com/decaffeinate/decaffeinate/blob/main/docs/suggestions.md
  7. */
  8. app.views.Menu = class Menu extends app.View {
  9. static initClass() {
  10. this.el = "._menu";
  11. this.activeClass = "active";
  12. this.events = { click: "onClick" };
  13. }
  14. init() {
  15. $.on(document.body, "click", (event) => this.onGlobalClick(event));
  16. }
  17. onClick(event) {
  18. const target = $.eventTarget(event);
  19. if (target.tagName === "A") {
  20. target.blur();
  21. }
  22. }
  23. onGlobalClick(event) {
  24. if (event.which !== 1) {
  25. return;
  26. }
  27. if (
  28. typeof event.target.hasAttribute === "function"
  29. ? event.target.hasAttribute("data-toggle-menu")
  30. : undefined
  31. ) {
  32. this.toggleClass(this.constructor.activeClass);
  33. } else if (this.hasClass(this.constructor.activeClass)) {
  34. this.removeClass(this.constructor.activeClass);
  35. }
  36. }
  37. };
  38. app.views.Menu.initClass();