]> source.dussan.org Git - jquery-ui.git/commitdiff
Position: Use parseInt() to prevent fractional pixel values.
authorScott González <scott.gonzalez@gmail.com>
Fri, 26 Mar 2010 23:53:43 +0000 (19:53 -0400)
committerScott González <scott.gonzalez@gmail.com>
Fri, 26 Mar 2010 23:53:43 +0000 (19:53 -0400)
Fixes #5280 - ui.position generates different position in static context.

tests/unit/position/position.html
tests/unit/position/position_core.js
ui/jquery.ui.position.js

index 5a54e44c9bda67c6a774edcaa6d062af58acd0e1..ca5f2585de05c13c6a0e729e9453a0b970d0ba44 100644 (file)
@@ -43,5 +43,9 @@
 
 <div style="position: absolute; height: 5000px; width: 5000px;"></div>
 
+<div id="bug-5280" style="height: 30px; width: 201px;">
+       <div style="width: 50px; height: 10px;"></div>
+</div>
+
 </body>
 </html>
index 4d2716cedb53825e4288f89cd842c612dcf94beb..57e02da0a345ce8ae39531b68aa22a5a289cfe5f 100644 (file)
@@ -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);
index f01640e18baf569194faa2d6de0dabb04ccb171c..11f8baa063834707208c52ac4f4eac71aeb4941b 100644 (file)
@@ -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, {