diff options
| author | saranya.r <[email protected]> | 2014-09-09 18:47:06 +0530 |
|---|---|---|
| committer | Heinrich Fenkart <[email protected]> | 2014-09-17 23:11:04 +0200 |
| commit | db9e8ee813d13546acc9663970c810c230ed026c (patch) | |
| tree | 7f6893c12f1cd0012772f922008f2e4f1edf8d5b | |
| parent | c5c67d0f54674dede58fc924d4d7c0f1d65705d9 (diff) | |
| download | bootstrap-db9e8ee813d13546acc9663970c810c230ed026c.tar.xz bootstrap-db9e8ee813d13546acc9663970c810c230ed026c.zip | |
Fix tooltip misplacement with "auto top"
Fixes #14322.
Closes #14581.
| -rw-r--r-- | js/tests/unit/tooltip.js | 50 | ||||
| -rw-r--r-- | js/tooltip.js | 2 |
2 files changed, 51 insertions, 1 deletions
diff --git a/js/tests/unit/tooltip.js b/js/tests/unit/tooltip.js index c75924e9f..cd239f0c6 100644 --- a/js/tests/unit/tooltip.js +++ b/js/tests/unit/tooltip.js @@ -382,6 +382,56 @@ $(function () { $style.remove() }) + test('should position tip on top if viewport has enough space and placement is "auto top"', function () { + var styles = '<style>' + + 'body { padding-top: 100px; }' + + 'section { height: 300px; border: 1px solid red; padding-top: 50px }' + + 'div[rel="tooltip"] { width: 150px; border: 1px solid blue; }' + + '</style>' + var $styles = $(styles).appendTo('head') + + var $container = $('<section/>').appendTo('#qunit-fixture') + var $target = $('<div rel="tooltip" title="tip"/>') + .appendTo($container) + .bootstrapTooltip({ + placement: 'auto top', + viewport: 'section' + }) + + $target.bootstrapTooltip('show') + ok($('.tooltip').is('.top'), 'top positioned tooltip is dynamically positioned to top') + + $target.bootstrapTooltip('hide') + equal($('.tooltip').length, 0, 'tooltip removed from dom') + + $styles.remove() + }) + + test('should position tip on bottom if the tip\'s dimension exceeds the viewport area and placement is "auto top"', function () { + var styles = '<style>' + + 'body { padding-top: 100px; }' + + 'section { height: 300px; border: 1px solid red; }' + + 'div[rel="tooltip"] { width: 150px; border: 1px solid blue; }' + + '</style>' + var $styles = $(styles).appendTo('head') + + var $container = $('<section/>').appendTo('#qunit-fixture') + var $target = $('<div rel="tooltip" title="tip"/>') + .appendTo($container) + .bootstrapTooltip({ + placement: 'auto top', + viewport: 'section' + }) + + $target.bootstrapTooltip('show') + ok($('.tooltip').is('.bottom'), 'top positioned tooltip is dynamically positioned to bottom') + + $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 7194b5d01..9932c0b18 100644 --- a/js/tooltip.js +++ b/js/tooltip.js @@ -192,7 +192,7 @@ var parentDim = this.getPosition($parent) placement = placement == 'bottom' && pos.top + pos.height + actualHeight - parentDim.scroll > parentDim.height ? 'top' : - placement == 'top' && pos.top - parentDim.scroll - actualHeight < 0 ? 'bottom' : + placement == 'top' && pos.top - parentDim.scroll - actualHeight < parentDim.top ? 'bottom' : placement == 'right' && pos.right + actualWidth > parentDim.width ? 'left' : placement == 'left' && pos.left - actualWidth < parentDim.left ? 'right' : placement |
