path.js 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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. * DS101: Remove unnecessary use of Array.from
  7. * DS206: Consider reworking classes to avoid initClass
  8. * Full docs: https://github.com/decaffeinate/decaffeinate/blob/main/docs/suggestions.md
  9. */
  10. const Cls = (app.views.Path = class Path extends app.View {
  11. constructor(...args) {
  12. this.onClick = this.onClick.bind(this);
  13. this.afterRoute = this.afterRoute.bind(this);
  14. super(...args);
  15. }
  16. static initClass() {
  17. this.className = '_path';
  18. this.attributes =
  19. {role: 'complementary'};
  20. this.events =
  21. {click: 'onClick'};
  22. this.routes =
  23. {after: 'afterRoute'};
  24. }
  25. render(...args) {
  26. this.html(this.tmpl('path', ...Array.from(args)));
  27. this.show();
  28. }
  29. show() {
  30. if (!this.el.parentNode) { this.prependTo(app.el); }
  31. }
  32. hide() {
  33. if (this.el.parentNode) { $.remove(this.el); }
  34. }
  35. onClick(event) {
  36. let link;
  37. if (link = $.closestLink(event.target, this.el)) { this.clicked = true; }
  38. }
  39. afterRoute(route, context) {
  40. if (context.type) {
  41. this.render(context.doc, context.type);
  42. } else if (context.entry) {
  43. if (context.entry.isIndex()) {
  44. this.render(context.doc);
  45. } else {
  46. this.render(context.doc, context.entry.getType(), context.entry);
  47. }
  48. } else {
  49. this.hide();
  50. }
  51. if (this.clicked) {
  52. this.clicked = null;
  53. app.document.sidebar.reset();
  54. }
  55. }
  56. });
  57. Cls.initClass();