diff options
author | GeoSot <geo.sotis@gmail.com> | 2021-11-25 21:08:11 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-11-25 21:08:11 +0300 |
commit | 6f077ff7bcf5c3e8a9cd579e26a2325ce32543c9 (patch) | |
tree | d5724e70a005c3e44c0255758d3f973ba84a75db /js/src/tooltip.js | |
parent | 374eeecfbcabae20da08ce00d0f9268bb67b1e5e (diff) |
Clean tooltip component unneeded functionality (#32692)
Diffstat (limited to 'js/src/tooltip.js')
-rw-r--r-- | js/src/tooltip.js | 63 |
1 files changed, 7 insertions, 56 deletions
diff --git a/js/src/tooltip.js b/js/src/tooltip.js index bc59e6e946..29be4d8d26 100644 --- a/js/src/tooltip.js +++ b/js/src/tooltip.js @@ -29,7 +29,6 @@ import TemplateFactory from './util/template-factory' const NAME = 'tooltip' const DATA_KEY = 'bs.tooltip' const EVENT_KEY = `.${DATA_KEY}` -const CLASS_PREFIX = 'bs-tooltip' const DISALLOWED_ATTRIBUTES = new Set(['sanitize', 'allowList', 'sanitizeFn']) const CLASS_NAME_FADE = 'fade' @@ -232,13 +231,6 @@ class Tooltip extends BaseComponent { this._element.setAttribute('aria-describedby', tip.getAttribute('id')) - const placement = typeof this._config.placement === 'function' ? - this._config.placement.call(this, tip, this._element) : - this._config.placement - - const attachment = this._getAttachment(placement) - this._addAttachmentClass(attachment) - const { container } = this._config Data.set(tip, this.constructor.DATA_KEY, this) @@ -250,6 +242,10 @@ class Tooltip extends BaseComponent { if (this._popper) { this._popper.update() } else { + const placement = typeof this._config.placement === 'function' ? + this._config.placement.call(this, tip, this._element) : + this._config.placement + const attachment = AttachmentMap[placement.toUpperCase()] this._popper = Popper.createPopper(this._element, tip, this._getPopperConfig(attachment)) } @@ -295,7 +291,6 @@ class Tooltip extends BaseComponent { tip.remove() } - this._cleanTipClass() this._element.removeAttribute('aria-describedby') EventHandler.trigger(this._element, this.constructor.Event.HIDDEN) @@ -346,6 +341,8 @@ class Tooltip extends BaseComponent { const tip = templateFactory.toHtml() tip.classList.remove(CLASS_NAME_FADE, CLASS_NAME_SHOW) + // todo on v6 the following can be done on css only + tip.classList.add(`bs-${this.constructor.NAME}-auto`) const tipId = getUID(this.constructor.NAME).toString() @@ -463,19 +460,8 @@ class Tooltip extends BaseComponent { options: { element: SELECTOR_TOOLTIP_ARROW } - }, - { - name: 'onChange', - enabled: true, - phase: 'afterWrite', - fn: data => this._handlePopperPlacementChange(data) - } - ], - onFirstUpdate: data => { - if (data.options.placement !== data.placement) { - this._handlePopperPlacementChange(data) } - } + ] } return { @@ -484,14 +470,6 @@ class Tooltip extends BaseComponent { } } - _addAttachmentClass(attachment) { - this.getTipElement().classList.add(`${this._getBasicClassPrefix()}-${this.updateAttachment(attachment)}`) - } - - _getAttachment(placement) { - return AttachmentMap[placement.toUpperCase()] - } - _setListeners() { const triggers = this._config.trigger.split(' ') @@ -652,33 +630,6 @@ class Tooltip extends BaseComponent { return config } - _cleanTipClass() { - const tip = this.getTipElement() - const basicClassPrefixRegex = new RegExp(`(^|\\s)${this._getBasicClassPrefix()}\\S+`, 'g') - const tabClass = tip.getAttribute('class').match(basicClassPrefixRegex) - if (tabClass !== null && tabClass.length > 0) { - for (const tClass of tabClass.map(token => token.trim())) { - tip.classList.remove(tClass) - } - } - } - - _getBasicClassPrefix() { - return CLASS_PREFIX - } - - _handlePopperPlacementChange(popperData) { - const { state } = popperData - - if (!state) { - return - } - - this.tip = state.elements.popper - this._cleanTipClass() - this._addAttachmentClass(this._getAttachment(state.placement)) - } - _disposePopper() { if (this._popper) { this._popper.destroy() |