mirror of
https://github.com/twbs/bootstrap.git
synced 2025-09-26 05:19:15 +02:00
Move offset function logic to a private function.
This commit is contained in:
@@ -273,16 +273,6 @@ class Tooltip {
|
|||||||
const attachment = this._getAttachment(placement)
|
const attachment = this._getAttachment(placement)
|
||||||
this.addAttachmentClass(attachment)
|
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()
|
const container = this._getContainer()
|
||||||
$(tip).data(this.constructor.DATA_KEY, this)
|
$(tip).data(this.constructor.DATA_KEY, this)
|
||||||
|
|
||||||
@@ -295,7 +285,7 @@ class Tooltip {
|
|||||||
this._popper = new Popper(this.element, tip, {
|
this._popper = new Popper(this.element, tip, {
|
||||||
placement: attachment,
|
placement: attachment,
|
||||||
modifiers: {
|
modifiers: {
|
||||||
offset: offsetConf,
|
offset: this._getOffset(),
|
||||||
flip: {
|
flip: {
|
||||||
behavior: this.config.fallbackPlacement
|
behavior: this.config.fallbackPlacement
|
||||||
},
|
},
|
||||||
@@ -458,6 +448,25 @@ class Tooltip {
|
|||||||
|
|
||||||
// Private
|
// Private
|
||||||
|
|
||||||
|
_getOffset() {
|
||||||
|
const offset = {}
|
||||||
|
|
||||||
|
if (typeof this.config.offset === 'function') {
|
||||||
|
offset.fn = (data) => {
|
||||||
|
data.offsets = {
|
||||||
|
...data.offsets,
|
||||||
|
...this.config.offset(data.offsets, this.element) || {}
|
||||||
|
}
|
||||||
|
|
||||||
|
return data
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
offset.offset = this.config.offset
|
||||||
|
}
|
||||||
|
|
||||||
|
return offset
|
||||||
|
}
|
||||||
|
|
||||||
_getContainer() {
|
_getContainer() {
|
||||||
if (this.config.container === false) {
|
if (this.config.container === false) {
|
||||||
return document.body
|
return document.body
|
||||||
|
Reference in New Issue
Block a user