diff --git a/src/public/javascripts/services/app_context.js b/src/public/javascripts/services/app_context.js index 4c36d062e..05323bdf7 100644 --- a/src/public/javascripts/services/app_context.js +++ b/src/public/javascripts/services/app_context.js @@ -11,6 +11,7 @@ import TabRowWidget from "./tab_row.js"; import NoteTitleWidget from "../widgets/note_title.js"; import PromotedAttributesWidget from "../widgets/promoted_attributes.js"; import NoteDetailWidget from "../widgets/note_detail.js"; +import TabCachingWidget from "../widgets/tab_caching_widget.js"; class AppContext { constructor() { @@ -40,23 +41,19 @@ class AppContext { ]; for (const widget of leftPaneWidgets) { - const $widget = widget.render(); - - $leftPane.append($widget); + widget.renderTo($leftPane); } const $centerPane = $("#center-pane"); const centerPaneWidgets = [ - new NoteTitleWidget(this), - new PromotedAttributesWidget(this), - new NoteDetailWidget(this) + new TabCachingWidget(this, () => new NoteTitleWidget(this)), + new TabCachingWidget(this, () => new PromotedAttributesWidget(this)), + new TabCachingWidget(this, () => new NoteDetailWidget(this)) ]; for (const widget of centerPaneWidgets) { - const $widget = widget.render(); - - $centerPane.append($widget); + widget.renderTo($centerPane); } this.widgets = [ diff --git a/src/public/javascripts/widgets/basic_widget.js b/src/public/javascripts/widgets/basic_widget.js index 48983be9c..256f416ed 100644 --- a/src/public/javascripts/widgets/basic_widget.js +++ b/src/public/javascripts/widgets/basic_widget.js @@ -7,13 +7,17 @@ class BasicWidget { this.widgetId = `widget-${this.constructor.name}`; } + renderTo($parent) { + $parent.append(this.render()); + } + render() { // actual rendering is async - const $widget = this.doRender(); + this.$widget = this.doRender(); // $widget.attr('id', this.widgetId); - return $widget; + return this.$widget; } /** @@ -33,6 +37,10 @@ class BasicWidget { this.appContext.trigger(name, data); } + toggle(show) { + this.$widget.toggle(show); + } + cleanup() {} } diff --git a/src/public/javascripts/widgets/note_title.js b/src/public/javascripts/widgets/note_title.js index 1c20cc49c..dba3f1beb 100644 --- a/src/public/javascripts/widgets/note_title.js +++ b/src/public/javascripts/widgets/note_title.js @@ -8,24 +8,24 @@ import protectedSessionHolder from "../services/protected_session_holder.js"; import NoteTypeWidget from "./note_type.js"; const TPL = ` - -