Notes/src/public/javascripts/widgets/tab_caching_widget.js

43 lines
1.2 KiB
JavaScript
Raw Normal View History

2020-01-14 20:27:40 +01:00
import TabAwareWidget from "./tab_aware_widget.js";
export default class TabCachingWidget extends TabAwareWidget {
constructor(appContext, widgetFactory) {
super(appContext);
this.widgetFactory = widgetFactory;
this.widgets = {};
}
doRender() {
this.$widget = $(`<div class="marker" style="display: none;">`);
return this.$widget;
2020-01-14 20:27:40 +01:00
}
activeTabChangedListener() {
super.activeTabChangedListener();
2020-01-14 20:27:40 +01:00
for (const widget of Object.values(this.widgets)) {
widget.toggle(false);
}
let widget = this.widgets[this.tabContext.tabId];
if (!widget) {
widget = this.widgets[this.tabContext.tabId] = this.widgetFactory();
2020-01-18 18:01:16 +01:00
this.children.push(widget);
this.$widget.after(widget.render());
2020-01-18 18:01:16 +01:00
widget.eventReceived('setTabContext', {tabContext: this.tabContext});
2020-01-14 20:27:40 +01:00
}
widget.toggle(true);
return false; // stop propagation to children
2020-01-14 20:27:40 +01:00
}
2020-01-19 11:37:24 +01:00
toggle(show) {
for (const tabId in this.widgets) {
this.widgets[tabId].toggle(show && this.tabContext && tabId === this.tabContext.tabId);
}
}
2020-01-14 20:27:40 +01:00
}