From 4d9890ea2e7e868221d0c2254c9dc86152304815 Mon Sep 17 00:00:00 2001 From: Chris Rebert Date: Mon, 15 Sep 2014 12:36:40 -0700 Subject: Use container instead of parent for tooltip/popover auto-placement calcs Fixes #14561. Big thanks to @wickstargazer. [skip validator] --- js/tests/unit/tooltip.js | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) (limited to 'js/tests') diff --git a/js/tests/unit/tooltip.js b/js/tests/unit/tooltip.js index fd02a5e7f..78ea7a81b 100644 --- a/js/tests/unit/tooltip.js +++ b/js/tests/unit/tooltip.js @@ -827,6 +827,47 @@ $(function () { $circle.bootstrapTooltip('show') }) + test('should correctly determine auto placement based on container rather than parent', function () { + stop() + + var styles = '' + var $styles = $(styles).appendTo('head') + + $('#qunit-fixture').append('HOVER OVER ME') + var $trigger = $('#tt-trigger') + + $trigger + .on('shown.bs.tooltip', function () { + var $tip = $('.tooltip-inner') + var tipXrightEdge = $tip.offset().left + $tip.width() + var triggerXleftEdge = $trigger.offset().left + ok(tipXrightEdge < triggerXleftEdge, 'tooltip with auto left placement, when near the right edge of the viewport, gets left placement') + $trigger.bootstrapTooltip('hide') + }) + .on('hidden.bs.tooltip', function () { + $styles.remove() + $(this).remove() + equal($('.tooltip').length, 0, 'tooltip removed from dom') + start() + }) + .bootstrapTooltip({ + container: 'body', + placement: 'auto left', + trigger: 'manual' + }) + + $trigger.bootstrapTooltip('show') + }) + test('should not reload the tooltip on subsequent mouseenter events', function () { var titleHtml = function () { var uid = $.fn.bootstrapTooltip.Constructor.prototype.getUID('tooltip') @@ -909,6 +950,7 @@ $(function () { .on('hidden.bs.tooltip', function () { $styles.remove() $(this).remove() + equal($('.tooltip').length, 0, 'tooltip removed from dom') start() }) .bootstrapTooltip({ -- cgit v1.2.3