]> git.ipfire.org Git - thirdparty/bootstrap.git/commitdiff
Move offset function logic to a private function.
authorJason Golieb <jgolieb@hortonworks.com>
Tue, 29 Jan 2019 19:56:38 +0000 (14:56 -0500)
committerXhmikosR <xhmikosr@gmail.com>
Tue, 5 Feb 2019 08:24:49 +0000 (10:24 +0200)
js/src/tooltip.js

index 0b6e21085f8f203d83ee19aa2aa69f0245b81ba8..7af07734047e273cfcd2dc8a69558fd127cee2ea 100644 (file)
@@ -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