trilium/src/public/javascripts/services/sidebar.js

74 lines
1.9 KiB
JavaScript
Raw Normal View History

2019-07-21 17:32:38 +08:00
import NoteInfoWidget from "../widgets/note_info.js";
const WIDGET_TPL = `
<div class="card widget">
<div class="card-header">
<h5 class="mb-0">
<button class="btn btn-sm widget-title" data-toggle="collapse" data-target="#collapseOne">
Collapsible Group Item
</button>
</h5>
</div>
<div id="collapseOne" class="collapse show body-wrapper">
<div class="card-body"></div>
</div>
</div>
`;
let widgetIdCtr = 1;
2019-07-21 16:17:08 +08:00
class Sidebar {
/**
* @param {TabContext} ctx
*/
constructor(ctx) {
this.ctx = ctx;
this.$sidebar = ctx.$tabContent.find(".note-detail-sidebar");
2019-07-21 17:32:38 +08:00
this.$widgets = this.$sidebar.find(".note-detail-widgets");
2019-07-21 16:17:08 +08:00
this.$showSideBarButton = this.ctx.$tabContent.find(".show-sidebar-button");
this.$showSideBarButton.hide();
this.$hideSidebarButton = this.$sidebar.find(".hide-sidebar-button");
this.$hideSidebarButton.click(() => {
this.$sidebar.hide();
this.$showSideBarButton.show();
});
this.$showSideBarButton.click(() => {
this.$sidebar.show();
this.$showSideBarButton.hide();
2019-07-21 17:32:38 +08:00
});
}
async noteLoaded() {
this.$widgets.empty();
this.addNoteInfoWidget();
this.addNoteInfoWidget();
}
async addNoteInfoWidget() {
const $widget = this.createWidgetElement();
const noteInfoWidget = new NoteInfoWidget(this.ctx, $widget);
await noteInfoWidget.renderBody();
console.log($widget);
this.$widgets.append($widget);
}
createWidgetElement() {
const widgetId = 'widget-' + widgetIdCtr++;
const $widget = $(WIDGET_TPL);
$widget.find('[data-target]').attr('data-target', "#" + widgetId);
$widget.find('.body-wrapper').attr('id', widgetId);
return $widget;
2019-07-21 16:17:08 +08:00
}
}
export default Sidebar;