aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGeoSot <[email protected]>2021-06-10 10:55:34 +0300
committerXhmikosR <[email protected]>2021-07-22 17:20:38 +0300
commita97fd1cd2420a4c07589689593385484bd38fb50 (patch)
tree71bb6a2564c7b6d392a39ed725dda0248238bb35
parent3716603dbc3dc1b612c4ef6c83860195312f2532 (diff)
downloadbootstrap-a97fd1cd2420a4c07589689593385484bd38fb50.tar.xz
bootstrap-a97fd1cd2420a4c07589689593385484bd38fb50.zip
use one private method to resolve string or function
-rw-r--r--js/src/popover.js2
-rw-r--r--js/src/tooltip.js21
2 files changed, 9 insertions, 14 deletions
diff --git a/js/src/popover.js b/js/src/popover.js
index a08e4c4dd..5ef127b8a 100644
--- a/js/src/popover.js
+++ b/js/src/popover.js
@@ -124,7 +124,7 @@ class Popover extends Tooltip {
// Private
_getContent() {
- return this._element.getAttribute('data-bs-content') || this._config.content
+ return this._resolvePossibleFunction(this._config.content)
}
_getBasicClassPrefix() {
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,