| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253 |
- /**
- * @class SmartButton
- * @description SmartButton is a class that enables the creation of a movable button.
- */
- export class SmartButton {
- constructor(buttonId) {
- this.button = document.getElementById(buttonId);
- if (!this.button) throw new Error("SmartButton not found");
- this.isVisible = false;
- }
- /**
- * Move the smartButton to the target position
- * @param {number} x - X Position
- * @param {number} y - Y position
- */
- moveTo(x, y) {
- Object.assign(this.button.style, {
- left: `${x}px`,
- top: `${y}px`,
- position: "absolute",
- });
- this.show();
- }
- show() {
- this.button.style.display = "block";
- this.isVisible = true;
- }
- hide() {
- this.button.style.display = "none";
- this.isVisible = false;
- }
- setPosition(x, y) {
- this.moveTo(x, y);
- }
- /**
- *
- * @returns {HTMLElement}
- */
- getElement() {
- return this.button;
- }
- onClick(callback) {
- this.button.addEventListener("click", () => {
- callback();
- });
- }
- }
|