aboutsummaryrefslogtreecommitdiffstats
path: root/ui/jquery.ui.position.js
diff options
context:
space:
mode:
authorkborchers <k_borchers@yahoo.com>2011-10-26 10:43:01 -0400
committerScott González <scott.gonzalez@gmail.com>2011-10-26 10:43:01 -0400
commitbfbc0b1fb3c0bf43ccbaefd03bcfa2cf19ea4a03 (patch)
tree3d6db2a19b2942b7991439f82d6831918d0e0007 /ui/jquery.ui.position.js
parent757384b8c5eb1ccf354f9ab98fcb3b0e6cae6e1d (diff)
downloadjquery-ui-bfbc0b1fb3c0bf43ccbaefd03bcfa2cf19ea4a03.tar.gz
jquery-ui-bfbc0b1fb3c0bf43ccbaefd03bcfa2cf19ea4a03.zip
Position: Added a check for fraction support in element positions. Fixes #7255 - Position: Revisit solution for off-by-1 errors.
Diffstat (limited to 'ui/jquery.ui.position.js')
-rw-r--r--ui/jquery.ui.position.js52
1 files changed, 49 insertions, 3 deletions
diff --git a/ui/jquery.ui.position.js b/ui/jquery.ui.position.js
index 837f23f40..92cf8001d 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;
@@ -121,9 +122,11 @@ $.fn.position = function( options ) {
position.top -= elemHeight / 2;
}
- // prevent fractions (see #5280)
- position.left = Math.round( position.left );
- position.top = Math.round( position.top );
+ // prevent fractions if jQuery version doesn't support them (see #5280)
+ if ( !support.fractions ) {
+ position.left = Math.round( position.left );
+ position.top = Math.round( position.top );
+ }
collisionPosition = {
left: position.left - marginLeft,
@@ -249,4 +252,47 @@ if ( !$.offset.setOffset ) {
};
}
+// fraction support test (older versions of jQuery don't support fractions)
+(function () {
+ var body = document.getElementsByTagName( "body" )[ 0 ],
+ div = document.createElement( "div" ),
+ testElement, testElementParent, testElementStyle, offset, offsetTotal;
+
+ //Create a "fake body" for testing based on method used in jQuery.support
+ testElement = document.createElement( body ? "div" : "body" );
+ testElementStyle = {
+ visibility: "hidden",
+ width: 0,
+ height: 0,
+ border: 0,
+ margin: 0,
+ background: "none"
+ };
+ if ( body ) {
+ jQuery.extend( testElementStyle, {
+ position: "absolute",
+ left: "-1000px",
+ top: "-1000px"
+ });
+ }
+ for ( var i in testElementStyle ) {
+ testElement.style[ i ] = testElementStyle[ i ];
+ }
+ testElement.appendChild( div );
+ testElementParent = body || document.documentElement;
+ testElementParent.insertBefore( testElement, testElementParent.firstChild );
+
+ div.style.cssText = "position: absolute; left: 10.7432222px; top: 10.432325px; height: 30px; width: 201px;";
+
+ offset = $( div ).offset( function( _, offset ) {
+ return offset;
+ }).offset();
+
+ testElement.innerHTML = "";
+ testElementParent.removeChild( testElement );
+
+ offsetTotal = offset.top + offset.left + ( body ? 2000 : 0 );
+ support.fractions = offsetTotal > 21 && offsetTotal < 22;
+})();
+
}( jQuery ));