aboutsummaryrefslogtreecommitdiff
path: root/js
diff options
context:
space:
mode:
authorsaranya.r <[email protected]>2014-10-10 11:49:45 +0530
committerHeinrich Fenkart <[email protected]>2014-10-22 21:35:44 +0200
commite2cfbd5f2df12cb207a66663925f5ee7e5cb2320 (patch)
treebb4b6cac309e41a22f21592f0ccf74eac289a575 /js
parent2bc5277b44ed5d2e79ab531e398f9930023426a5 (diff)
downloadbootstrap-e2cfbd5f2df12cb207a66663925f5ee7e5cb2320.tar.xz
bootstrap-e2cfbd5f2df12cb207a66663925f5ee7e5cb2320.zip
Fixes tooltip misplacements in scrollable viewports with auto positioning
Fixes #14756. Closes #14767.
Diffstat (limited to 'js')
-rw-r--r--js/tests/unit/tooltip.js104
-rw-r--r--js/tooltip.js8
2 files changed, 108 insertions, 4 deletions
diff --git a/js/tests/unit/tooltip.js b/js/tests/unit/tooltip.js
index 3eb3c7b85..7b5f8adf7 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 = '<style>'
+ + '#scrollable-div { height: 200px; overflow: auto; }'
+ + '.tooltip-item { margin: 200px 0 400px; width: 150px; }'
+ + '</style>'
+ var $styles = $(styles).appendTo('head')
+
+ var $container = $('<div id="scrollable-div"/>').appendTo('#qunit-fixture')
+ var $target = $('<div rel="tooltip" title="tip" class="tooltip-item">Tooltip Item</div>')
+ .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 = '<style>'
+ + '#scrollable-div { height: 200px; overflow: auto; }'
+ + '.tooltip-item { margin: 200px 0 400px; width: 150px; }'
+ + '</style>'
+ var $styles = $(styles).appendTo('head')
+
+ var $container = $('<div id="scrollable-div"/>').appendTo('#qunit-fixture')
+ var $target = $('<div rel="tooltip" title="tip" class="tooltip-item">Tooltip Item</div>')
+ .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 = '<style>'
+ + '#scrollable-div { height: 200px; overflow: auto; }'
+ + '.tooltip-item { margin: 200px 0 400px; width: 150px; }'
+ + '</style>'
+ var $styles = $(styles).appendTo('head')
+
+ var $container = $('<div id="scrollable-div"/>').appendTo('#qunit-fixture')
+ var $target = $('<div rel="tooltip" title="tip" class="tooltip-item">Tooltip Item</div>')
+ .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 = '<style>'
+ + '#scrollable-div { height: 200px; overflow: auto; }'
+ + '.tooltip-item { margin-top: 400px; width: 150px; }'
+ + '</style>'
+ var $styles = $(styles).appendTo('head')
+
+ var $container = $('<div id="scrollable-div"/>').appendTo('#qunit-fixture')
+ var $target = $('<div rel="tooltip" title="tip" class="tooltip-item">Tooltip Item</div>')
+ .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 = '<style>'
+ '.tooltip .tooltip-inner { width: 200px; height: 200px; max-width: none; }'
diff --git a/js/tooltip.js b/js/tooltip.js
index ff33a4f10..6dc6cf2e1 100644
--- a/js/tooltip.js
+++ b/js/tooltip.js
@@ -191,10 +191,10 @@
var $container = this.options.container ? $(this.options.container) : this.$element.parent()
var containerDim = this.getPosition($container)
- placement = placement == 'bottom' && pos.top + pos.height + actualHeight - containerDim.scroll > containerDim.height ? 'top' :
- placement == 'top' && pos.top - containerDim.scroll - actualHeight < containerDim.top ? 'bottom' :
- placement == 'right' && pos.right + actualWidth > containerDim.width ? 'left' :
- placement == 'left' && pos.left - actualWidth < containerDim.left ? 'right' :
+ placement = placement == 'bottom' && pos.bottom + actualHeight > containerDim.bottom ? 'top' :
+ placement == 'top' && pos.top - actualHeight < containerDim.top ? 'bottom' :
+ placement == 'right' && pos.right + actualWidth > containerDim.width ? 'left' :
+ placement == 'left' && pos.left - actualWidth < containerDim.left ? 'right' :
placement
$tip