From e9a7d26d0636445fb20def22db54fe703164031b Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?J=C3=B8rgen=20Borgesen?= <joergen.borgesen@gmail.com>
Date: Mon, 14 May 2012 14:03:36 +0200
Subject: [PATCH 1/3] Cancel running timer for tooltips with delayed show, but
 instant hide. This prevents delayed tooltips from appearing if the mouse
 leaves the elements before tooltip is showed and the hiding delay is 0.

---
 js/bootstrap-tooltip.js | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/js/bootstrap-tooltip.js b/js/bootstrap-tooltip.js
index 577ead48b5..4c2a2a328d 100644
--- a/js/bootstrap-tooltip.js
+++ b/js/bootstrap-tooltip.js
@@ -84,6 +84,7 @@
   , leave: function (e) {
       var self = $(e.currentTarget)[this.type](this._options).data(this.type)
 
+      if (this.timeout) clearTimeout(this.timeout)
       if (!self.options.delay || !self.options.delay.hide) return self.hide()
 
       clearTimeout(this.timeout)
@@ -272,4 +273,4 @@
   , delay: 0
   }
 
-}(window.jQuery);
\ No newline at end of file
+}(window.jQuery);
-- 
GitLab


From e388a5e475867cd266d58caf83b614aafe06cc10 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?J=C3=B8rgen=20Borgesen?= <joergen.borgesen@gmail.com>
Date: Sun, 20 May 2012 19:59:53 +0200
Subject: [PATCH 2/3] Added unit test to check that tooltips is not showed when
 leave event is triggered before show delay has expired AND the hide delay is
 set to 0

---
 js/bootstrap-tooltip.js            |  1 -
 js/tests/unit/bootstrap-tooltip.js | 21 ++++++++++++++++++++-
 2 files changed, 20 insertions(+), 2 deletions(-)

diff --git a/js/bootstrap-tooltip.js b/js/bootstrap-tooltip.js
index 4c2a2a328d..6ff2b47086 100644
--- a/js/bootstrap-tooltip.js
+++ b/js/bootstrap-tooltip.js
@@ -87,7 +87,6 @@
       if (this.timeout) clearTimeout(this.timeout)
       if (!self.options.delay || !self.options.delay.hide) return self.hide()
 
-      clearTimeout(this.timeout)
       self.hoverState = 'out'
       this.timeout = setTimeout(function() {
         if (self.hoverState == 'out') self.hide()
diff --git a/js/tests/unit/bootstrap-tooltip.js b/js/tests/unit/bootstrap-tooltip.js
index 63f4f0b07c..c25093420d 100644
--- a/js/tests/unit/bootstrap-tooltip.js
+++ b/js/tests/unit/bootstrap-tooltip.js
@@ -78,6 +78,25 @@ $(function () {
         }, 100)
       })
 
+      test("should not show tooltip if leave event occurs before delay expires, even if hide delay is 0", function () {
+        var tooltip = $('<a href="#" rel="tooltip" title="Another tooltip"></a>')
+          .appendTo('#qunit-fixture')
+          .tooltip({ delay: { show: 200, hide: 0} })
+
+        stop()
+
+        tooltip.trigger('mouseenter')
+
+        setTimeout(function () {
+          ok(!$(".tooltip").is('.fade.in'), 'tooltip is not faded in')
+          tooltip.trigger('mouseout')
+          setTimeout(function () {
+            ok(!$(".tooltip").is('.fade.in'), 'tooltip is not faded in')
+            start()
+          }, 200)
+        }, 100)
+      })
+
       test("should not show tooltip if leave event occurs before delay expires", function () {
         var tooltip = $('<a href="#" rel="tooltip" title="Another tooltip"></a>')
           .appendTo('#qunit-fixture')
@@ -133,4 +152,4 @@ $(function () {
         ok($.fn.tooltip.Constructor.prototype.isHTML($('<div></div>')), 'correctly detected html')
       })
 
-})
\ No newline at end of file
+})
-- 
GitLab


From 8dda83906d72ade81ecf9b21d55b5a2922589d30 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?J=C3=B8rgen=20Borgesen?= <joergen.borgesen@gmail.com>
Date: Sun, 20 May 2012 20:10:21 +0200
Subject: [PATCH 3/3] Swapped out .hasClass() with .is() when checking for
 multiple classes

---
 js/tests/unit/bootstrap-tooltip.js | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)

diff --git a/js/tests/unit/bootstrap-tooltip.js b/js/tests/unit/bootstrap-tooltip.js
index c25093420d..63a42b0d4d 100644
--- a/js/tests/unit/bootstrap-tooltip.js
+++ b/js/tests/unit/bootstrap-tooltip.js
@@ -33,7 +33,7 @@ $(function () {
           .tooltip({placement: 'bottom'})
           .tooltip('show')
 
-        ok($(".tooltip").hasClass('fade bottom in'), 'has correct classes applied')
+        ok($(".tooltip").is('.fade.bottom.in'), 'has correct classes applied')
         tooltip.tooltip('hide')
       })
 
@@ -69,10 +69,10 @@ $(function () {
         tooltip.trigger('mouseenter')
 
         setTimeout(function () {
-          ok(!$(".tooltip").hasClass('fade in'), 'tooltip is not faded in')
+          ok(!$(".tooltip").is('.fade.in'), 'tooltip is not faded in')
           tooltip.trigger('mouseout')
           setTimeout(function () {
-            ok(!$(".tooltip").hasClass('fade in'), 'tooltip is not faded in')
+            ok(!$(".tooltip").is('.fade.in'), 'tooltip is not faded in')
             start()
           }, 200)
         }, 100)
@@ -104,10 +104,10 @@ $(function () {
         stop()
         tooltip.trigger('mouseenter')
         setTimeout(function () {
-          ok(!$(".tooltip").hasClass('fade in'), 'tooltip is not faded in')
+          ok(!$(".tooltip").is('.fade.in'), 'tooltip is not faded in')
           tooltip.trigger('mouseout')
           setTimeout(function () {
-            ok(!$(".tooltip").hasClass('fade in'), 'tooltip is not faded in')
+            ok(!$(".tooltip").is('.fade.in'), 'tooltip is not faded in')
             start()
           }, 100)
         }, 50)
@@ -120,9 +120,9 @@ $(function () {
         stop()
         tooltip.trigger('mouseenter')
         setTimeout(function () {
-          ok(!$(".tooltip").hasClass('fade in'), 'tooltip is not faded in')
+          ok(!$(".tooltip").is('.fade.in'), 'tooltip is not faded in')
           setTimeout(function () {
-            ok(!$(".tooltip").hasClass('fade in'), 'tooltip has faded in')
+            ok(!$(".tooltip").is('.fade.in'), 'tooltip has faded in')
             start()
           }, 200)
         }, 100)
-- 
GitLab