X-Git-Url: http://git.asbjorn.biz/?a=blobdiff_plain;f=src%2Fcss.js;h=5d31757b0537db1c761f75249462b883b97b17f6;hb=31f1e99500af6e57cfdd571272be193b4646fc09;hp=7215fe620506884607f852a32c56b8d429f04ceb;hpb=4e9fed3b16ed9612ed373d14a89294e98054f4dd;p=jquery.git diff --git a/src/css.js b/src/css.js index 7215fe6..5d31757 100644 --- a/src/css.js +++ b/src/css.js @@ -8,11 +8,15 @@ var rexclude = /z-?index|font-?weight|opacity|zoom|line-?height/i, rnumpx = /^-?\d+(?:px)?$/i, rnum = /^-?\d/, + cssShow = { position: "absolute", visibility: "hidden", display:"block" }, + cssWidth = [ "Left", "Right" ], + cssHeight = [ "Top", "Bottom" ], + // cache check for defaultView.getComputedStyle getComputedStyle = document.defaultView && document.defaultView.getComputedStyle, // normalize float css property styleFloat = jQuery.support.cssFloat ? "cssFloat" : "styleFloat", - fcamelCase = function(all, letter){ + fcamelCase = function( all, letter ) { return letter.toUpperCase(); }; @@ -52,13 +56,13 @@ jQuery.extend({ style.zoom = 1; // Set the alpha filter to set the opacity - var opacity = parseInt( value, 10 ) + '' === "NaN" ? "" : "alpha(opacity=" + value * 100 + ")"; - var filter = style.filter || jQuery.curCSS( elem, 'filter' ) || ""; + var opacity = parseInt( value, 10 ) + "" === "NaN" ? "" : "alpha(opacity=" + value * 100 + ")"; + var filter = style.filter || jQuery.curCSS( elem, "filter" ) || ""; style.filter = ralpha.test(filter) ? filter.replace(ralpha, opacity) : opacity; } return style.filter && style.filter.indexOf("opacity=") >= 0 ? - (parseFloat( ropacity.exec(style.filter)[1] ) / 100) + '': + (parseFloat( ropacity.exec(style.filter)[1] ) / 100) + "": ""; } @@ -78,12 +82,14 @@ jQuery.extend({ css: function( elem, name, force, extra ) { if ( name === "width" || name === "height" ) { - var val, props = { position: "absolute", visibility: "hidden", display:"block" }, which = name === "width" ? [ "Left", "Right" ] : [ "Top", "Bottom" ]; + var val, props = cssShow, which = name === "width" ? cssWidth : cssHeight; function getWH() { val = name === "width" ? elem.offsetWidth : elem.offsetHeight; - if ( extra === "border" ) { return; } + if ( extra === "border" ) { + return; + } jQuery.each( which, function() { if ( !extra ) { @@ -141,7 +147,13 @@ jQuery.extend({ name = name.replace( rupper, "-$1" ).toLowerCase(); - var computedStyle = elem.ownerDocument.defaultView.getComputedStyle( elem, null ); + var defaultView = elem.ownerDocument.defaultView; + + if ( !defaultView ) { + return null; + } + + var computedStyle = defaultView.getComputedStyle( elem, null ); if ( computedStyle ) { ret = computedStyle.getPropertyValue( name );