1
0
mirror of https://github.com/twbs/bootstrap.git synced 2025-09-26 05:19:15 +02:00

Add support for tooltip offset option to be a function.

This commit is contained in:
Jason Golieb
2019-01-28 22:55:21 +02:00
committed by XhmikosR
parent 1accd37aa0
commit 88a34aacbe
3 changed files with 55 additions and 6 deletions

View File

@@ -32,7 +32,7 @@ const DefaultType = {
html : 'boolean',
selector : '(string|boolean)',
placement : '(string|function)',
offset : '(number|string)',
offset : '(number|string|function)',
container : '(string|element|boolean)',
fallbackPlacement : '(string|array)',
boundary : '(string|element)'
@@ -273,6 +273,16 @@ class Tooltip {
const attachment = this._getAttachment(placement)
this.addAttachmentClass(attachment)
const offsetConf = {}
if (typeof this.config.offset === 'function') {
offsetConf.fn = (data) => {
data.offsets = $.extend({}, data.offsets, this.config.offset(data.offsets, this.element) || {})
return data
}
} else {
offsetConf.offset = this.config.offset
}
const container = this._getContainer()
$(tip).data(this.constructor.DATA_KEY, this)
@@ -285,9 +295,7 @@ class Tooltip {
this._popper = new Popper(this.element, tip, {
placement: attachment,
modifiers: {
offset: {
offset: this.config.offset
},
offset: offsetConf,
flip: {
behavior: this.config.fallbackPlacement
},