From edb221a20ceabebd427e27d0432e94a227717217 Mon Sep 17 00:00:00 2001 From: Ben Ogle Date: Fri, 22 Nov 2013 11:58:53 -0800 Subject: Add tooltip `viewport` option, respect bounds of the viewport --- js/tests/unit/tooltip.js | 65 ++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 63 insertions(+), 2 deletions(-) (limited to 'js/tests/unit/tooltip.js') diff --git a/js/tests/unit/tooltip.js b/js/tests/unit/tooltip.js index d921bee7f..94b881bd7 100644 --- a/js/tests/unit/tooltip.js +++ b/js/tests/unit/tooltip.js @@ -338,10 +338,10 @@ $(function () { }) test('should add position class before positioning so that position-specific styles are taken into account', function () { - $('head').append('') + $('head').append('') var container = $('
').appendTo('body'), - target = $('') + target = $('') .appendTo(container) .tooltip({placement: 'right'}) .tooltip('show'), @@ -349,6 +349,67 @@ $(function () { ok( Math.round(target.offset().top + (target[0].offsetHeight / 2) - (tooltip[0].offsetHeight / 2)) === Math.round(tooltip.offset().top) ) target.tooltip('hide') + $('head #test').remove() + }) + + test('should adjust the tip\'s top when up against the top of the viewport', function () { + $('head').append('') + + var container = $('
').appendTo('body'), + target = $('') + .appendTo(container) + .tooltip({placement: 'right', viewportPadding: 12}) + .tooltip('show'), + tooltip = container.find('.tooltip') + + ok( Math.round(tooltip.offset().top) === 12 ) + target.tooltip('hide') + $('head #test').remove() + }) + + test('should adjust the tip\'s top when up against the bottom of the viewport', function () { + $('head').append('') + + var container = $('
').appendTo('body'), + target = $('') + .appendTo(container) + .tooltip({placement: 'right', viewportPadding: 12}) + .tooltip('show'), + tooltip = container.find('.tooltip') + + ok( Math.round(tooltip.offset().top) === Math.round($(window).height() - 12 - tooltip[0].offsetHeight) ) + target.tooltip('hide') + $('head #test').remove() + }) + + test('should adjust the tip\'s left when up against the left of the viewport', function () { + $('head').append('') + + var container = $('
').appendTo('body'), + target = $('') + .appendTo(container) + .tooltip({placement: 'bottom', viewportPadding: 12}) + .tooltip('show'), + tooltip = container.find('.tooltip') + + ok( Math.round(tooltip.offset().left) === 12 ) + target.tooltip('hide') + $('head #test').remove() + }) + + test('should adjust the tip\'s left when up against the right of the viewport', function () { + $('head').append('') + + var container = $('
').appendTo('body'), + target = $('') + .appendTo(container) + .tooltip({placement: 'bottom', viewportPadding: 12}) + .tooltip('show'), + tooltip = container.find('.tooltip') + + ok( Math.round(tooltip.offset().left) === Math.round($(window).width() - 12 - tooltip[0].offsetWidth) ) + target.tooltip('hide') + $('head #test').remove() }) test('tooltip title test #1', function () { -- cgit v1.2.3 From 2f76821a4dce7683168ab190e53c64fdf13dd469 Mon Sep 17 00:00:00 2001 From: fat Date: Thu, 16 Jan 2014 13:33:09 -0800 Subject: new qunit --- js/tests/unit/tooltip.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'js/tests/unit/tooltip.js') diff --git a/js/tests/unit/tooltip.js b/js/tests/unit/tooltip.js index d921bee7f..2a74b2a55 100644 --- a/js/tests/unit/tooltip.js +++ b/js/tests/unit/tooltip.js @@ -387,6 +387,8 @@ $(function () { }) test('tooltips should be placed dynamically, with the dynamic placement option', function () { + $(document.body).scrollTop(0) // force to top of page + $.support.transition = false var ttContainer = $('
').css({ 'height' : 400, @@ -402,7 +404,6 @@ $(function () { .tooltip({placement: 'auto'}) .tooltip('show') - ok($('.tooltip').is('.bottom'), 'top positioned tooltip is dynamically positioned bottom') topTooltip.tooltip('hide') -- cgit v1.2.3 From 3b2418e6885d31d9cd1eab33b4cb952e876f8cf7 Mon Sep 17 00:00:00 2001 From: fat Date: Thu, 16 Jan 2014 13:44:08 -0800 Subject: remove flaky pos bottom test which is effect by unit scroll pos --- js/tests/unit/tooltip.js | 10 ---------- 1 file changed, 10 deletions(-) (limited to 'js/tests/unit/tooltip.js') diff --git a/js/tests/unit/tooltip.js b/js/tests/unit/tooltip.js index 2a74b2a55..fa1ad57fe 100644 --- a/js/tests/unit/tooltip.js +++ b/js/tests/unit/tooltip.js @@ -387,8 +387,6 @@ $(function () { }) test('tooltips should be placed dynamically, with the dynamic placement option', function () { - $(document.body).scrollTop(0) // force to top of page - $.support.transition = false var ttContainer = $('
').css({ 'height' : 400, @@ -416,14 +414,6 @@ $(function () { ok($('.tooltip').is('.left'), 'right positioned tooltip is dynamically positioned left') rightTooltip.tooltip('hide') - var bottomTooltip = $('
Bottom Dynamic Tooltip
') - .appendTo('#dynamic-tt-test') - .tooltip({placement: 'auto bottom'}) - .tooltip('show') - - ok($('.tooltip').is('.top'), 'bottom positioned tooltip is dynamically positioned top') - bottomTooltip.tooltip('hide') - var leftTooltip = $('
Left Dynamic Tooltip
') .appendTo('#dynamic-tt-test') .tooltip({placement: 'auto left'}) -- cgit v1.2.3 From 82ff4e2e40a3f81c569cc46c1ae1f10ffde9e6ad Mon Sep 17 00:00:00 2001 From: fat Date: Thu, 16 Jan 2014 14:25:28 -0800 Subject: tooltip subpixel test fixes --- js/tests/unit/tooltip.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'js/tests/unit/tooltip.js') diff --git a/js/tests/unit/tooltip.js b/js/tests/unit/tooltip.js index fa1ad57fe..087de80dd 100644 --- a/js/tests/unit/tooltip.js +++ b/js/tests/unit/tooltip.js @@ -332,7 +332,7 @@ $(function () { var tooltip = container.find('.tooltip') start() - ok(tooltip.offset().top + tooltip.outerHeight() <= tooltiped.offset().top) + ok(Math.round(tooltip.offset().top + tooltip.outerHeight()) <= Math.round(tooltiped.offset().top) container.remove() }, 100) }) @@ -347,7 +347,11 @@ $(function () { .tooltip('show'), tooltip = container.find('.tooltip') - ok( Math.round(target.offset().top + (target[0].offsetHeight / 2) - (tooltip[0].offsetHeight / 2)) === Math.round(tooltip.offset().top) ) + // this is some dumb hack shit because sub pixels in firefox + var top = Math.round(target.offset().top + (target[0].offsetHeight / 2) - (tooltip[0].offsetHeight / 2)) + var top2 = Math.round(tooltip.offset().top) + var topDiff = top - top2 + ok(topDiff <= 1 && topDiff >= -1) target.tooltip('hide') }) -- cgit v1.2.3 From 4bd6a52562c48d6d798bcbe427e08ad306889b4a Mon Sep 17 00:00:00 2001 From: fat Date: Thu, 16 Jan 2014 14:28:21 -0800 Subject: add missing paren --- js/tests/unit/tooltip.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'js/tests/unit/tooltip.js') diff --git a/js/tests/unit/tooltip.js b/js/tests/unit/tooltip.js index 087de80dd..b9b003dd1 100644 --- a/js/tests/unit/tooltip.js +++ b/js/tests/unit/tooltip.js @@ -332,7 +332,7 @@ $(function () { var tooltip = container.find('.tooltip') start() - ok(Math.round(tooltip.offset().top + tooltip.outerHeight()) <= Math.round(tooltiped.offset().top) + ok(Math.round(tooltip.offset().top + tooltip.outerHeight()) <= Math.round(tooltiped.offset().top)) container.remove() }, 100) }) -- cgit v1.2.3 From 6af0013ac52c391dd7623f9cbbb25cd7d3c43d35 Mon Sep 17 00:00:00 2001 From: Chris Rebert Date: Thu, 16 Jan 2014 20:31:19 -0800 Subject: Revert "Add tooltip `viewport` option, respect bounds of the viewport" This reverts commit edb221a20ceabebd427e27d0432e94a227717217. Reverting due to broken JS unit tests. Conflicts: docs/javascript.html --- js/tests/unit/tooltip.js | 65 ++---------------------------------------------- 1 file changed, 2 insertions(+), 63 deletions(-) (limited to 'js/tests/unit/tooltip.js') diff --git a/js/tests/unit/tooltip.js b/js/tests/unit/tooltip.js index 9fab6c61f..b9b003dd1 100644 --- a/js/tests/unit/tooltip.js +++ b/js/tests/unit/tooltip.js @@ -338,10 +338,10 @@ $(function () { }) test('should add position class before positioning so that position-specific styles are taken into account', function () { - $('head').append('') + $('head').append('') var container = $('
').appendTo('body'), - target = $('') + target = $('') .appendTo(container) .tooltip({placement: 'right'}) .tooltip('show'), @@ -353,67 +353,6 @@ $(function () { var topDiff = top - top2 ok(topDiff <= 1 && topDiff >= -1) target.tooltip('hide') - $('head #test').remove() - }) - - test('should adjust the tip\'s top when up against the top of the viewport', function () { - $('head').append('') - - var container = $('
').appendTo('body'), - target = $('') - .appendTo(container) - .tooltip({placement: 'right', viewportPadding: 12}) - .tooltip('show'), - tooltip = container.find('.tooltip') - - ok( Math.round(tooltip.offset().top) === 12 ) - target.tooltip('hide') - $('head #test').remove() - }) - - test('should adjust the tip\'s top when up against the bottom of the viewport', function () { - $('head').append('') - - var container = $('
').appendTo('body'), - target = $('') - .appendTo(container) - .tooltip({placement: 'right', viewportPadding: 12}) - .tooltip('show'), - tooltip = container.find('.tooltip') - - ok( Math.round(tooltip.offset().top) === Math.round($(window).height() - 12 - tooltip[0].offsetHeight) ) - target.tooltip('hide') - $('head #test').remove() - }) - - test('should adjust the tip\'s left when up against the left of the viewport', function () { - $('head').append('') - - var container = $('
').appendTo('body'), - target = $('') - .appendTo(container) - .tooltip({placement: 'bottom', viewportPadding: 12}) - .tooltip('show'), - tooltip = container.find('.tooltip') - - ok( Math.round(tooltip.offset().left) === 12 ) - target.tooltip('hide') - $('head #test').remove() - }) - - test('should adjust the tip\'s left when up against the right of the viewport', function () { - $('head').append('') - - var container = $('
').appendTo('body'), - target = $('') - .appendTo(container) - .tooltip({placement: 'bottom', viewportPadding: 12}) - .tooltip('show'), - tooltip = container.find('.tooltip') - - ok( Math.round(tooltip.offset().left) === Math.round($(window).width() - 12 - tooltip[0].offsetWidth) ) - target.tooltip('hide') - $('head #test').remove() }) test('tooltip title test #1', function () { -- cgit v1.2.3