Notes/src/public/app/widgets/button_widget.js

68 lines
1.4 KiB
JavaScript
Raw Normal View History

2021-05-18 22:14:35 +02:00
import BasicWidget from "./basic_widget.js";
const TPL = `
<span class="button-widget"
2021-05-22 21:51:40 +02:00
data-toggle="tooltip"
2021-05-18 22:14:35 +02:00
title="">
<span class="bx"></span>
</span>
`;
export default class ButtonWidget extends BasicWidget {
constructor() {
super();
2021-05-22 22:55:24 +02:00
this.settings = {
titlePlacement: 'right'
};
2021-05-18 22:14:35 +02:00
}
doRender() {
this.$widget = $(TPL);
this.overflowing();
2021-05-22 21:35:25 +02:00
this.$widget.on("click", () => this.triggerCommand(this.settings.command));
2021-05-23 20:26:54 +02:00
this.$widget.attr("data-placement", this.settings.titlePlacement);
2021-05-18 22:14:35 +02:00
2021-05-22 21:51:40 +02:00
this.$widget.tooltip({
html: true,
title: () => this.settings.title
});
2021-05-18 22:14:35 +02:00
super.doRender();
}
refreshIcon() {
2021-05-22 22:55:24 +02:00
this.$widget
.attr("title", this.settings.title)
2021-05-18 22:14:35 +02:00
this.$widget.find("span.bx")
.removeClass()
.addClass("bx")
2021-05-22 21:35:25 +02:00
.addClass(this.settings.icon);
}
initialRenderCompleteEvent() {
this.refreshIcon();
2021-05-18 22:14:35 +02:00
}
icon(icon) {
2021-05-22 21:35:25 +02:00
this.settings.icon = icon;
2021-05-18 22:14:35 +02:00
return this;
}
title(title) {
2021-05-22 21:35:25 +02:00
this.settings.title = title;
2021-05-18 22:14:35 +02:00
return this;
}
2021-05-22 22:55:24 +02:00
titlePlacement(placement) {
this.settings.titlePlacement = placement;
return this;
}
2021-05-18 22:14:35 +02:00
command(command) {
2021-05-22 21:35:25 +02:00
this.settings.command = command;
2021-05-18 22:14:35 +02:00
return this;
}
}