Skip to content

Commit dac716c

Browse files
committed
CSS: simplify hack of css getter for the computed values
Ref jquerygh-1906
1 parent d9d8906 commit dac716c

File tree

3 files changed

+18
-10
lines changed

3 files changed

+18
-10
lines changed

src/css/curCSS.js

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ if ( window.getComputedStyle ) {
7272
};
7373

7474
curCSS = function( elem, name, computed ) {
75-
var left, rs, rsLeft, ret,
75+
var left, ret,
7676
style = elem.style;
7777

7878
computed = computed || getStyles( elem );
@@ -84,7 +84,7 @@ if ( window.getComputedStyle ) {
8484
ret = style[ name ];
8585
}
8686

87-
// From the awesome hack by Dean Edwards
87+
// Simplified hack by Dean Edwards
8888
// http://erik.eae.net/archives/2007/07/27/18.54.15/#comment-102291
8989

9090
// If we're not dealing with a regular pixel number
@@ -97,21 +97,13 @@ if ( window.getComputedStyle ) {
9797

9898
// Remember the original values
9999
left = style.left;
100-
rs = elem.runtimeStyle;
101-
rsLeft = rs && rs.left;
102100

103101
// Put in the new values to get a computed value out
104-
if ( rsLeft ) {
105-
rs.left = elem.currentStyle.left;
106-
}
107102
style.left = name === "fontSize" ? "1em" : ret;
108103
ret = style.pixelLeft + "px";
109104

110105
// Revert the changed values
111106
style.left = left;
112-
if ( rsLeft ) {
113-
rs.left = rsLeft;
114-
}
115107
}
116108

117109
// Support: IE<9

test/data/testsuite.css

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,3 +163,8 @@ section { background:#f0f; display:block; }
163163
-ms-filter: "progid:DXImageTransform.Microsoft.Alpha(Opacity=50)";
164164
}
165165

166+
.get-computed-value {
167+
padding-left: 50%;
168+
width: 20%;
169+
font-size: 2em;
170+
}

test/unit/css.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,17 @@ test("css(String|Hash)", function() {
119119
"Make sure that a string z-index is returned from css('z-index') (#14432)." );
120120
});
121121

122+
test( "css(String) computed values", 3, function() {
123+
var div = jQuery( "<div/>" ).addClass( "get-computed-value" ),
124+
fixture = document.getElementById( "qunit-fixture" );
125+
126+
div.appendTo( fixture );
127+
strictEqual( div.css( "padding-left" ), "500px", "should get computed value for padding-left property" );
128+
strictEqual( div.css( "width" ), "200px", "should get computed value for width property" );
129+
strictEqual( div.css( "font-size" ), "32px", "should get computed value for font-size property" );
130+
});
131+
132+
122133
test( "css() explicit and relative values", 29, function() {
123134
var $elem = jQuery("#nothiddendiv");
124135

0 commit comments

Comments
 (0)