From 43115ae531c05cf8b26964949a84a4f14a8c7cf8 Mon Sep 17 00:00:00 2001 From: Sylvester Keil Date: Wed, 3 Aug 2011 23:09:48 +0200 Subject: [PATCH 1/6] Position: added test whether jQuery.offset supports fractions and suppresses rounding if it does --- ui/jquery.ui.position.js | 31 +++++++++++++++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) diff --git a/ui/jquery.ui.position.js b/ui/jquery.ui.position.js index 837f23f40cd..39b0630c0b5 100644 --- a/ui/jquery.ui.position.js +++ b/ui/jquery.ui.position.js @@ -14,6 +14,7 @@ $.ui = $.ui || {}; var horizontalPositions = /left|center|right/, verticalPositions = /top|center|bottom/, center = "center", + support = {}, _position = $.fn.position, _offset = $.fn.offset; @@ -122,8 +123,10 @@ $.fn.position = function( options ) { } // prevent fractions (see #5280) - position.left = Math.round( position.left ); - position.top = Math.round( position.top ); + if (!support.fractions) { + position.left = Math.round( position.left ); + position.top = Math.round( position.top ); + } collisionPosition = { left: position.left - marginLeft, @@ -249,4 +252,28 @@ if ( !$.offset.setOffset ) { }; } +// support fractions (older versions of jquery don't support fractions) +support.fractions = (function () { + var body = document.body, offset, + div = $(body.appendChild( document.createElement( "div" ) ) ); + + $.extend( div[0].style, { + position: 'absolute', + left: '10.7432222px', + top: '10.532325px', + height: '30px', + width: '201px' + }); + + offset = div.offset(); + div.offset(offset); + offset = div.offset(); + + // set display to none to avoid a layout bug in IE + // http://dev.jquery.com/ticket/4014 + body.removeChild( div[0] ).style.display = "none"; + + return offset.top + offset.left > 20.0; +})(); + }( jQuery )); From 41dc845fae825be934dd4c29c8726ea6805ca316 Mon Sep 17 00:00:00 2001 From: Sylvester Keil Date: Wed, 7 Sep 2011 20:02:58 +0200 Subject: [PATCH 2/6] Position: re-activated consistency test #5280 --- 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 f4075ccfe7c..b7d0894d386 100644 --- a/tests/unit/position/position_core.js +++ b/tests/unit/position/position_core.js @@ -406,22 +406,22 @@ test("collision: flip, with margin", function() { }, { top: 0, left: 0 }, "right bottom"); }); -//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); From 957a80b1c389823bf726d6d9edbe4f7e72c96889 Mon Sep 17 00:00:00 2001 From: Sylvester Keil Date: Wed, 7 Sep 2011 20:23:50 +0200 Subject: [PATCH 3/6] Position: fixes fractions test in FF6 --- ui/jquery.ui.position.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/ui/jquery.ui.position.js b/ui/jquery.ui.position.js index 39b0630c0b5..801187123b5 100644 --- a/ui/jquery.ui.position.js +++ b/ui/jquery.ui.position.js @@ -254,8 +254,9 @@ if ( !$.offset.setOffset ) { // support fractions (older versions of jquery don't support fractions) support.fractions = (function () { - var body = document.body, offset, - div = $(body.appendChild( document.createElement( "div" ) ) ); + var body = document.body, offset, div; + + div = $(body.appendChild( document.createElement( "div" ) ) ); $.extend( div[0].style, { position: 'absolute', From 10d86091844362493c776b8d8b3e11fc5e8b3458 Mon Sep 17 00:00:00 2001 From: Sylvester Keil Date: Wed, 7 Sep 2011 20:52:23 +0200 Subject: [PATCH 4/6] Position: lazily execute fraction test --- ui/jquery.ui.position.js | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/ui/jquery.ui.position.js b/ui/jquery.ui.position.js index 801187123b5..cdae238f07f 100644 --- a/ui/jquery.ui.position.js +++ b/ui/jquery.ui.position.js @@ -253,11 +253,10 @@ if ( !$.offset.setOffset ) { } // support fractions (older versions of jquery don't support fractions) -support.fractions = (function () { - var body = document.body, offset, div; +support.fractions = $(function () { + var body = document.body, offset, + div = $(body.appendChild( document.createElement( "div" ) ) ); - div = $(body.appendChild( document.createElement( "div" ) ) ); - $.extend( div[0].style, { position: 'absolute', left: '10.7432222px', @@ -265,16 +264,16 @@ support.fractions = (function () { height: '30px', width: '201px' }); - + offset = div.offset(); div.offset(offset); offset = div.offset(); - + // set display to none to avoid a layout bug in IE // http://dev.jquery.com/ticket/4014 body.removeChild( div[0] ).style.display = "none"; - + return offset.top + offset.left > 20.0; -})(); +}); }( jQuery )); From c0dd5fdfc73087b921dba25fb7f6a4fda21ded97 Mon Sep 17 00:00:00 2001 From: Sylvester Keil Date: Thu, 8 Sep 2011 09:20:25 +0200 Subject: [PATCH 5/6] Position: fixes assignment of test result --- ui/jquery.ui.position.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ui/jquery.ui.position.js b/ui/jquery.ui.position.js index cdae238f07f..bb2a98d1c5d 100644 --- a/ui/jquery.ui.position.js +++ b/ui/jquery.ui.position.js @@ -253,7 +253,7 @@ if ( !$.offset.setOffset ) { } // support fractions (older versions of jquery don't support fractions) -support.fractions = $(function () { +$(function () { var body = document.body, offset, div = $(body.appendChild( document.createElement( "div" ) ) ); @@ -273,7 +273,7 @@ support.fractions = $(function () { // http://dev.jquery.com/ticket/4014 body.removeChild( div[0] ).style.display = "none"; - return offset.top + offset.left > 20.0; + support.fractions = offset.top + offset.left > 20.0; }); }( jQuery )); From 54307ec967e81dec8d82f222f8f50e91c25de0c2 Mon Sep 17 00:00:00 2001 From: Sylvester Keil Date: Wed, 14 Sep 2011 19:29:46 +0200 Subject: [PATCH 6/6] Position: fixed fractions test for IE9 --- ui/jquery.ui.position.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ui/jquery.ui.position.js b/ui/jquery.ui.position.js index bb2a98d1c5d..5cb609471d1 100644 --- a/ui/jquery.ui.position.js +++ b/ui/jquery.ui.position.js @@ -259,8 +259,8 @@ $(function () { $.extend( div[0].style, { position: 'absolute', - left: '10.7432222px', - top: '10.532325px', + left: '10.2432222px', + top: '10.432325px', height: '30px', width: '201px' });