From 09b486411577849951a351637946f1b9a8440ccb Mon Sep 17 00:00:00 2001 From: Sylvester Keil Date: Tue, 26 Apr 2011 11:05:35 +0200 Subject: [PATCH 1/3] Fixes fractions handling in ui.position. --- tests/unit/position/position.html | 4 ++-- tests/unit/position/position_core.js | 10 ++++++++++ ui/jquery.ui.position.js | 5 +++-- 3 files changed, 15 insertions(+), 4 deletions(-) diff --git a/tests/unit/position/position.html b/tests/unit/position/position.html index 4f2e87e080b..cac0cbf1a49 100644 --- a/tests/unit/position/position.html +++ b/tests/unit/position/position.html @@ -54,8 +54,8 @@

-
-
+
+
diff --git a/tests/unit/position/position_core.js b/tests/unit/position/position_core.js index 5a47fe6bb2f..428a3353720 100644 --- a/tests/unit/position/position_core.js +++ b/tests/unit/position/position_core.js @@ -417,6 +417,16 @@ test( "collision: flip, with margin", function() { }, { top: 0, left: 0 }, "right bottom" ); }); +test( "fractions", function() { + $( "#fractions-element" ).position({ + my: "left top", + at: "left top", + of: "#fractions-parent", + collision: "none" + }); + same( $( "#fractions-element" ).offset(), $( "#fractions-parent" ).offset(), "left top, left top" ); +}); + //test( "bug #5280: consistent results (avoid fractional values)", function() { // var wrapper = $( "#bug-5280" ), // elem = wrapper.children(), diff --git a/ui/jquery.ui.position.js b/ui/jquery.ui.position.js index b6fcc715192..b6dc8ca0484 100644 --- a/ui/jquery.ui.position.js +++ b/ui/jquery.ui.position.js @@ -147,9 +147,10 @@ $.fn.position = function( options ) { position.left += myOffset[ 0 ]; position.top += myOffset[ 1 ]; + // not required using latest jquery core (see #6000) // prevent fractions (see #5280) - position.left = Math.round( position.left ); - position.top = Math.round( position.top ); + // position.left = Math.round( position.left ); + // position.top = Math.round( position.top ); collisionPosition = { left: position.left - marginLeft, From cb0149e8e55d8c2c9bece0e4dcd4218bec7c9065 Mon Sep 17 00:00:00 2001 From: Sylvester Keil Date: Tue, 26 Apr 2011 14:16:40 +0200 Subject: [PATCH 2/3] Retains #5280 consistency test --- tests/unit/position/position.html | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tests/unit/position/position.html b/tests/unit/position/position.html index cac0cbf1a49..2d6bc392133 100644 --- a/tests/unit/position/position.html +++ b/tests/unit/position/position.html @@ -54,6 +54,10 @@

+
+
+
+
From a609e85b9b93eff1ba418fed2ef9e3d907d74f20 Mon Sep 17 00:00:00 2001 From: Sylvester Keil Date: Wed, 27 Apr 2011 14:52:58 +0200 Subject: [PATCH 3/3] Uncomments #5280 test. --- tests/unit/position/position_core.js | 34 ++++++++++++++-------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/tests/unit/position/position_core.js b/tests/unit/position/position_core.js index 428a3353720..51f0ef875fb 100644 --- a/tests/unit/position/position_core.js +++ b/tests/unit/position/position_core.js @@ -427,22 +427,22 @@ test( "fractions", function() { same( $( "#fractions-element" ).offset(), $( "#fractions-parent" ).offset(), "left top, left top" ); }); -//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 ); -//}); +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 ) );