Skip to content

Commit

Permalink
Opera doesn't give height/width of display: none elements with getCom…
Browse files Browse the repository at this point in the history
…putedStyle but does with currentStyle - fall back to that if it exists.
  • Loading branch information
jeresig committed Nov 3, 2010
1 parent 62c83a7 commit fb44450
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions src/css.js
Expand Up @@ -12,8 +12,8 @@ var ralpha = /alpha\([^)]*\)/i,
cssHeight = [ "Top", "Bottom" ],
curCSS,

// cache check for defaultView.getComputedStyle
getComputedStyle = document.defaultView && document.defaultView.getComputedStyle,
getComputedStyle,
currentStyle,

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

if ( val === "0px" && currentStyle ) {
val = currentStyle( elem, name, name );
}

if ( val != null ) {
return val;
}
Expand Down Expand Up @@ -231,8 +235,8 @@ if ( !jQuery.support.opacity ) {
};
}

if ( getComputedStyle ) {
curCSS = function( elem, newName, name ) {
if ( document.defaultView && document.defaultView.getComputedStyle ) {
getComputedStyle = function( elem, newName, name ) {
var ret, defaultView, computedStyle;

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

return ret === "" ? "auto" : ret;
};
}

} else if ( document.documentElement.currentStyle ) {
curCSS = function( elem, name ) {
if ( document.documentElement.currentStyle ) {
currentStyle = function( elem, name ) {
var left, rsLeft, ret = elem.currentStyle && elem.currentStyle[ name ], style = elem.style;

// From the awesome hack by Dean Edwards
Expand All @@ -279,6 +284,8 @@ if ( getComputedStyle ) {
};
}

curCSS = getComputedStyle || currentStyle;

function getWH( elem, name, extra ) {
var which = name === "width" ? cssWidth : cssHeight,
val = name === "width" ? elem.offsetWidth : elem.offsetHeight;
Expand Down

2 comments on commit fb44450

@jitter
Copy link
Contributor

@jitter jitter commented on fb44450 Nov 3, 2010

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems like the fix for the bug I reported in #7336

@jdalton
Copy link
Member

@jdalton jdalton commented on fb44450 Nov 3, 2010

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I dig the fallback. Does this create an inconsistent behavior where browsers with currentStyle can resolve hidden element's height/width and those with just getComputedStyle cant?

Please sign in to comment.