From 776012b8b3898fad2e0727880f1dc4af5c7b33c1 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Micha=C5=82=20Go=C5=82e=CC=A8biowski?= Date: Thu, 22 Aug 2013 00:33:57 +0200 Subject: [PATCH] Fix #14084: attach the test div to documentElement, not body. --- .jshintignore | 2 + src/support.js | 84 ++++++++++------------- test/data/css/cssWidthBeforeDocReady.html | 26 +++++++ test/unit/css.js | 5 ++ 4 files changed, 70 insertions(+), 47 deletions(-) create mode 100644 test/data/css/cssWidthBeforeDocReady.html diff --git a/.jshintignore b/.jshintignore index 6c1c77037..894187dc1 100644 --- a/.jshintignore +++ b/.jshintignore @@ -5,3 +5,5 @@ test/data/badjson.js test/data/json_obj.js test/data/readywaitasset.js test/data/readywaitloader.js +test/data/support/csp.js +test/data/support/getComputedSupport.js 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; })( {} ); diff --git a/test/data/css/cssWidthBeforeDocReady.html b/test/data/css/cssWidthBeforeDocReady.html new file mode 100644 index 000000000..3bdd1b5ab --- /dev/null +++ b/test/data/css/cssWidthBeforeDocReady.html @@ -0,0 +1,26 @@ + + + + + + + +
+ + + + diff --git a/test/unit/css.js b/test/unit/css.js index 82fd6828a..ec7758c34 100644 --- a/test/unit/css.js +++ b/test/unit/css.js @@ -797,6 +797,11 @@ test("css('width') and css('height') should respect box-sizing, see #11004", fun equal( el_dis.css("height"), el_dis.css("height", el_dis.css("height")).css("height"), "css('height') is not respecting box-sizing for disconnected element, see #11004"); }); +testIframeWithCallback( "css('width') should works correctly before document ready", "css/cssWidthBeforeDocReady.html", function( cssWidthBeforeDocReady ) { + expect( 1 ); + strictEqual( cssWidthBeforeDocReady, "100px", "elem.css('width') works correctly before document ready" ); +}); + test("certain css values of 'normal' should be convertable to a number, see #8627", function() { expect ( 2 ); -- 2.39.5