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

38 lines
1001 B
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;
/** @type {JQuery} */
this.$parent = null;
this.widgets = {};
}
renderTo($parent) {
this.$parent = $parent;
}
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);
2020-01-14 20:27:40 +01:00
widget.renderTo(this.$parent);
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
}
}