Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Position: Simplify fraction support test
Also makes the test lazy to avoid any potential layouts/recalculations during initialization. Fixes #9898 Ref #9899
- Loading branch information
1 parent
dff1c74
commit 3970e8c
Showing
1 changed file
with
21 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -41,6 +41,26 @@ var cachedScrollbarWidth, supportsOffsetFractions, | ||
rpercent = /%$/, | ||
_position = $.fn.position; | ||
|
||
// Support: IE <=9 only | ||
supportsOffsetFractions = function() { | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
scottgonzalez
Author
Member
|
||
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; | ||
@scottgonzalez question for the confused: which jquery-ui release did this go into? It looks like the latest code (1.11.4) doesn't have this commit, despite being released after this got merged.