aboutsummaryrefslogtreecommitdiff
path: root/js/src
diff options
context:
space:
mode:
Diffstat (limited to 'js/src')
-rw-r--r--js/src/dropdown.js3
-rw-r--r--js/src/tooltip.js10
-rw-r--r--js/src/util/index.js6
-rw-r--r--js/src/util/template-factory.js4
4 files changed, 10 insertions, 13 deletions
diff --git a/js/src/dropdown.js b/js/src/dropdown.js
index b05d92cf7..d37886d89 100644
--- a/js/src/dropdown.js
+++ b/js/src/dropdown.js
@@ -8,6 +8,7 @@
import * as Popper from '@popperjs/core'
import {
defineJQueryPlugin,
+ execute,
getElement,
getNextActiveElement,
isDisabled,
@@ -319,7 +320,7 @@ class Dropdown extends BaseComponent {
return {
...defaultBsPopperConfig,
- ...(typeof this._config.popperConfig === 'function' ? this._config.popperConfig(defaultBsPopperConfig) : this._config.popperConfig)
+ ...execute(this._config.popperConfig, [defaultBsPopperConfig])
}
}
diff --git a/js/src/tooltip.js b/js/src/tooltip.js
index 70198c81b..a3f3377c0 100644
--- a/js/src/tooltip.js
+++ b/js/src/tooltip.js
@@ -6,7 +6,7 @@
*/
import * as Popper from '@popperjs/core'
-import { defineJQueryPlugin, findShadowRoot, getElement, getUID, isRTL, noop } from './util/index'
+import { defineJQueryPlugin, execute, findShadowRoot, getElement, getUID, isRTL, noop } from './util/index'
import { DefaultAllowlist } from './util/sanitizer'
import EventHandler from './dom/event-handler'
import Manipulator from './dom/manipulator'
@@ -370,9 +370,7 @@ class Tooltip extends BaseComponent {
}
_createPopper(tip) {
- const placement = typeof this._config.placement === 'function' ?
- this._config.placement.call(this, tip, this._element) :
- this._config.placement
+ const placement = execute(this._config.placement, [this, tip, this._element])
const attachment = AttachmentMap[placement.toUpperCase()]
return Popper.createPopper(this._element, tip, this._getPopperConfig(attachment))
}
@@ -392,7 +390,7 @@ class Tooltip extends BaseComponent {
}
_resolvePossibleFunction(arg) {
- return typeof arg === 'function' ? arg.call(this._element) : arg
+ return execute(arg, [this._element])
}
_getPopperConfig(attachment) {
@@ -438,7 +436,7 @@ class Tooltip extends BaseComponent {
return {
...defaultBsPopperConfig,
- ...(typeof this._config.popperConfig === 'function' ? this._config.popperConfig(defaultBsPopperConfig) : this._config.popperConfig)
+ ...execute(this._config.popperConfig, [defaultBsPopperConfig])
}
}
diff --git a/js/src/util/index.js b/js/src/util/index.js
index 7c2411665..ad99f85ed 100644
--- a/js/src/util/index.js
+++ b/js/src/util/index.js
@@ -249,10 +249,8 @@ const defineJQueryPlugin = plugin => {
})
}
-const execute = callback => {
- if (typeof callback === 'function') {
- callback()
- }
+const execute = (possibleCallback, args = [], defaultValue = possibleCallback) => {
+ return typeof possibleCallback === 'function' ? possibleCallback(...args) : defaultValue
}
const executeAfterTransition = (callback, transitionElement, waitForTransition = true) => {
diff --git a/js/src/util/template-factory.js b/js/src/util/template-factory.js
index c6d52a50d..16ec6c28d 100644
--- a/js/src/util/template-factory.js
+++ b/js/src/util/template-factory.js
@@ -6,7 +6,7 @@
*/
import { DefaultAllowlist, sanitizeHtml } from './sanitizer'
-import { getElement, isElement } from '../util/index'
+import { execute, getElement, isElement } from '../util/index'
import SelectorEngine from '../dom/selector-engine'
import Config from './config'
@@ -143,7 +143,7 @@ class TemplateFactory extends Config {
}
_resolvePossibleFunction(arg) {
- return typeof arg === 'function' ? arg(this) : arg
+ return execute(arg, [this])
}
_putElementInTemplate(element, templateElement) {