Skip to content

Commit fb44450

Browse files
committed
Opera doesn't give height/width of display: none elements with getComputedStyle but does with currentStyle - fall back to that if it exists.
1 parent 62c83a7 commit fb44450

File tree

1 file changed

+13
-6
lines changed

1 file changed

+13
-6
lines changed

src/css.js

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ var ralpha = /alpha\([^)]*\)/i,
1212
cssHeight = [ "Top", "Bottom" ],
1313
curCSS,
1414

15-
// cache check for defaultView.getComputedStyle
16-
getComputedStyle = document.defaultView && document.defaultView.getComputedStyle,
15+
getComputedStyle,
16+
currentStyle,
1717

1818
fcamelCase = function( all, letter ) {
1919
return letter.toUpperCase();
@@ -172,6 +172,10 @@ jQuery.each(["height", "width"], function( i, name ) {
172172
if ( val <= 0 ) {
173173
val = curCSS( elem, name, name );
174174

175+
if ( val === "0px" && currentStyle ) {
176+
val = currentStyle( elem, name, name );
177+
}
178+
175179
if ( val != null ) {
176180
return val;
177181
}
@@ -231,8 +235,8 @@ if ( !jQuery.support.opacity ) {
231235
};
232236
}
233237

234-
if ( getComputedStyle ) {
235-
curCSS = function( elem, newName, name ) {
238+
if ( document.defaultView && document.defaultView.getComputedStyle ) {
239+
getComputedStyle = function( elem, newName, name ) {
236240
var ret, defaultView, computedStyle;
237241

238242
name = name.replace( rupper, "-$1" ).toLowerCase();
@@ -250,9 +254,10 @@ if ( getComputedStyle ) {
250254

251255
return ret === "" ? "auto" : ret;
252256
};
257+
}
253258

254-
} else if ( document.documentElement.currentStyle ) {
255-
curCSS = function( elem, name ) {
259+
if ( document.documentElement.currentStyle ) {
260+
currentStyle = function( elem, name ) {
256261
var left, rsLeft, ret = elem.currentStyle && elem.currentStyle[ name ], style = elem.style;
257262

258263
// From the awesome hack by Dean Edwards
@@ -279,6 +284,8 @@ if ( getComputedStyle ) {
279284
};
280285
}
281286

287+
curCSS = getComputedStyle || currentStyle;
288+
282289
function getWH( elem, name, extra ) {
283290
var which = name === "width" ? cssWidth : cssHeight,
284291
val = name === "width" ? elem.offsetWidth : elem.offsetHeight;

0 commit comments

Comments
 (0)