diff options
author | GeoSot <geo.sotis@gmail.com> | 2021-11-28 05:02:10 +0300 |
---|---|---|
committer | XhmikosR <xhmikosr@gmail.com> | 2021-12-01 19:00:36 +0300 |
commit | 9b9372e8ddd60413f3d9a582bd5481586d119d8d (patch) | |
tree | 16b3bfd263639a44d6413b821f96b2dcd2202f4f /js | |
parent | 8eacbaa08b1b8a5a935fd31368388f3f7e9e25da (diff) |
Tooltip: refactor `_hoverState` to Boolean to achieve better control
Diffstat (limited to 'js')
-rw-r--r-- | js/src/tooltip.js | 27 |
1 files changed, 12 insertions, 15 deletions
diff --git a/js/src/tooltip.js b/js/src/tooltip.js index 35abd29442..f03f9ef4d5 100644 --- a/js/src/tooltip.js +++ b/js/src/tooltip.js @@ -34,9 +34,6 @@ const CLASS_NAME_FADE = 'fade' const CLASS_NAME_MODAL = 'modal' const CLASS_NAME_SHOW = 'show' -const HOVER_STATE_SHOW = 'show' -const HOVER_STATE_OUT = 'out' - const SELECTOR_TOOLTIP_INNER = '.tooltip-inner' const SELECTOR_MODAL = `.${CLASS_NAME_MODAL}` @@ -126,7 +123,7 @@ class Tooltip extends BaseComponent { // Private this._isEnabled = true this._timeout = 0 - this._hoverState = '' + this._isHovered = false this._activeTrigger = {} this._popper = null this._templateFactory = null @@ -259,12 +256,12 @@ class Tooltip extends BaseComponent { } const complete = () => { - const prevHoverState = this._hoverState + const prevHoverState = this._isHovered - this._hoverState = null + this._isHovered = false EventHandler.trigger(this._element, this.constructor.Event.SHOWN) - if (prevHoverState === HOVER_STATE_OUT) { + if (prevHoverState) { this._leave() } } @@ -283,7 +280,7 @@ class Tooltip extends BaseComponent { return } - if (this._hoverState !== HOVER_STATE_SHOW) { + if (!this._isHovered) { tip.remove() } @@ -313,7 +310,7 @@ class Tooltip extends BaseComponent { this._activeTrigger[TRIGGER_HOVER] = false this._queueCallback(complete, this.tip, this._isAnimated()) - this._hoverState = '' + this._isHovered = false } update() { @@ -521,15 +518,15 @@ class Tooltip extends BaseComponent { } _enter() { - if (this.getTipElement().classList.contains(CLASS_NAME_SHOW) || this._hoverState === HOVER_STATE_SHOW) { - this._hoverState = HOVER_STATE_SHOW + if (this.getTipElement().classList.contains(CLASS_NAME_SHOW) || this._isHovered) { + this._isHovered = true return } - this._hoverState = HOVER_STATE_SHOW + this._isHovered = true this._setTimeout(() => { - if (this._hoverState === HOVER_STATE_SHOW) { + if (this._isHovered) { this.show() } }, this._config.delay.show) @@ -540,10 +537,10 @@ class Tooltip extends BaseComponent { return } - this._hoverState = HOVER_STATE_OUT + this._isHovered = false this._setTimeout(() => { - if (this._hoverState === HOVER_STATE_OUT) { + if (!this._isHovered) { this.hide() } }, this._config.delay.hide) |