path.js 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. app.views.Path = class Path extends app.View {
  2. static className = "_path";
  3. static attributes = { role: "complementary" };
  4. static events = { click: "onClick" };
  5. static routes = { after: "afterRoute" };
  6. render(...args) {
  7. this.html(this.tmpl("path", ...args));
  8. this.show();
  9. }
  10. show() {
  11. if (!this.el.parentNode) {
  12. this.prependTo(app.el);
  13. }
  14. }
  15. hide() {
  16. if (this.el.parentNode) {
  17. $.remove(this.el);
  18. }
  19. }
  20. onClick(event) {
  21. let link;
  22. if ((link = $.closestLink(event.target, this.el))) {
  23. this.clicked = true;
  24. }
  25. }
  26. afterRoute(route, context) {
  27. if (context.type) {
  28. this.render(context.doc, context.type);
  29. } else if (context.entry) {
  30. if (context.entry.isIndex()) {
  31. this.render(context.doc);
  32. } else {
  33. this.render(context.doc, context.entry.getType(), context.entry);
  34. }
  35. } else {
  36. this.hide();
  37. }
  38. if (this.clicked) {
  39. this.clicked = null;
  40. app.document.sidebar.reset();
  41. }
  42. }
  43. };