2021-10-06 22:25:33 +02:00
|
|
|
import BasicWidget from "../basic_widget.js";
|
2025-02-21 20:41:00 +01:00
|
|
|
import { Tooltip, Dropdown } from "bootstrap";
|
2021-10-06 22:25:33 +02:00
|
|
|
|
|
|
|
const TPL = `
|
2024-09-02 19:37:02 +02:00
|
|
|
<div class="dropdown right-dropdown-widget dropend">
|
2024-11-23 00:11:49 +02:00
|
|
|
<button type="button" data-bs-toggle="dropdown"
|
2021-10-06 22:25:33 +02:00
|
|
|
aria-haspopup="true" aria-expanded="false"
|
2022-12-11 13:20:37 +01:00
|
|
|
class="bx right-dropdown-button launcher-button"></button>
|
2021-10-06 22:25:33 +02:00
|
|
|
|
2024-09-02 19:37:02 +02:00
|
|
|
<div class="tooltip-trigger"></div>
|
|
|
|
|
2021-10-06 22:25:33 +02:00
|
|
|
<div class="dropdown-menu dropdown-menu-right"></div>
|
|
|
|
</div>
|
|
|
|
`;
|
|
|
|
|
|
|
|
export default class RightDropdownButtonWidget extends BasicWidget {
|
2022-08-05 16:44:26 +02:00
|
|
|
constructor(title, iconClass, dropdownTpl) {
|
2021-10-06 22:25:33 +02:00
|
|
|
super();
|
|
|
|
|
|
|
|
this.iconClass = iconClass;
|
|
|
|
this.title = title;
|
|
|
|
this.dropdownTpl = dropdownTpl;
|
2024-11-23 00:11:49 +02:00
|
|
|
|
|
|
|
this.settings = {
|
2025-01-09 18:07:02 +02:00
|
|
|
titlePlacement: "right"
|
2024-11-23 00:11:49 +02:00
|
|
|
};
|
2021-10-06 22:25:33 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
doRender() {
|
|
|
|
this.$widget = $(TPL);
|
2021-10-07 21:57:20 +02:00
|
|
|
this.$dropdownMenu = this.$widget.find(".dropdown-menu");
|
2025-02-21 20:41:00 +01:00
|
|
|
this.dropdown = Dropdown.getOrCreateInstance(this.$widget.find("[data-bs-toggle='dropdown']"));
|
2021-10-06 22:25:33 +02:00
|
|
|
|
2024-09-02 19:37:02 +02:00
|
|
|
this.$tooltip = this.$widget.find(".tooltip-trigger").attr("title", this.title);
|
2025-02-21 20:41:00 +01:00
|
|
|
this.tooltip = new Tooltip(this.$tooltip, {
|
2024-11-23 00:11:49 +02:00
|
|
|
placement: this.settings.titlePlacement,
|
2025-01-09 18:07:02 +02:00
|
|
|
fallbackPlacements: [this.settings.titlePlacement]
|
2024-11-23 00:11:49 +02:00
|
|
|
});
|
2024-09-02 19:37:02 +02:00
|
|
|
|
2025-01-09 18:07:02 +02:00
|
|
|
this.$widget
|
|
|
|
.find(".right-dropdown-button")
|
2021-10-06 22:25:33 +02:00
|
|
|
.addClass(this.iconClass)
|
2024-09-02 19:37:02 +02:00
|
|
|
.on("click", () => this.tooltip.hide())
|
2025-01-09 18:07:02 +02:00
|
|
|
.on("mouseenter", () => this.tooltip.show())
|
|
|
|
.on("mouseleave", () => this.tooltip.hide());
|
2021-10-06 22:25:33 +02:00
|
|
|
|
2025-01-09 18:07:02 +02:00
|
|
|
this.$widget.on("show.bs.dropdown", async () => {
|
2021-10-07 21:57:20 +02:00
|
|
|
await this.dropdownShown();
|
|
|
|
|
|
|
|
const rect = this.$dropdownMenu[0].getBoundingClientRect();
|
|
|
|
const pixelsToBottom = $(window).height() - rect.bottom;
|
|
|
|
|
|
|
|
if (pixelsToBottom < 0) {
|
|
|
|
this.$dropdownMenu.css("top", pixelsToBottom);
|
|
|
|
}
|
|
|
|
});
|
2021-10-06 22:25:33 +02:00
|
|
|
|
|
|
|
this.$dropdownContent = $(this.dropdownTpl);
|
|
|
|
this.$widget.find(".dropdown-menu").append(this.$dropdownContent);
|
|
|
|
}
|
|
|
|
|
2023-06-23 00:26:47 +08:00
|
|
|
// to be overridden
|
2025-01-09 18:07:02 +02:00
|
|
|
async dropdownShow() {}
|
2021-10-06 22:25:33 +02:00
|
|
|
}
|