aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJacob <[email protected]>2014-09-07 10:36:45 -0700
committerJacob <[email protected]>2014-09-07 10:36:45 -0700
commitc22b2705829f43ccd79f83c3e89d011a3cf5461f (patch)
treedbb444bd4ec64821f5c79c49150bf129012c13ec
parent9f5660c3e3b3d392529d07c4f2cfe0aba2abbe89 (diff)
parentaac0e16452301a4735a668dc228b6b084b2d63d0 (diff)
downloadbootstrap-c22b2705829f43ccd79f83c3e89d011a3cf5461f.tar.xz
bootstrap-c22b2705829f43ccd79f83c3e89d011a3cf5461f.zip
Merge pull request #14273 from sgonyea/master
Fix hover-popover/tooltip flickering when mouse re-enters
-rw-r--r--js/tests/unit/tooltip.js61
-rw-r--r--js/tooltip.js5
2 files changed, 66 insertions, 0 deletions
diff --git a/js/tests/unit/tooltip.js b/js/tests/unit/tooltip.js
index 7896c2c96..c0c628485 100644
--- a/js/tests/unit/tooltip.js
+++ b/js/tests/unit/tooltip.js
@@ -775,4 +775,65 @@ $(function () {
$circle.bootstrapTooltip('show')
})
+ test('should not reload the tooltip on subsequent mouseenter events', function () {
+ var titleHtml = function () {
+ var uid = $.fn.bootstrapTooltip.Constructor.prototype.getUID('tooltip')
+ return '<p id="tt-content">' + uid + '</p><p>' + uid + '</p><p>' + uid + '</p>'
+ }
+
+ var $tooltip = $('<span id="tt-outer" rel="tooltip" data-trigger="hover" data-placement="top">some text</span>')
+ .appendTo('#qunit-fixture')
+
+ $tooltip.bootstrapTooltip({
+ html: true,
+ animation: false,
+ trigger: 'hover',
+ delay: { show: 0, hide: 500 },
+ container: $tooltip,
+ title: titleHtml
+ })
+
+ $('#tt-outer').trigger('mouseenter')
+
+ var currentUid = $('#tt-content').text()
+
+ $('#tt-content').trigger('mouseenter')
+ equal(currentUid, $('#tt-content').text())
+ })
+
+ test('should not reload the tooltip if the mouse leaves and re-enters before hiding', function () {
+ var titleHtml = function () {
+ var uid = $.fn.bootstrapTooltip.Constructor.prototype.getUID('tooltip')
+ return '<p id="tt-content">' + uid + '</p><p>' + uid + '</p><p>' + uid + '</p>'
+ }
+
+ var $tooltip = $('<span id="tt-outer" rel="tooltip" data-trigger="hover" data-placement="top">some text</span>')
+ .appendTo('#qunit-fixture')
+
+ $tooltip.bootstrapTooltip({
+ html: true,
+ animation: false,
+ trigger: 'hover',
+ delay: { show: 0, hide: 500 },
+ container: $tooltip,
+ title: titleHtml
+ })
+
+ var obj = $tooltip.data('bs.tooltip')
+
+ $('#tt-outer').trigger('mouseenter')
+
+ var currentUid = $('#tt-content').text()
+
+ $('#tt-outer').trigger('mouseleave')
+ equal(currentUid, $('#tt-content').text())
+
+ ok(obj.hoverState == 'out', 'the tooltip hoverState should be set to "out"')
+
+ $('#tt-content').trigger('mouseenter')
+ ok(obj.hoverState == 'in', 'the tooltip hoverState should be set to "in"')
+
+ equal(currentUid, $('#tt-content').text())
+ })
+
})
diff --git a/js/tooltip.js b/js/tooltip.js
index e730db6e9..88ee49eac 100644
--- a/js/tooltip.js
+++ b/js/tooltip.js
@@ -105,6 +105,11 @@
var self = obj instanceof this.constructor ?
obj : $(obj.currentTarget).data('bs.' + this.type)
+ if (self && self.$tip && self.$tip.is(':visible')) {
+ self.hoverState = 'in'
+ return
+ }
+
if (!self) {
self = new this.constructor(obj.currentTarget, this.getDelegateOptions())
$(obj.currentTarget).data('bs.' + this.type, self)