1
0

menu.js 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  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. const Cls = (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 =
  18. {click: 'onClick'};
  19. }
  20. init() {
  21. $.on(document.body, 'click', this.onGlobalClick);
  22. }
  23. onClick(event) {
  24. const target = $.eventTarget(event);
  25. if (target.tagName === 'A') { target.blur(); }
  26. }
  27. onGlobalClick(event) {
  28. if (event.which !== 1) { return; }
  29. if (typeof event.target.hasAttribute === 'function' ? event.target.hasAttribute('data-toggle-menu') : undefined) {
  30. this.toggleClass(this.constructor.activeClass);
  31. } else if (this.hasClass(this.constructor.activeClass)) {
  32. this.removeClass(this.constructor.activeClass);
  33. }
  34. }
  35. });
  36. Cls.initClass();