From 688bce4fa695cc360a0d084e34f029b0c192b223 Mon Sep 17 00:00:00 2001 From: XhmikosR Date: Tue, 22 Jun 2021 21:29:16 +0300 Subject: Release v5.0.2 (#34276) * Bump version to v5.0.2. * Dist --- js/src/tooltip.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'js/src/tooltip.js') diff --git a/js/src/tooltip.js b/js/src/tooltip.js index 78b7c478b..cd4a2878e 100644 --- a/js/src/tooltip.js +++ b/js/src/tooltip.js @@ -1,6 +1,6 @@ /** * -------------------------------------------------------------------------- - * Bootstrap (v5.0.1): tooltip.js + * Bootstrap (v5.0.2): tooltip.js * Licensed under MIT (https://github.com/twbs/bootstrap/blob/main/LICENSE) * -------------------------------------------------------------------------- */ -- cgit v1.2.3 From c4e189df40ffced65848d440e8e95892360445ba Mon Sep 17 00:00:00 2001 From: GeoSot Date: Thu, 10 Jun 2021 10:48:35 +0300 Subject: use a class private getter to decouple same methods usage --- js/src/tooltip.js | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'js/src/tooltip.js') diff --git a/js/src/tooltip.js b/js/src/tooltip.js index cd4a2878e..cdc9b1e5d 100644 --- a/js/src/tooltip.js +++ b/js/src/tooltip.js @@ -37,7 +37,6 @@ const NAME = 'tooltip' const DATA_KEY = 'bs.tooltip' const EVENT_KEY = `.${DATA_KEY}` const CLASS_PREFIX = 'bs-tooltip' -const BSCLS_PREFIX_REGEX = new RegExp(`(^|\\s)${CLASS_PREFIX}\\S+`, 'g') const DISALLOWED_ATTRIBUTES = new Set(['sanitize', 'allowList', 'sanitizeFn']) const DefaultType = { @@ -514,7 +513,7 @@ class Tooltip extends BaseComponent { } _addAttachmentClass(attachment) { - this.getTipElement().classList.add(`${CLASS_PREFIX}-${this.updateAttachment(attachment)}`) + this.getTipElement().classList.add(`${this._getBasicClassPrefix()}-${this.updateAttachment(attachment)}`) } _getAttachment(placement) { @@ -699,13 +698,18 @@ class Tooltip extends BaseComponent { _cleanTipClass() { const tip = this.getTipElement() - const tabClass = tip.getAttribute('class').match(BSCLS_PREFIX_REGEX) + const basicClassPrefixRegex = new RegExp(`(^|\\s)${this._getBasicClassPrefix()}\\S+`, 'g') + const tabClass = tip.getAttribute('class').match(basicClassPrefixRegex) if (tabClass !== null && tabClass.length > 0) { tabClass.map(token => token.trim()) .forEach(tClass => tip.classList.remove(tClass)) } } + _getBasicClassPrefix() { + return CLASS_PREFIX + } + _handlePopperPlacementChange(popperData) { const { state } = popperData -- cgit v1.2.3 From 92c7056619293a581626c37ef2c0095c6f1abceb Mon Sep 17 00:00:00 2001 From: GeoSot Date: Thu, 10 Jun 2021 10:52:35 +0300 Subject: `_getDelegateConfig()`: add a comment and remove an unneeded config check --- js/src/tooltip.js | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) (limited to 'js/src/tooltip.js') diff --git a/js/src/tooltip.js b/js/src/tooltip.js index cdc9b1e5d..d69a80e27 100644 --- a/js/src/tooltip.js +++ b/js/src/tooltip.js @@ -685,14 +685,15 @@ class Tooltip extends BaseComponent { _getDelegateConfig() { const config = {} - if (this._config) { - for (const key in this._config) { - if (this.constructor.Default[key] !== this._config[key]) { - config[key] = this._config[key] - } + for (const key in this._config) { + if (this.constructor.Default[key] !== this._config[key]) { + config[key] = this._config[key] } } + // 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)` return config } -- cgit v1.2.3 From 3716603dbc3dc1b612c4ef6c83860195312f2532 Mon Sep 17 00:00:00 2001 From: GeoSot Date: Thu, 10 Jun 2021 10:53:59 +0300 Subject: Use `getOrCreateInstance` on `_initializeOnDelegatedTarget` --- js/src/tooltip.js | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) (limited to 'js/src/tooltip.js') diff --git a/js/src/tooltip.js b/js/src/tooltip.js index d69a80e27..6dc7a0350 100644 --- a/js/src/tooltip.js +++ b/js/src/tooltip.js @@ -439,15 +439,7 @@ class Tooltip extends BaseComponent { // Private _initializeOnDelegatedTarget(event, context) { - const dataKey = this.constructor.DATA_KEY - context = context || Data.get(event.delegateTarget, dataKey) - - if (!context) { - context = new this.constructor(event.delegateTarget, this._getDelegateConfig()) - Data.set(event.delegateTarget, dataKey, context) - } - - return context + return context || this.constructor.getOrCreateInstance(event.delegateTarget, this._getDelegateConfig()) } _getOffset() { -- cgit v1.2.3 From a97fd1cd2420a4c07589689593385484bd38fb50 Mon Sep 17 00:00:00 2001 From: GeoSot Date: Thu, 10 Jun 2021 10:55:34 +0300 Subject: use one private method to resolve string or function --- js/src/tooltip.js | 21 ++++++++------------- 1 file changed, 8 insertions(+), 13 deletions(-) (limited to 'js/src/tooltip.js') diff --git a/js/src/tooltip.js b/js/src/tooltip.js index 6dc7a0350..5746ec6ba 100644 --- a/js/src/tooltip.js +++ b/js/src/tooltip.js @@ -17,10 +17,7 @@ import { noop, typeCheckConfig } from './util/index' -import { - DefaultAllowlist, - sanitizeHtml -} from './util/sanitizer' +import { DefaultAllowlist, sanitizeHtml } from './util/sanitizer' import Data from './dom/data' import EventHandler from './dom/event-handler' import Manipulator from './dom/manipulator' @@ -272,7 +269,7 @@ class Tooltip extends BaseComponent { tip.classList.add(CLASS_NAME_SHOW) - const customClass = typeof this._config.customClass === 'function' ? this._config.customClass() : this._config.customClass + const customClass = this._resolvePossibleFunction(this._config.customClass) if (customClass) { tip.classList.add(...customClass.split(' ')) } @@ -413,15 +410,9 @@ class Tooltip extends BaseComponent { } getTitle() { - let title = this._element.getAttribute('data-bs-original-title') - - if (!title) { - title = typeof this._config.title === 'function' ? - this._config.title.call(this._element) : - this._config.title - } + const title = this._element.getAttribute('data-bs-original-title') || this._config.title - return title + return this._resolvePossibleFunction(title) } updateAttachment(attachment) { @@ -456,6 +447,10 @@ class Tooltip extends BaseComponent { return offset } + _resolvePossibleFunction(content) { + return typeof content === 'function' ? content.call(this._element) : content + } + _getPopperConfig(attachment) { const defaultBsPopperConfig = { placement: attachment, -- cgit v1.2.3 From 9c3ceaa25b0fcb9b5bd9ff688235e4f3b741026a Mon Sep 17 00:00:00 2001 From: GeoSot Date: Thu, 10 Jun 2021 10:58:41 +0300 Subject: popover: Move common code in tooltip's `getTipElement()` --- js/src/tooltip.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'js/src/tooltip.js') diff --git a/js/src/tooltip.js b/js/src/tooltip.js index 5746ec6ba..fa364a1e6 100644 --- a/js/src/tooltip.js +++ b/js/src/tooltip.js @@ -367,7 +367,10 @@ class Tooltip extends BaseComponent { const element = document.createElement('div') element.innerHTML = this._config.template - this.tip = element.children[0] + const tip = element.children[0] + tip.classList.remove(CLASS_NAME_FADE, CLASS_NAME_SHOW) + + this.tip = tip return this.tip } -- cgit v1.2.3 From da2db218edfc0746c169b567e6a13c9f8e945dda Mon Sep 17 00:00:00 2001 From: GeoSot Date: Thu, 10 Jun 2021 11:00:05 +0300 Subject: Use on private method to set content & cleanup template --- js/src/tooltip.js | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) (limited to 'js/src/tooltip.js') diff --git a/js/src/tooltip.js b/js/src/tooltip.js index fa364a1e6..e09a53b5c 100644 --- a/js/src/tooltip.js +++ b/js/src/tooltip.js @@ -376,8 +376,18 @@ class Tooltip extends BaseComponent { setContent() { const tip = this.getTipElement() - this.setElementContent(SelectorEngine.findOne(SELECTOR_TOOLTIP_INNER, tip), this.getTitle()) - tip.classList.remove(CLASS_NAME_FADE, CLASS_NAME_SHOW) + this._sanitizeAndSetContent(tip, this.getTitle(), SELECTOR_TOOLTIP_INNER) + } + + _sanitizeAndSetContent(template, content, selector) { + const templateElement = SelectorEngine.findOne(selector, template) + if (!content) { + templateElement.remove() + return + } + + // we use append for html objects to maintain js events + this.setElementContent(templateElement, content) } setElementContent(element, content) { -- cgit v1.2.3