path.js 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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. 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 = { role: "complementary" };
  19. this.events = { click: "onClick" };
  20. this.routes = { after: "afterRoute" };
  21. }
  22. render(...args) {
  23. this.html(this.tmpl("path", ...Array.from(args)));
  24. this.show();
  25. }
  26. show() {
  27. if (!this.el.parentNode) {
  28. this.prependTo(app.el);
  29. }
  30. }
  31. hide() {
  32. if (this.el.parentNode) {
  33. $.remove(this.el);
  34. }
  35. }
  36. onClick(event) {
  37. let link;
  38. if ((link = $.closestLink(event.target, this.el))) {
  39. this.clicked = true;
  40. }
  41. }
  42. afterRoute(route, context) {
  43. if (context.type) {
  44. this.render(context.doc, context.type);
  45. } else if (context.entry) {
  46. if (context.entry.isIndex()) {
  47. this.render(context.doc);
  48. } else {
  49. this.render(context.doc, context.entry.getType(), context.entry);
  50. }
  51. } else {
  52. this.hide();
  53. }
  54. if (this.clicked) {
  55. this.clicked = null;
  56. app.document.sidebar.reset();
  57. }
  58. }
  59. };
  60. app.views.Path.initClass();