diff options
author | Michał Gołębiowski <m.goleb@gmail.com> | 2013-08-22 00:33:57 +0200 |
---|---|---|
committer | Michał Gołębiowski <m.goleb@gmail.com> | 2013-09-05 18:26:21 +0200 |
commit | 776012b8b3898fad2e0727880f1dc4af5c7b33c1 (patch) | |
tree | c03730b064fb22a1e87f9ac93d6b24710f6fa0e7 /src/support.js | |
parent | dfaee326e6605dc6d848c4c5022e39069d2cee65 (diff) | |
download | jquery-776012b8b3898fad2e0727880f1dc4af5c7b33c1.tar.gz jquery-776012b8b3898fad2e0727880f1dc4af5c7b33c1.zip |
Fix #14084: attach the test div to documentElement, not body.
Diffstat (limited to 'src/support.js')
-rw-r--r-- | src/support.js | 84 |
1 files changed, 37 insertions, 47 deletions
diff --git a/src/support.js b/src/support.js index 5880e2310..ec15b16f3 100644 --- a/src/support.js +++ b/src/support.js @@ -6,7 +6,11 @@ define([ ], function( jQuery ) { jQuery.support = (function( support ) { - var input = document.createElement("input"), + var container, marginDiv, divStyle, + // Support: Firefox, Android 2.3 (Prefixed box-sizing versions). + divReset = "padding:0;margin:0;border:0;display:block;-webkit-box-sizing:content-box;-moz-box-sizing:content-box;box-sizing:content-box", + docElem = document.documentElement, + input = document.createElement("input"), fragment = document.createDocumentFragment(), div = document.createElement("div"), select = document.createElement("select"), @@ -27,6 +31,10 @@ jQuery.support = (function( support ) { // Support: IE9, IE10 support.optSelected = opt.selected; + // This is hard-coded to true for compatibility reasons, + // all supported browsers passed the test. + support.boxSizing = true; + // Will be defined later support.reliableMarginRight = true; support.boxSizingReliable = true; @@ -67,53 +75,35 @@ jQuery.support = (function( support ) { div.cloneNode( true ).style.backgroundClip = ""; support.clearCloneStyle = div.style.backgroundClip === "content-box"; - // Run tests that need a body at doc ready - jQuery(function() { - var container, marginDiv, - // Support: Firefox, Android 2.3 (Prefixed box-sizing versions). - divReset = "padding:0;margin:0;border:0;display:block;-webkit-box-sizing:content-box;-moz-box-sizing:content-box;box-sizing:content-box", - body = document.getElementsByTagName("body")[ 0 ]; - - if ( !body ) { - // Return for frameset docs that don't have a body - return; - } - - container = document.createElement("div"); - container.style.cssText = "border:0;width:0;height:0;position:absolute;top:0;left:-9999px;margin-top:1px"; + container = document.createElement("div"); + container.style.cssText = "border:0;width:0;height:0;position:absolute;top:0;left:-9999px;margin-top:1px"; + + // Check box-sizing and margin behavior. + docElem.appendChild( container ).appendChild( div ); + div.innerHTML = ""; + // Support: Firefox, Android 2.3 (Prefixed box-sizing versions). + div.style.cssText = "-webkit-box-sizing:border-box;-moz-box-sizing:border-box;box-sizing:border-box;padding:1px;border:1px;display:block;width:4px;margin-top:1%;position:absolute;top:1%"; + + // Use window.getComputedStyle because jsdom on node.js will break without it. + if ( window.getComputedStyle ) { + divStyle = window.getComputedStyle( div, null ); + support.pixelPosition = ( divStyle || {} ).top !== "1%"; + support.boxSizingReliable = ( divStyle || { width: "4px" } ).width === "4px"; + + // Support: Android 2.3 + // Check if div with explicit width and no margin-right incorrectly + // gets computed margin-right based on width of container. (#3333) + // WebKit Bug 13343 - getComputedStyle returns wrong value for margin-right + marginDiv = div.appendChild( document.createElement( "div" ) ); + marginDiv.style.cssText = div.style.cssText = divReset; + marginDiv.style.marginRight = marginDiv.style.width = "0"; + div.style.width = "1px"; + + support.reliableMarginRight = + !parseFloat( ( window.getComputedStyle( marginDiv, null ) || {} ).marginRight ); + } - // Check box-sizing and margin behavior. - body.appendChild( container ).appendChild( div ); - div.innerHTML = ""; - // Support: Firefox, Android 2.3 (Prefixed box-sizing versions). - div.style.cssText = "-webkit-box-sizing:border-box;-moz-box-sizing:border-box;box-sizing:border-box;padding:1px;border:1px;display:block;width:4px;margin-top:1%;position:absolute;top:1%"; - - // Workaround failing boxSizing test due to offsetWidth returning wrong value - // with some non-1 values of body zoom, ticket #13543 - jQuery.swap( body, body.style.zoom != null ? { zoom: 1 } : {}, function() { - support.boxSizing = div.offsetWidth === 4; - }); - - // Use window.getComputedStyle because jsdom on node.js will break without it. - if ( window.getComputedStyle ) { - support.pixelPosition = ( window.getComputedStyle( div, null ) || {} ).top !== "1%"; - support.boxSizingReliable = ( window.getComputedStyle( div, null ) || { width: "4px" } ).width === "4px"; - - // Support: Android 2.3 - // Check if div with explicit width and no margin-right incorrectly - // gets computed margin-right based on width of container. (#3333) - // WebKit Bug 13343 - getComputedStyle returns wrong value for margin-right - marginDiv = div.appendChild( document.createElement("div") ); - marginDiv.style.cssText = div.style.cssText = divReset; - marginDiv.style.marginRight = marginDiv.style.width = "0"; - div.style.width = "1px"; - - support.reliableMarginRight = - !parseFloat( ( window.getComputedStyle( marginDiv, null ) || {} ).marginRight ); - } - - body.removeChild( container ); - }); + docElem.removeChild( container ); return support; })( {} ); |