From e2cfbd5f2df12cb207a66663925f5ee7e5cb2320 Mon Sep 17 00:00:00 2001 From: "saranya.r" Date: Fri, 10 Oct 2014 11:49:45 +0530 Subject: [PATCH] Fixes tooltip misplacements in scrollable viewports with auto positioning Fixes #14756. Closes #14767. --- js/tests/unit/tooltip.js | 104 +++++++++++++++++++++++++++++++++++++++ js/tooltip.js | 8 +-- 2 files changed, 108 insertions(+), 4 deletions(-) diff --git a/js/tests/unit/tooltip.js b/js/tests/unit/tooltip.js index 3eb3c7b85c..7b5f8adf72 100644 --- a/js/tests/unit/tooltip.js +++ b/js/tests/unit/tooltip.js @@ -432,6 +432,110 @@ $(function () { $styles.remove() }) + test('should display the tip on top whenever scrollable viewport has enough room if the given placement is "auto top"', function () { + var styles = '' + var $styles = $(styles).appendTo('head') + + var $container = $('
').appendTo('#qunit-fixture') + var $target = $('
Tooltip Item
') + .appendTo($container) + .bootstrapTooltip({ + placement: 'top auto', + viewport: '#scrollable-div' + }) + + $('#scrollable-div').scrollTop(100) + + $target.bootstrapTooltip('show') + ok($('.tooltip').is('.fade.top.in'), 'has correct classes applied') + + $target.bootstrapTooltip('hide') + equal($('.tooltip').length, 0, 'tooltip removed from dom') + + $styles.remove() + }) + + test('should display the tip on bottom whenever scrollable viewport doesn\'t have enough room if the given placement is "auto top"', function () { + var styles = '' + var $styles = $(styles).appendTo('head') + + var $container = $('
').appendTo('#qunit-fixture') + var $target = $('
Tooltip Item
') + .appendTo($container) + .bootstrapTooltip({ + placement: 'top auto', + viewport: '#scrollable-div' + }) + + $('#scrollable-div').scrollTop(200) + + $target.bootstrapTooltip('show') + ok($('.tooltip').is('.fade.bottom.in'), 'has correct classes applied') + + $target.bootstrapTooltip('hide') + equal($('.tooltip').length, 0, 'tooltip removed from dom') + + $styles.remove() + }) + + test('should display the tip on bottom whenever scrollable viewport has enough room if the given placement is "auto bottom"', function () { + var styles = '' + var $styles = $(styles).appendTo('head') + + var $container = $('
').appendTo('#qunit-fixture') + var $target = $('
Tooltip Item
') + .appendTo($container) + .bootstrapTooltip({ + placement: 'bottom auto', + viewport: '#scrollable-div' + }) + + $('#scrollable-div').scrollTop(200) + + $target.bootstrapTooltip('show') + ok($('.tooltip').is('.fade.bottom.in'), 'has correct classes applied') + + $target.bootstrapTooltip('hide') + equal($('.tooltip').length, 0, 'tooltip removed from dom') + + $styles.remove() + }) + + test('should display the tip on top whenever scrollable viewport doesn\'t have enough room if the given placement is "auto bottom"', function () { + var styles = '' + var $styles = $(styles).appendTo('head') + + var $container = $('
').appendTo('#qunit-fixture') + var $target = $('
Tooltip Item
') + .appendTo($container) + .bootstrapTooltip({ + placement: 'bottom auto', + viewport: '#scrollable-div' + }) + + $('#scrollable-div').scrollTop(400) + + $target.bootstrapTooltip('show') + ok($('.tooltip').is('.fade.top.in'), 'has correct classes applied') + + $target.bootstrapTooltip('hide') + equal($('.tooltip').length, 0, 'tooltip removed from dom') + + $styles.remove() + }) + test('should adjust the tip\'s top position when up against the top of the viewport', function () { var styles = '