path.js 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. // TODO: This file was created by bulk-decaffeinate.
  2. // Sanity-check the conversion and remove this comment.
  3. /*
  4. * decaffeinate suggestions:
  5. * DS101: Remove unnecessary use of Array.from
  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.Path = class Path extends app.View {
  10. static initClass() {
  11. this.className = "_path";
  12. this.attributes = { role: "complementary" };
  13. this.events = { click: "onClick" };
  14. this.routes = { after: "afterRoute" };
  15. }
  16. render(...args) {
  17. this.html(this.tmpl("path", ...Array.from(args)));
  18. this.show();
  19. }
  20. show() {
  21. if (!this.el.parentNode) {
  22. this.prependTo(app.el);
  23. }
  24. }
  25. hide() {
  26. if (this.el.parentNode) {
  27. $.remove(this.el);
  28. }
  29. }
  30. onClick(event) {
  31. let link;
  32. if ((link = $.closestLink(event.target, this.el))) {
  33. this.clicked = true;
  34. }
  35. }
  36. afterRoute(route, context) {
  37. if (context.type) {
  38. this.render(context.doc, context.type);
  39. } else if (context.entry) {
  40. if (context.entry.isIndex()) {
  41. this.render(context.doc);
  42. } else {
  43. this.render(context.doc, context.entry.getType(), context.entry);
  44. }
  45. } else {
  46. this.hide();
  47. }
  48. if (this.clicked) {
  49. this.clicked = null;
  50. app.document.sidebar.reset();
  51. }
  52. }
  53. };
  54. app.views.Path.initClass();