Created
July 26, 2012 16:30
Run tests that need a body at doc ready
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
// Run tests that need a body at doc ready | |
jQuery(function() { | |
var container, outer, inner, table, td, offsetSupport, | |
marginDiv, conMarginTop, style, html, positionTopLeftWidthHeight, | |
paddingMarginBorderVisibility, paddingMarginBorder, | |
body = document.getElementsByTagName("body")[0]; | |
if ( !body ) { | |
// Return for frameset docs that don't have a body | |
return; | |
} | |
conMarginTop = 1; | |
paddingMarginBorder = "padding:0;margin:0;border:"; | |
positionTopLeftWidthHeight = "position:absolute;top:0;left:0;width:1px;height:1px;"; | |
paddingMarginBorderVisibility = paddingMarginBorder + "0;visibility:hidden;"; | |
style = "style='" + positionTopLeftWidthHeight + paddingMarginBorder + "5px solid #000;"; | |
html = "<div " + style + "display:block;'><div style='" + paddingMarginBorder + "0;display:block;overflow:hidden;'></div></div>" + | |
"<table " + style + "' cellpadding='0' cellspacing='0'>" + | |
"<tr><td></td></tr></table>"; | |
container = document.createElement("div"); | |
container.style.cssText = paddingMarginBorderVisibility + "width:0;height:0;position:static;top:0;margin-top:" + conMarginTop + "px"; | |
body.insertBefore( container, body.firstChild ); | |
// Construct the test element | |
div = document.createElement("div"); | |
container.appendChild( div ); | |
// Check if table cells still have offsetWidth/Height when they are set | |
// to display:none and there are still other visible table cells in a | |
// table row; if so, offsetWidth/Height are not reliable for use when | |
// determining if an element has been hidden directly using | |
// display:none (it is still safe to use offsets if a parent element is | |
// hidden; don safety goggles and see bug #4512 for more information). | |
// (only IE 8 fails this test) | |
div.innerHTML = "<table><tr><td style='" + paddingMarginBorder + "0;display:none'></td><td>t</td></tr></table>"; | |
tds = div.getElementsByTagName( "td" ); | |
isSupported = ( tds[ 0 ].offsetHeight === 0 ); | |
tds[ 0 ].style.display = ""; | |
tds[ 1 ].style.display = "none"; | |
// Check if empty table cells still have offsetWidth/Height | |
// (IE <= 8 fail this test) | |
support.reliableHiddenOffsets = isSupported && ( tds[ 0 ].offsetHeight === 0 ); | |
// Check if div with explicit width and no margin-right incorrectly | |
// gets computed margin-right based on width of container. For more | |
// info see bug #3333 | |
// Fails in WebKit before Feb 2011 nightlies | |
// WebKit Bug 13343 - getComputedStyle returns wrong value for margin-right | |
if ( window.getComputedStyle ) { | |
div.innerHTML = ""; | |
marginDiv = document.createElement( "div" ); | |
marginDiv.style.width = "0"; | |
marginDiv.style.marginRight = "0"; | |
div.style.width = "2px"; | |
div.appendChild( marginDiv ); | |
support.reliableMarginRight = | |
( parseInt( ( window.getComputedStyle( marginDiv, null ) || { marginRight: 0 } ).marginRight, 10 ) || 0 ) === 0; | |
} | |
if ( typeof div.style.zoom !== "undefined" ) { | |
// Check if natively block-level elements act like inline-block | |
// elements when setting their display to 'inline' and giving | |
// them layout | |
// (IE < 8 does this) | |
div.innerHTML = ""; | |
div.style.width = div.style.padding = "1px"; | |
div.style.border = 0; | |
div.style.overflow = "hidden"; | |
div.style.display = "inline"; | |
div.style.zoom = 1; | |
support.inlineBlockNeedsLayout = ( div.offsetWidth === 3 ); | |
// Check if elements with layout shrink-wrap their children | |
// (IE 6 does this) | |
div.style.display = "block"; | |
div.style.overflow = "visible"; | |
div.innerHTML = "<div style='width:5px;'></div>"; | |
support.shrinkWrapBlocks = ( div.offsetWidth !== 3 ); | |
} | |
div.style.cssText = positionTopLeftWidthHeight + paddingMarginBorderVisibility; | |
div.innerHTML = html; | |
outer = div.firstChild; | |
inner = outer.firstChild; | |
td = outer.nextSibling.firstChild.firstChild; | |
offsetSupport = { | |
doesNotAddBorder: ( inner.offsetTop !== 5 ), | |
doesAddBorderForTableAndCells: ( td.offsetTop === 5 ) | |
}; | |
inner.style.position = "fixed"; | |
inner.style.top = "20px"; | |
// safari subtracts parent border width here which is 5px | |
offsetSupport.fixedPosition = ( inner.offsetTop === 20 || inner.offsetTop === 15 ); | |
inner.style.position = inner.style.top = ""; | |
outer.style.overflow = "hidden"; | |
outer.style.position = "relative"; | |
offsetSupport.subtractsBorderForOverflowNotVisible = ( inner.offsetTop === -5 ); | |
offsetSupport.doesNotIncludeMarginInBodyOffset = ( body.offsetTop !== conMarginTop ); | |
if ( window.getComputedStyle ) { | |
div.style.marginTop = "1%"; | |
support.pixelMargin = ( window.getComputedStyle( div, null ) || { marginTop: 0 } ).marginTop !== "1%"; | |
} | |
if ( typeof container.style.zoom !== "undefined" ) { | |
container.style.zoom = 1; | |
} | |
body.removeChild( container ); | |
marginDiv = div = container = null; | |
jQuery.extend( support, offsetSupport ); | |
}); | |
return support; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment