mirror of
https://github.com/zadam/trilium.git
synced 2025-11-06 13:26:01 +01:00
32 lines
819 B
JavaScript
32 lines
819 B
JavaScript
|
|
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;
|
||
|
|
}
|
||
|
|
|
||
|
|
activeTabChanged() {
|
||
|
|
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();
|
||
|
|
widget.renderTo(this.$parent);
|
||
|
|
widget.activeTabChangedListener();
|
||
|
|
}
|
||
|
|
|
||
|
|
widget.toggle(true);
|
||
|
|
}
|
||
|
|
}
|