]> source.dussan.org Git - jquery.git/commitdiff
CSS: simplify hack of css getter for the computed values
authorOleg Gaidarenko <markelog@gmail.com>
Thu, 18 Dec 2014 15:36:58 +0000 (18:36 +0300)
committerOleg Gaidarenko <markelog@gmail.com>
Tue, 23 Dec 2014 23:46:09 +0000 (02:46 +0300)
Ref gh-1906

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

index 0b8f25997f2d6a197fd5fc28d4c0865e31c9ecf7..c3210f18650f4e183e650e33be1b0fbc96a06467 100644 (file)
@@ -72,7 +72,7 @@ if ( window.getComputedStyle ) {
        };
 
        curCSS = function( elem, name, computed ) {
-               var left, rs, rsLeft, ret,
+               var left, ret,
                        style = elem.style;
 
                computed = computed || getStyles( elem );
@@ -84,7 +84,7 @@ if ( window.getComputedStyle ) {
                        ret = style[ name ];
                }
 
-               // From the awesome hack by Dean Edwards
+               // Simplified 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
@@ -97,21 +97,13 @@ 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 de5f3fb0081397c7ef3d635f1d9bb8a044a6cb05..9f80473d86c19e246db17b4db8f19bb115609b30 100644 (file)
@@ -163,3 +163,8 @@ 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 a5bd304b24b1ec2f91ba29047df92ef7720a11c3..ffe607b156710190da02db2be07546daa315e465 100644 (file)
@@ -119,6 +119,17 @@ test("css(String|Hash)", function() {
                "Make sure that a string z-index is returned from css('z-index') (#14432)." );
 });
 
+test( "css(String) computed values", 3, function() {
+       var div = jQuery( "<div/>" ).addClass( "get-computed-value" ),
+               fixture = document.getElementById( "qunit-fixture" );
+
+       div.appendTo( fixture );
+       strictEqual( div.css( "padding-left" ), "500px", "should get computed value for padding-left property" );
+       strictEqual( div.css( "width" ), "200px", "should get computed value for width property" );
+       strictEqual( div.css( "font-size" ), "32px", "should get computed value for font-size property" );
+});
+
+
 test( "css() explicit and relative values", 29, function() {
        var $elem = jQuery("#nothiddendiv");