mirror of
https://github.com/zadam/trilium.git
synced 2025-11-08 22:35:50 +01:00
standard widget => collapsible widget
This commit is contained in:
91
src/public/javascripts/widgets/collapsible_widget.js
Normal file
91
src/public/javascripts/widgets/collapsible_widget.js
Normal file
@@ -0,0 +1,91 @@
|
||||
import utils from "../services/utils.js";
|
||||
import TabAwareWidget from "./tab_aware_widget.js";
|
||||
|
||||
const WIDGET_TPL = `
|
||||
<div class="card widget">
|
||||
<div class="card-header">
|
||||
<div>
|
||||
<button class="btn btn-sm widget-title" data-toggle="collapse" data-target="#[to be set]">
|
||||
Collapsible Group Item
|
||||
</button>
|
||||
|
||||
<a class="widget-help external no-arrow bx bx-info-circle"></a>
|
||||
</div>
|
||||
|
||||
<div class="widget-header-actions"></div>
|
||||
</div>
|
||||
|
||||
<div id="[to be set]" class="collapse body-wrapper" style="transition: none;">
|
||||
<div class="card-body"></div>
|
||||
</div>
|
||||
</div>
|
||||
`;
|
||||
|
||||
class CollapsibleWidget extends TabAwareWidget {
|
||||
getWidgetTitle() { return "Untitled widget"; }
|
||||
|
||||
getHeaderActions() { return []; }
|
||||
|
||||
getHelp() { return {}; }
|
||||
|
||||
getMaxHeight() { return null; }
|
||||
|
||||
render() {
|
||||
this.$widget = $(WIDGET_TPL);
|
||||
this.$widget.find('[data-target]').attr('data-target', "#" + this.componentId);
|
||||
|
||||
this.$bodyWrapper = this.$widget.find('.body-wrapper');
|
||||
this.$bodyWrapper.attr('id', this.componentId);
|
||||
|
||||
this.$bodyWrapper.collapse("show");
|
||||
|
||||
this.$body = this.$bodyWrapper.find('.card-body');
|
||||
|
||||
const maxHeight = this.getMaxHeight();
|
||||
|
||||
if (maxHeight) {
|
||||
this.$body.css("max-height", maxHeight);
|
||||
this.$body.css("overflow", "auto");
|
||||
}
|
||||
|
||||
this.$title = this.$widget.find('.widget-title');
|
||||
this.$title.text(this.getWidgetTitle());
|
||||
|
||||
this.$help = this.$widget.find('.widget-help');
|
||||
const help = this.getHelp();
|
||||
|
||||
if (help.title) {
|
||||
this.$help.attr("title", help.title);
|
||||
this.$help.attr("href", help.url || "javascript:");
|
||||
|
||||
if (!help.url) {
|
||||
this.$help.addClass('no-link');
|
||||
}
|
||||
}
|
||||
else {
|
||||
this.$help.hide();
|
||||
}
|
||||
|
||||
this.$headerActions = this.$widget.find('.widget-header-actions');
|
||||
this.$headerActions.append(...this.getHeaderActions());
|
||||
|
||||
this.initialized = this.renderBody();
|
||||
|
||||
return this.$widget;
|
||||
}
|
||||
|
||||
async renderBody() {
|
||||
await this.doRenderBody();
|
||||
}
|
||||
|
||||
/** for overriding */
|
||||
async doRenderBody() {}
|
||||
|
||||
isExpanded() {
|
||||
return this.$bodyWrapper.hasClass("show");
|
||||
}
|
||||
|
||||
cleanup() {}
|
||||
}
|
||||
|
||||
export default CollapsibleWidget;
|
||||
Reference in New Issue
Block a user