diff options
Diffstat (limited to 'vendor/twbs/bootstrap/js/src/tooltip.js')
-rw-r--r-- | vendor/twbs/bootstrap/js/src/tooltip.js | 62 |
1 files changed, 36 insertions, 26 deletions
diff --git a/vendor/twbs/bootstrap/js/src/tooltip.js b/vendor/twbs/bootstrap/js/src/tooltip.js index e01f0a4ae..54ec0367e 100644 --- a/vendor/twbs/bootstrap/js/src/tooltip.js +++ b/vendor/twbs/bootstrap/js/src/tooltip.js @@ -1,6 +1,6 @@ /** * -------------------------------------------------------------------------- - * Bootstrap (v5.2.2): tooltip.js + * Bootstrap (v5.2.0): tooltip.js * Licensed under MIT (https://github.com/twbs/bootstrap/blob/main/LICENSE) * -------------------------------------------------------------------------- */ @@ -111,7 +111,7 @@ class Tooltip extends BaseComponent { // Private this._isEnabled = true this._timeout = 0 - this._isHovered = null + this._isHovered = false this._activeTrigger = {} this._popper = null this._templateFactory = null @@ -121,10 +121,6 @@ class Tooltip extends BaseComponent { this.tip = null this._setListeners() - - if (!this._config.selector) { - this._fixTitle() - } } // Getters @@ -153,12 +149,25 @@ class Tooltip extends BaseComponent { this._isEnabled = !this._isEnabled } - toggle() { + toggle(event) { if (!this._isEnabled) { return } - this._activeTrigger.click = !this._activeTrigger.click + if (event) { + const context = this._initializeOnDelegatedTarget(event) + + context._activeTrigger.click = !context._activeTrigger.click + + if (context._isWithActiveTrigger()) { + context._enter() + } else { + context._leave() + } + + return + } + if (this._isShown()) { this._leave() return @@ -176,10 +185,6 @@ class Tooltip extends BaseComponent { this.tip.remove() } - if (this._element.getAttribute('data-bs-original-title')) { - this._element.setAttribute('title', this._element.getAttribute('data-bs-original-title')) - } - this._disposePopper() super.dispose() } @@ -237,13 +242,14 @@ class Tooltip extends BaseComponent { } const complete = () => { + const previousHoverState = this._isHovered + + this._isHovered = false EventHandler.trigger(this._element, this.constructor.eventName(EVENT_SHOWN)) - if (this._isHovered === false) { + if (previousHoverState) { this._leave() } - - this._isHovered = false } this._queueCallback(complete, this.tip, this._isAnimated()) @@ -273,7 +279,7 @@ class Tooltip extends BaseComponent { this._activeTrigger[TRIGGER_CLICK] = false this._activeTrigger[TRIGGER_FOCUS] = false this._activeTrigger[TRIGGER_HOVER] = false - this._isHovered = null // it is a trick to support manual triggering + this._isHovered = false const complete = () => { if (this._isWithActiveTrigger()) { @@ -366,7 +372,7 @@ class Tooltip extends BaseComponent { } _getTitle() { - return this._resolvePossibleFunction(this._config.title) || this._element.getAttribute('data-bs-original-title') + return this._resolvePossibleFunction(this._config.title) || this._config.originalTitle } // Private @@ -460,10 +466,7 @@ class Tooltip extends BaseComponent { for (const trigger of triggers) { if (trigger === 'click') { - EventHandler.on(this._element, this.constructor.eventName(EVENT_CLICK), this._config.selector, event => { - const context = this._initializeOnDelegatedTarget(event) - context.toggle() - }) + EventHandler.on(this._element, this.constructor.eventName(EVENT_CLICK), this._config.selector, event => this.toggle(event)) } else if (trigger !== TRIGGER_MANUAL) { const eventIn = trigger === TRIGGER_HOVER ? this.constructor.eventName(EVENT_MOUSEENTER) : @@ -494,10 +497,20 @@ class Tooltip extends BaseComponent { } EventHandler.on(this._element.closest(SELECTOR_MODAL), EVENT_MODAL_HIDE, this._hideModalHandler) + + if (this._config.selector) { + this._config = { + ...this._config, + trigger: 'manual', + selector: '' + } + } else { + this._fixTitle() + } } _fixTitle() { - const title = this._element.getAttribute('title') + const title = this._config.originalTitle if (!title) { return @@ -507,7 +520,6 @@ class Tooltip extends BaseComponent { this._element.setAttribute('aria-label', title) } - this._element.setAttribute('data-bs-original-title', title) // DO NOT USE IT. Is only for backwards compatibility this._element.removeAttribute('title') } @@ -578,6 +590,7 @@ class Tooltip extends BaseComponent { } } + config.originalTitle = this._element.getAttribute('title') || '' if (typeof config.title === 'number') { config.title = config.title.toString() } @@ -598,9 +611,6 @@ class Tooltip extends BaseComponent { } } - config.selector = false - config.trigger = 'manual' - // In the future can be replaced with: // const keysWithDifferentValues = Object.entries(this._config).filter(entry => this.constructor.Default[entry[0]] !== this._config[entry[0]]) // `Object.fromEntries(keysWithDifferentValues)` |