Skip to content

Commit

Permalink
[UPD] add ol.control.Button disable #1081
Browse files Browse the repository at this point in the history
  • Loading branch information
Viglino committed Jun 27, 2024
1 parent 1e98bb2 commit 5b5fe0c
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 7 deletions.
17 changes: 17 additions & 0 deletions src/control/Button.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,23 @@ var ol_control_Button = class olcontrolButton extends ol_control_Control {
else
ol_ext_element.hide(this.element);
}
/**
* Test if the control is disabled.
* @return {bool}
* @api stable
*/
getDisable() {
var button = this.element.querySelector('button');
return button && button.disabled;
}
/** Disable the control button.
* @param {bool} b disable (or enable) the control, default false (enable)
* @api stable
*/
setDisable(b) {
if (this.getDisable() == b) return;
this.element.querySelector('button').disabled = b;
}
/**
* Set the button title
* @param {string} title
Expand Down
12 changes: 5 additions & 7 deletions src/control/Toggle.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,22 +103,20 @@ var ol_control_Toggle = class olcontrolToggle extends ol_control_Button {
}
/**
* Test if the control is disabled.
* @return {bool}.
* @return {bool}
* @api stable
*/
getDisable() {
var button = this.element.querySelector("button");
var button = this.element.querySelector('button');
return button && button.disabled;
}
/** Disable the control. If disable, the control will be deactivated too.
* @param {bool} b disable (or enable) the control, default false (enable)
*/
setDisable(b) {
if (this.getDisable() == b)
return;
this.element.querySelector("button").disabled = b;
if (b && this.getActive())
this.setActive(false);
if (this.getDisable() == b) return;
this.element.querySelector('button').disabled = b;
if (b && this.getActive()) this.setActive(false);

this.dispatchEvent({ type: 'change:disable', key: 'disable', oldValue: !b, disable: b });
}
Expand Down

0 comments on commit 5b5fe0c

Please sign in to comment.