]> source.dussan.org Git - jquery.git/commitdiff
Revert "CSS: simplify hack of css getter for the computed values"
authorOleg Gaidarenko <markelog@gmail.com>
Tue, 22 Dec 2015 14:27:38 +0000 (17:27 +0300)
committerOleg Gaidarenko <markelog@gmail.com>
Tue, 22 Dec 2015 14:27:38 +0000 (17:27 +0300)
This reverts commit dac716ca65a83bab2449ffa35c43b4b52e26a0c1.

src/css/curCSS.js
test/data/testsuite.css
test/unit/css.js

index 8acf4903841a9fc3fad4f5adbc9c99c446d13b14..078cff6e1df1ddb9f539260eb39072b32653daab 100644 (file)
@@ -76,7 +76,7 @@ if ( window.getComputedStyle ) {
        };
 
        curCSS = function( elem, name, computed ) {
-               var left, ret,
+               var left, rs, rsLeft, ret,
                        style = elem.style;
 
                computed = computed || getStyles( elem );
@@ -88,7 +88,7 @@ if ( window.getComputedStyle ) {
                        ret = style[ name ];
                }
 
-               // Simplified hack by Dean Edwards
+               // From the awesome hack by Dean Edwards
                // http://erik.eae.net/archives/2007/07/27/18.54.15/#comment-102291
 
                // If we're not dealing with a regular pixel number
@@ -101,13 +101,21 @@ if ( window.getComputedStyle ) {
 
                        // Remember the original values
                        left = style.left;
+                       rs = elem.runtimeStyle;
+                       rsLeft = rs && rs.left;
 
                        // Put in the new values to get a computed value out
+                       if ( rsLeft ) {
+                               rs.left = elem.currentStyle.left;
+                       }
                        style.left = name === "fontSize" ? "1em" : ret;
                        ret = style.pixelLeft + "px";
 
                        // Revert the changed values
                        style.left = left;
+                       if ( rsLeft ) {
+                               rs.left = rsLeft;
+                       }
                }
 
                // Support: IE<9
index 9f80473d86c19e246db17b4db8f19bb115609b30..de5f3fb0081397c7ef3d635f1d9bb8a044a6cb05 100644 (file)
@@ -163,8 +163,3 @@ section { background:#f0f; display:block; }
        -ms-filter: "progid:DXImageTransform.Microsoft.Alpha(Opacity=50)";
 }
 
-.get-computed-value {
-       padding-left: 50%;
-       width: 20%;
-       font-size: 2em;
-}
index b15f2c76df6af62adb8cbc86dc5eaefc2ff7b34d..79dfbe90345ee10d19999efeca68910e44ce9ddb 100644 (file)
@@ -122,19 +122,8 @@ QUnit.test( "css(String|Hash)", function( assert ) {
 QUnit.test( "css(String) computed values", function( assert ) {
        assert.expect( 3 );
 
-       var div = jQuery( "<div/>" ).addClass( "get-computed-value" ),
-               fixture = document.getElementById( "qunit-fixture" );
-
-       div.appendTo( fixture );
-       assert.strictEqual( div.css( "padding-left" ), "500px", "should get computed value for padding-left property" );
-       assert.strictEqual( div.css( "width" ), "200px", "should get computed value for width property" );
-       assert.strictEqual( div.css( "font-size" ), "32px", "should get computed value for font-size property" );
-} );
-
-QUnit.test( "css() explicit and relative values", function( assert ) {
-       assert.expect( 29 );
-
-       var $elem = jQuery( "#nothiddendiv" );
+test( "css() explicit and relative values", 29, function() {
+       var $elem = jQuery("#nothiddendiv");
 
        $elem.css( { "width": 1, "height": 1, "paddingLeft": "1px", "opacity": 1 } );
        assert.equal( $elem.css( "width" ), "1px", "Initial css set or width/height works (hash)" );