From 8db7d6f20b4226994e88d1cd9243743c492773f5 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Micha=C5=82=20Go=C5=82=C4=99biowski?= Date: Mon, 4 Mar 2013 05:20:25 +0100 Subject: [PATCH] Fix #13543. offsetWidth is wrong on non-1 zoom. Close gh-1194. --- src/core.js | 25 ++++++++++++++++++++++++- src/css.js | 21 --------------------- src/support.js | 8 ++++++-- test/data/support/boxSizing.html | 19 +++++++++++++++++++ test/unit/support.js | 5 +++++ 5 files changed, 54 insertions(+), 24 deletions(-) create mode 100644 test/data/support/boxSizing.html diff --git a/src/core.js b/src/core.js index c0a32762..66c60774 100644 --- a/src/core.js +++ b/src/core.js @@ -781,7 +781,30 @@ jQuery.extend({ length ? fn( elems[0], key ) : emptyGet; }, - now: Date.now + now: Date.now, + + // A method for quickly swapping in/out CSS properties to get correct calculations. + // Note: this method belongs to the css module but it's needed here for the support module. + // If support gets modularized, this method should be moved back to the css module. + swap: function( elem, options, callback, args ) { + var ret, name, + old = {}; + + // Remember the old values, and insert the new ones + for ( name in options ) { + old[ name ] = elem.style[ name ]; + elem.style[ name ] = options[ name ]; + } + + ret = callback.apply( elem, args || [] ); + + // Revert the old values + for ( name in options ) { + elem.style[ name ] = old[ name ]; + } + + return ret; + } }); jQuery.ready.promise = function( obj ) { diff --git a/src/css.js b/src/css.js index 8684dc26..522982b3 100644 --- a/src/css.js +++ b/src/css.js @@ -277,27 +277,6 @@ jQuery.extend({ return extra === true || jQuery.isNumeric( num ) ? num || 0 : val; } return val; - }, - - // A method for quickly swapping in/out CSS properties to get correct calculations - swap: function( elem, options, callback, args ) { - var ret, name, - old = {}; - - // Remember the old values, and insert the new ones - for ( name in options ) { - old[ name ] = elem.style[ name ]; - elem.style[ name ] = options[ name ]; - } - - ret = callback.apply( elem, args || [] ); - - // Revert the old values - for ( name in options ) { - elem.style[ name ] = old[ name ]; - } - - return ret; } }); diff --git a/src/support.js b/src/support.js index bc02ee86..b80957a3 100644 --- a/src/support.js +++ b/src/support.js @@ -75,12 +75,16 @@ jQuery.support = (function( support ) { 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 + // Check box-sizing and margin behavior. body.appendChild( container ).appendChild( div ); div.innerHTML = ""; div.style.cssText = "box-sizing:border-box;-moz-box-sizing:border-box;-webkit-box-sizing:border-box;padding:1px;border:1px;display:block;width:4px;margin-top:1%;position:absolute;top:1%;"; - support.boxSizing = div.offsetWidth === 4; + // 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; + }); support.doesNotIncludeMarginInBodyOffset = body.offsetTop !== 1; // Use window.getComputedStyle because jsdom on node.js will break without it. diff --git a/test/data/support/boxSizing.html b/test/data/support/boxSizing.html new file mode 100644 index 00000000..2da883dc --- /dev/null +++ b/test/data/support/boxSizing.html @@ -0,0 +1,19 @@ + + + + + + + + + + + diff --git a/test/unit/support.js b/test/unit/support.js index 83a50f44..4754a68c 100644 --- a/test/unit/support.js +++ b/test/unit/support.js @@ -19,6 +19,11 @@ if ( jQuery.css ) { }); } +testIframeWithCallback( "A non-1 zoom on body doesn't cause WebKit to fail box-sizing test", "support/boxSizing.html", function( boxSizing ) { + expect( 1 ); + equal( boxSizing, jQuery.support.boxSizing, "box-sizing properly detected on page with non-1 body zoom" ); +}); + testIframeWithCallback( "A background on the testElement does not cause IE8 to crash (#9823)", "support/testElementCrash.html", function() { expect( 1 ); ok( true, "IE8 does not crash" ); -- 2.11.4.GIT