X-Git-Url: http://git.asbjorn.it/?a=blobdiff_plain;f=src%2Fcss.js;h=77949aebc60f56fa4237c0f61cbc738d5023a0e9;hb=0da700a4d03c1c43e75e3ab7f8e719e13c7e444a;hp=87f9abd70733903e81b1bd78dc536e6be738c327;hpb=37b607d2815b893d13de4ac3461090d0dd46535e;p=jquery.git diff --git a/src/css.js b/src/css.js index 87f9abd..77949ae 100644 --- a/src/css.js +++ b/src/css.js @@ -21,7 +21,9 @@ var ralpha = /alpha\([^)]*\)/, jQuery.fn.css = function( name, value ) { return jQuery.access( this, name, value, true, function( elem, name, value ) { - return jQuery.css( elem, name, value ); + return value !== undefined ? + jQuery.style( elem, name, value ) : + jQuery.css( elem, name ); }); }; @@ -62,7 +64,7 @@ jQuery.extend({ } // Make sure that we're working with the right name - var ret, origName = name.replace( rdashAlpha, fcamelCase ), + var ret, origName = jQuery.camelCase( name ), style = elem.style, hooks = jQuery.cssHooks[ origName ]; name = jQuery.cssProps[ origName ] || origName; @@ -90,19 +92,15 @@ jQuery.extend({ } }, - css: function( elem, name, value, extra ) { + css: function( elem, name, extra ) { // Make sure that we're working with the right name - var ret, origName = name.replace( rdashAlpha, fcamelCase ), + var ret, origName = jQuery.camelCase( name ), hooks = jQuery.cssHooks[ origName ]; name = jQuery.cssProps[ origName ] || origName; - // Check if we're setting a value, just use jQuery.style (DEPRECATED) - if ( value !== undefined ) { - jQuery.style( elem, name, value ); - // If a hook was provided get the computed value from there - } else if ( hooks && "get" in hooks && (ret = hooks.get( elem, true, extra )) !== undefined ) { + if ( hooks && "get" in hooks && (ret = hooks.get( elem, true, extra )) !== undefined ) { return ret; // Otherwise, if a way to get the computed value exists, use that @@ -127,9 +125,16 @@ jQuery.extend({ for ( name in options ) { elem.style[ name ] = old[ name ]; } + }, + + camelCase: function( string ) { + return string.replace( rdashAlpha, fcamelCase ); } }); +// DEPRECATED, Use jQuery.css() instead +jQuery.curCSS = jQuery.css; + jQuery.each(["height", "width"], function( i, name ) { jQuery.cssHooks[ name ] = { get: function( elem, computed, extra ) { @@ -150,11 +155,16 @@ jQuery.each(["height", "width"], function( i, name ) { }, set: function( elem, value ) { - // ignore negative width and height values #1599 - value = parseFloat(value); + if ( rnumpx.test( value ) ) { + // ignore negative width and height values #1599 + value = parseFloat(value); + + if ( value >= 0 ) { + return value + "px"; + } - if ( value >= 0 ) { - return value + "px"; + } else { + return value; } } }; @@ -164,7 +174,7 @@ if ( !jQuery.support.opacity ) { jQuery.cssHooks.opacity = { get: function( elem, computed ) { // IE uses filters for opacity - return ropacity.test((computed ? elem.currentStyle.filter : elem.style.filter) || "") ? + return ropacity.test((computed && elem.currentStyle ? elem.currentStyle.filter : elem.style.filter) || "") ? (parseFloat(RegExp.$1) / 100) + "" : "1"; }, @@ -177,11 +187,11 @@ if ( !jQuery.support.opacity ) { style.zoom = 1; // Set the alpha filter to set the opacity - var opacity = parseInt( value, 10 ) + "" === "NaN" ? + var opacity = isNaN(value) ? "" : "alpha(opacity=" + value * 100 + ")"; - var filter = style.filter || elem.currentStyle.filter || ""; + var filter = style.filter || elem.currentStyle && elem.currentStyle.filter || ""; style.filter = ralpha.test(filter) ? filter.replace(ralpha, opacity) : @@ -209,7 +219,7 @@ if ( getComputedStyle ) { } else if ( document.documentElement.currentStyle ) { curCSS = function( elem, name ) { - var left, rsLeft, ret = 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