X-Git-Url: http://git.asbjorn.biz/?a=blobdiff_plain;f=src%2Fcss.js;h=a6e2bb6143613a6d187a58c7f803d7beacff5afe;hb=a8fa5f2ec1030bceb9a65d0237f0c92ae4e014dd;hp=4bf818e5abeae651d2ee0c24e6f9fd6645cb7fad;hpb=06c505d85194890f8bacabc66895a6167b61728a;p=jquery.git diff --git a/src/css.js b/src/css.js index 4bf818e..a6e2bb6 100644 --- a/src/css.js +++ b/src/css.js @@ -12,9 +12,6 @@ var ralpha = /alpha\([^)]*\)/i, cssHeight = [ "Top", "Bottom" ], curCSS, - // cache check for defaultView.getComputedStyle - getComputedStyle = document.defaultView && document.defaultView.getComputedStyle, - fcamelCase = function( all, letter ) { return letter.toUpperCase(); }; @@ -70,7 +67,7 @@ jQuery.extend({ style: function( elem, name, value, extra ) { // Don't set styles on text and comment nodes if ( !elem || elem.nodeType === 3 || elem.nodeType === 8 || !elem.style ) { - return undefined; + return; } // Make sure that we're working with the right name @@ -81,6 +78,11 @@ jQuery.extend({ // Check if we're setting a value if ( value !== undefined ) { + // Make sure that NaN and null values aren't set. See: #7116 + if ( typeof value === "number" && isNaN( value ) || value == null ) { + return; + } + // If a number was passed in, add 'px' to the (except for certain CSS properties) if ( typeof value === "number" && !jQuery.cssNumber[ origName ] ) { value += "px"; @@ -88,7 +90,11 @@ jQuery.extend({ // If a hook was provided, use that value, otherwise just set the specified value if ( !hooks || !("set" in hooks) || (value = hooks.set( elem, value )) !== undefined ) { - style[ name ] = value; + // Wrapped to prevent IE from throwing errors when 'invalid' values are provided + // Fixes bug #5509 + try { + style[ name ] = value; + } catch(e) {} } } else { @@ -160,7 +166,25 @@ jQuery.each(["height", "width"], function( i, name ) { }); } - return val + "px"; + if ( val <= 0 ) { + val = curCSS( elem, name, name ); + + if ( val != null ) { + // Should return "auto" instead of 0, use 0 for + // temporary backwards-compat + return val === "" || val === "auto" ? "0px" : val; + } + } + + if ( val < 0 || val == null ) { + val = elem.style[ name ]; + + // Should return "auto" instead of 0, use 0 for + // temporary backwards-compat + return val === "" || val === "auto" ? "0px" : val; + } + + return typeof val === "string" ? val : val + "px"; } }, @@ -209,7 +233,7 @@ if ( !jQuery.support.opacity ) { }; } -if ( getComputedStyle ) { +if ( document.defaultView && document.defaultView.getComputedStyle ) { curCSS = function( elem, newName, name ) { var ret, defaultView, computedStyle; @@ -221,14 +245,18 @@ if ( getComputedStyle ) { if ( (computedStyle = defaultView.getComputedStyle( elem, null )) ) { ret = computedStyle.getPropertyValue( name ); + if ( ret === "" && !jQuery.contains( elem.ownerDocument.documentElement, elem ) ) { + ret = jQuery.style( elem, name ); + } } return ret; }; - } else if ( document.documentElement.currentStyle ) { curCSS = function( elem, name ) { - var left, rsLeft, ret = elem.currentStyle && elem.currentStyle[ name ], style = elem.style; + var left, rsLeft, + ret = elem.currentStyle && elem.currentStyle[ name ], + style = elem.style; // From the awesome hack by Dean Edwards // http://erik.eae.net/archives/2007/07/27/18.54.15/#comment-102291 @@ -250,7 +278,7 @@ if ( getComputedStyle ) { elem.runtimeStyle.left = rsLeft; } - return ret; + return ret === "" ? "auto" : ret; }; } @@ -280,14 +308,10 @@ function getWH( elem, name, extra ) { if ( jQuery.expr && jQuery.expr.filters ) { jQuery.expr.filters.hidden = function( elem ) { - var width = elem.offsetWidth, height = elem.offsetHeight, - skip = elem.nodeName.toLowerCase() === "tr"; - - return width === 0 && height === 0 && !skip ? - true : - width > 0 && height > 0 && !skip ? - false : - (elem.style.display || jQuery.css( elem, "display" )) === "none"; + var width = elem.offsetWidth, + height = elem.offsetHeight; + + return (width === 0 && height === 0) || (!jQuery.support.reliableHiddenOffsets && (elem.style.display || jQuery.css( elem, "display" )) === "none"); }; jQuery.expr.filters.visible = function( elem ) {