From: Scott González Date: Fri, 26 Mar 2010 23:53:43 +0000 (-0400) Subject: Position: Use parseInt() to prevent fractional pixel values. X-Git-Tag: 1.8.1~5^2~62^2~4^2~1 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=9541bd0bf2ca72795e8f2b2c1d3accc32afcac96;p=jquery-ui.git Position: Use parseInt() to prevent fractional pixel values. Fixes #5280 - ui.position generates different position in static context. --- diff --git a/tests/unit/position/position.html b/tests/unit/position/position.html index 5a54e44c9..ca5f2585d 100644 --- a/tests/unit/position/position.html +++ b/tests/unit/position/position.html @@ -43,5 +43,9 @@
+
+
+
+ diff --git a/tests/unit/position/position_core.js b/tests/unit/position/position_core.js index 4d2716ced..57e02da0a 100644 --- a/tests/unit/position/position_core.js +++ b/tests/unit/position/position_core.js @@ -330,4 +330,22 @@ test("collision: none, with offset", function() { }, { top: -13, left: -12 }, "left top, negative offset"); }); +//test('bug #5280: consistent results (avoid fractional values)', function() { +// var wrapper = $('#bug-5280'), +// elem = wrapper.children(), +// offset1 = elem.position({ +// my: 'center', +// at: 'center', +// of: wrapper, +// collision: 'none' +// }).offset(), +// offset2 = elem.position({ +// my: 'center', +// at: 'center', +// of: wrapper, +// collision: 'none' +// }).offset(); +// same(offset1, offset2); +//}); + })(jQuery); diff --git a/ui/jquery.ui.position.js b/ui/jquery.ui.position.js index f01640e18..11f8baa06 100644 --- a/ui/jquery.ui.position.js +++ b/ui/jquery.ui.position.js @@ -113,6 +113,10 @@ $.fn.position = function( options ) { position.top -= elemHeight / 2; } + // prevent fractions (see #5280) + position.left = parseInt( position.left ); + position.top = parseInt( position.top ); + $.each( [ "left", "top" ], function( i, dir ) { if ( $.ui.position[ collision[i] ] ) { $.ui.position[ collision[i] ][ dir ]( position, {