Commit 93750cee authored by timmywil's avatar timmywil

Run offset support tests at doc ready. Fixes #10613.

parent 38f087b5
...@@ -20,8 +20,7 @@ jQuery.support = (function() { ...@@ -20,8 +20,7 @@ jQuery.support = (function() {
events, events,
eventName, eventName,
i, i,
isSupported, isSupported;
offsetSupport;
// Preliminary tests // Preliminary tests
div.setAttribute("className", "t"); div.setAttribute("className", "t");
...@@ -231,9 +230,6 @@ jQuery.support = (function() { ...@@ -231,9 +230,6 @@ jQuery.support = (function() {
( parseInt( ( document.defaultView.getComputedStyle( marginDiv, null ) || { marginRight: 0 } ).marginRight, 10 ) || 0 ) === 0; ( parseInt( ( document.defaultView.getComputedStyle( marginDiv, null ) || { marginRight: 0 } ).marginRight, 10 ) || 0 ) === 0;
} }
// Remove the body element we added
testElement.innerHTML = "";
// Technique from Juriy Zaytsev // Technique from Juriy Zaytsev
// http://perfectionkills.com/detecting-event-support-without-browser-sniffing/ // http://perfectionkills.com/detecting-event-support-without-browser-sniffing/
// We only care about the case where non-standard event systems // We only care about the case where non-standard event systems
...@@ -256,29 +252,31 @@ jQuery.support = (function() { ...@@ -256,29 +252,31 @@ jQuery.support = (function() {
} }
} }
// Determine fixed-position support early // Run fixed position tests at doc ready to avoid a crash
testElement.style.position = "static"; // related to the invisible body in IE8
testElement.style.top = "0px"; jQuery(function() {
testElement.style.marginTop = "1px"; var outer, inner, table, td, offsetSupport,
offsetSupport = (function( body, container ) { bodyMarginTop = 1,
var outer, inner, table, td, supports,
bodyMarginTop = parseFloat( body.style.marginTop ) || 0,
ptlm = "position:absolute;top:0;left:0;width:1px;height:1px;margin:0;", ptlm = "position:absolute;top:0;left:0;width:1px;height:1px;margin:0;",
style = "style='" + ptlm + "border:5px solid #000;padding:0;'", style = "style='" + ptlm + "border:5px solid #000;padding:0;'",
html = "<div " + style + "><div></div></div>" + html = "<div " + style + "><div></div></div>" +
"<table " + style + " cellpadding='0' cellspacing='0'>" + "<table " + style + " cellpadding='0' cellspacing='0'>" +
"<tr><td></td></tr></table>"; "<tbody><tr><td></td></tr></tbody></table>";
container.style.cssText = ptlm + "border:0;visibility:hidden"; body = document.getElementsByTagName("body")[0];
testElement = document.createElement("div");
container.innerHTML = html; body.style.position = "static";
body.insertBefore( container, body.firstChild ); body.style.top = "0px";
outer = container.firstChild; body.style.marginTop = bodyMarginTop + "px";
testElement.style.cssText = ptlm + "border:0;visibility:hidden";
testElement.innerHTML = html;
body.appendChild( testElement );
outer = testElement.firstChild;
inner = outer.firstChild; inner = outer.firstChild;
td = outer.nextSibling.firstChild.firstChild; td = outer.nextSibling.firstChild.firstChild.firstChild;
supports = { offsetSupport = {
doesNotAddBorder: ( inner.offsetTop !== 5 ), doesNotAddBorder: ( inner.offsetTop !== 5 ),
doesAddBorderForTableAndCells: ( td.offsetTop === 5 ) doesAddBorderForTableAndCells: ( td.offsetTop === 5 )
}; };
...@@ -287,20 +285,21 @@ jQuery.support = (function() { ...@@ -287,20 +285,21 @@ jQuery.support = (function() {
inner.style.top = "20px"; inner.style.top = "20px";
// safari subtracts parent border width here which is 5px // safari subtracts parent border width here which is 5px
supports.supportsFixedPosition = ( inner.offsetTop === 20 || inner.offsetTop === 15 ); offsetSupport.supportsFixedPosition = ( inner.offsetTop === 20 || inner.offsetTop === 15 );
inner.style.position = inner.style.top = ""; inner.style.position = inner.style.top = "";
outer.style.overflow = "hidden"; outer.style.overflow = "hidden";
outer.style.position = "relative"; outer.style.position = "relative";
supports.subtractsBorderForOverflowNotVisible = ( inner.offsetTop === -5 ); offsetSupport.subtractsBorderForOverflowNotVisible = ( inner.offsetTop === -5 );
supports.doesNotIncludeMarginInBodyOffset = ( body.offsetTop !== bodyMarginTop ); offsetSupport.doesNotIncludeMarginInBodyOffset = ( body.offsetTop !== bodyMarginTop );
return supports;
})( testElement, div ); body.removeChild( testElement );
jQuery.extend( jQuery.offset, offsetSupport );
jQuery.extend( support, offsetSupport );
});
jQuery.extend( support, offsetSupport ); testElement.innerHTML = "";
testElementParent.removeChild( testElement ); testElementParent.removeChild( testElement );
// Null connected elements to avoid leaks in IE // Null connected elements to avoid leaks in IE
......
...@@ -298,5 +298,6 @@ Z</textarea> ...@@ -298,5 +298,6 @@ Z</textarea>
<div id="fx-tests"></div> <div id="fx-tests"></div>
</div> </div>
</body> </body>
</html> </html>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment