menu.js 1.2 KB

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