]> git.ipfire.org Git - thirdparty/bootstrap.git/commitdiff
Tooltip: merge timeout functionality
authorGeoSot <geo.sotis@gmail.com>
Sun, 28 Nov 2021 01:58:59 +0000 (03:58 +0200)
committerXhmikosR <xhmikosr@gmail.com>
Wed, 1 Dec 2021 16:00:36 +0000 (18:00 +0200)
js/src/tooltip.js

index 645a6b7e28fb8e2283718f9233af42e30b900acc..35abd29442ffb7a34cf717c0c0ec8d4fbc6e993f 100644 (file)
@@ -526,16 +526,9 @@ class Tooltip extends BaseComponent {
       return
     }
 
-    clearTimeout(this._timeout)
-
     this._hoverState = HOVER_STATE_SHOW
 
-    if (!this._config.delay.show) {
-      this.show()
-      return
-    }
-
-    this._timeout = setTimeout(() => {
+    this._setTimeout(() => {
       if (this._hoverState === HOVER_STATE_SHOW) {
         this.show()
       }
@@ -547,22 +540,20 @@ class Tooltip extends BaseComponent {
       return
     }
 
-    clearTimeout(this._timeout)
-
     this._hoverState = HOVER_STATE_OUT
 
-    if (!this._config.delay.hide) {
-      this.hide()
-      return
-    }
-
-    this._timeout = setTimeout(() => {
+    this._setTimeout(() => {
       if (this._hoverState === HOVER_STATE_OUT) {
         this.hide()
       }
     }, this._config.delay.hide)
   }
 
+  _setTimeout(handler, timeout) {
+    clearTimeout(this._timeout)
+    this._timeout = setTimeout(handler, timeout)
+  }
+
   _isWithActiveTrigger() {
     return Object.values(this._activeTrigger).includes(true)
   }