diff options
| author | Jason Golieb <[email protected]> | 2019-01-29 14:56:38 -0500 |
|---|---|---|
| committer | XhmikosR <[email protected]> | 2019-02-05 10:24:49 +0200 |
| commit | 8f6cffde97d9ef0f41f11ed55578d736b9750e89 (patch) | |
| tree | b47cdec1aa4cc822a37bc30dcf162becb9a32509 | |
| parent | 88a34aacbee09417252c804f7cded926a496904a (diff) | |
| download | bootstrap-8f6cffde97d9ef0f41f11ed55578d736b9750e89.tar.xz bootstrap-8f6cffde97d9ef0f41f11ed55578d736b9750e89.zip | |
Move offset function logic to a private function.
| -rw-r--r-- | js/src/tooltip.js | 31 |
1 files changed, 20 insertions, 11 deletions
diff --git a/js/src/tooltip.js b/js/src/tooltip.js index 0b6e21085..7af077340 100644 --- a/js/src/tooltip.js +++ b/js/src/tooltip.js @@ -273,16 +273,6 @@ 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) @@ -295,7 +285,7 @@ class Tooltip { this._popper = new Popper(this.element, tip, { placement: attachment, modifiers: { - offset: offsetConf, + offset: this._getOffset(), flip: { behavior: this.config.fallbackPlacement }, @@ -458,6 +448,25 @@ class Tooltip { // 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() { if (this.config.container === false) { return document.body |
