]> git.ipfire.org Git - thirdparty/bootstrap.git/commitdiff
use one private method to resolve string or function
authorGeoSot <geo.sotis@gmail.com>
Thu, 10 Jun 2021 07:55:34 +0000 (10:55 +0300)
committerXhmikosR <xhmikosr@gmail.com>
Thu, 22 Jul 2021 14:20:38 +0000 (17:20 +0300)
js/src/popover.js
js/src/tooltip.js

index a08e4c4dd4bdc63b552333016c705c14feb70950..5ef127b8af2edf1deb04bc767a5df5d97edee2b7 100644 (file)
@@ -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() {
index 6dc7a0350d3609693e66830930bd0122b1ab5ec3..5746ec6baff04c0f1eba4d40def1e62119c5a38a 100644 (file)
@@ -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,