Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/twbs/bootstrap.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGeoSot <geo.sotis@gmail.com>2021-11-28 04:09:42 +0300
committerXhmikosR <xhmikosr@gmail.com>2021-12-01 19:00:36 +0300
commitc69ccba08cd4f16d42bd83ffd40d2a57c9ca0ffc (patch)
treea02c7bc3176bc8d9a779d71d0d2d163cb88ea115
parenta20e4203fe951593e804254f8d0593a822dc5e50 (diff)
Tooltip: Change `_enter` & `_leave` to work without arguments
-rw-r--r--js/src/tooltip.js86
-rw-r--r--js/tests/unit/tooltip.spec.js4
2 files changed, 42 insertions, 48 deletions
diff --git a/js/src/tooltip.js b/js/src/tooltip.js
index ccec08ddac..645a6b7e28 100644
--- a/js/src/tooltip.js
+++ b/js/src/tooltip.js
@@ -179,17 +179,17 @@ class Tooltip extends BaseComponent {
context._activeTrigger.click = !context._activeTrigger.click
if (context._isWithActiveTrigger()) {
- context._enter(null, context)
+ context._enter()
} else {
- context._leave(null, context)
+ context._leave()
}
} else {
if (this.getTipElement().classList.contains(CLASS_NAME_SHOW)) {
- this._leave(null, this)
+ this._leave()
return
}
- this._enter(null, this)
+ this._enter()
}
}
@@ -265,7 +265,7 @@ class Tooltip extends BaseComponent {
EventHandler.trigger(this._element, this.constructor.Event.SHOWN)
if (prevHoverState === HOVER_STATE_OUT) {
- this._leave(null, this)
+ this._leave()
}
}
@@ -401,8 +401,8 @@ class Tooltip extends BaseComponent {
}
// Private
- _initializeOnDelegatedTarget(event, context) {
- return context || this.constructor.getOrCreateInstance(event.delegateTarget, this._getDelegateConfig())
+ _initializeOnDelegatedTarget(event) {
+ return this.constructor.getOrCreateInstance(event.delegateTarget, this._getDelegateConfig())
}
_isAnimated() {
@@ -478,8 +478,18 @@ class Tooltip extends BaseComponent {
this.constructor.Event.MOUSELEAVE :
this.constructor.Event.FOCUSOUT
- EventHandler.on(this._element, eventIn, this._config.selector, event => this._enter(event))
- EventHandler.on(this._element, eventOut, this._config.selector, event => this._leave(event))
+ EventHandler.on(this._element, eventIn, this._config.selector, event => {
+ const context = this._initializeOnDelegatedTarget(event)
+ context._activeTrigger[event.type === 'focusin' ? TRIGGER_FOCUS : TRIGGER_HOVER] = true
+ context._enter()
+ })
+ EventHandler.on(this._element, eventOut, this._config.selector, event => {
+ const context = this._initializeOnDelegatedTarget(event)
+ context._activeTrigger[event.type === 'focusout' ? TRIGGER_FOCUS : TRIGGER_HOVER] =
+ context._element.contains(event.relatedTarget)
+
+ context._leave()
+ })
}
}
@@ -510,63 +520,47 @@ class Tooltip extends BaseComponent {
}
}
- _enter(event, context) {
- context = this._initializeOnDelegatedTarget(event, context)
-
- if (event) {
- context._activeTrigger[
- event.type === 'focusin' ? TRIGGER_FOCUS : TRIGGER_HOVER
- ] = true
- }
-
- if (context.getTipElement().classList.contains(CLASS_NAME_SHOW) || context._hoverState === HOVER_STATE_SHOW) {
- context._hoverState = HOVER_STATE_SHOW
+ _enter() {
+ if (this.getTipElement().classList.contains(CLASS_NAME_SHOW) || this._hoverState === HOVER_STATE_SHOW) {
+ this._hoverState = HOVER_STATE_SHOW
return
}
- clearTimeout(context._timeout)
+ clearTimeout(this._timeout)
- context._hoverState = HOVER_STATE_SHOW
+ this._hoverState = HOVER_STATE_SHOW
- if (!context._config.delay.show) {
- context.show()
+ if (!this._config.delay.show) {
+ this.show()
return
}
- context._timeout = setTimeout(() => {
- if (context._hoverState === HOVER_STATE_SHOW) {
- context.show()
+ this._timeout = setTimeout(() => {
+ if (this._hoverState === HOVER_STATE_SHOW) {
+ this.show()
}
- }, context._config.delay.show)
+ }, this._config.delay.show)
}
- _leave(event, context) {
- context = this._initializeOnDelegatedTarget(event, context)
-
- if (event) {
- context._activeTrigger[
- event.type === 'focusout' ? TRIGGER_FOCUS : TRIGGER_HOVER
- ] = context._element.contains(event.relatedTarget)
- }
-
- if (context._isWithActiveTrigger()) {
+ _leave() {
+ if (this._isWithActiveTrigger()) {
return
}
- clearTimeout(context._timeout)
+ clearTimeout(this._timeout)
- context._hoverState = HOVER_STATE_OUT
+ this._hoverState = HOVER_STATE_OUT
- if (!context._config.delay.hide) {
- context.hide()
+ if (!this._config.delay.hide) {
+ this.hide()
return
}
- context._timeout = setTimeout(() => {
- if (context._hoverState === HOVER_STATE_OUT) {
- context.hide()
+ this._timeout = setTimeout(() => {
+ if (this._hoverState === HOVER_STATE_OUT) {
+ this.hide()
}
- }, context._config.delay.hide)
+ }, this._config.delay.hide)
}
_isWithActiveTrigger() {
diff --git a/js/tests/unit/tooltip.spec.js b/js/tests/unit/tooltip.spec.js
index d261986c37..7dff265b75 100644
--- a/js/tests/unit/tooltip.spec.js
+++ b/js/tests/unit/tooltip.spec.js
@@ -702,7 +702,7 @@ describe('Tooltip', () => {
expect(document.querySelectorAll('.tooltip')).toHaveSize(1)
done()
}, 200)
- }, 0)
+ }, 3)
tooltipEl.dispatchEvent(createEvent('mouseover'))
})
@@ -765,7 +765,7 @@ describe('Tooltip', () => {
expect(tooltip.getTipElement().getAttribute('data-popper-placement')).toEqual('top')
done()
}, 200)
- }, 0)
+ }, 3)
tooltipEl.dispatchEvent(createEvent('mouseover'))
})