aboutsummaryrefslogtreecommitdiffstats
path: root/ui
diff options
context:
space:
mode:
authorScott González <scott.gonzalez@gmail.com>2015-03-18 10:05:36 -0400
committerScott González <scott.gonzalez@gmail.com>2015-03-18 10:55:53 -0400
commit3970e8c68146a3645f09d54735a40d5cf7eeef9e (patch)
treeb3f5234528235808e6a56502dc4f6d195e060f48 /ui
parentdff1c74dd4c0fd6b951c7c183bebae09f9f229f6 (diff)
downloadjquery-ui-3970e8c68146a3645f09d54735a40d5cf7eeef9e.tar.gz
jquery-ui-3970e8c68146a3645f09d54735a40d5cf7eeef9e.zip
Position: Simplify fraction support test
Also makes the test lazy to avoid any potential layouts/recalculations during initialization. Fixes #9898 Ref #9899
Diffstat (limited to 'ui')
-rw-r--r--ui/position.js61
1 files changed, 21 insertions, 40 deletions
diff --git a/ui/position.js b/ui/position.js
index 7423d02d1..367fc3978 100644
--- a/ui/position.js
+++ b/ui/position.js
@@ -41,6 +41,26 @@ var cachedScrollbarWidth, supportsOffsetFractions,
rpercent = /%$/,
_position = $.fn.position;
+// Support: IE <=9 only
+supportsOffsetFractions = function() {
+ var element = $( "<div>" )
+ .css( "position", "absolute" )
+ .appendTo( "body" )
+ .offset( {
+ top: 1.5,
+ left: 1.5
+ } ),
+ support = element.offset().top === 1.5;
+
+ element.remove();
+
+ supportsOffsetFractions = function() {
+ return support;
+ };
+
+ return support;
+};
+
function getOffsets( offsets, width, height ) {
return [
parseFloat( offsets[ 0 ] ) * ( rpercent.test( offsets[ 0 ] ) ? width / 100 : 1 ),
@@ -243,7 +263,7 @@ $.fn.position = function( options ) {
position.top += myOffset[ 1 ];
// if the browser doesn't support fractions, then round for consistent results
- if ( !supportsOffsetFractions ) {
+ if ( !supportsOffsetFractions() ) {
position.left = round( position.left );
position.top = round( position.top );
}
@@ -475,45 +495,6 @@ $.ui.position = {
}
};
-// fraction support test
-( function() {
- var testElement, testElementParent, testElementStyle, offsetLeft, i,
- body = document.getElementsByTagName( "body" )[ 0 ],
- div = document.createElement( "div" );
-
- //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 ) {
- $.extend( testElementStyle, {
- position: "absolute",
- left: "-1000px",
- top: "-1000px"
- } );
- }
- for ( 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;";
-
- offsetLeft = $( div ).offset().left;
- supportsOffsetFractions = offsetLeft > 10 && offsetLeft < 11;
-
- testElement.innerHTML = "";
- testElementParent.removeChild( testElement );
-} )();
-
} )();
return $.ui.position;