X-Git-Url: http://git.asbjorn.it/?a=blobdiff_plain;f=src%2Fcss.js;h=c32034d9482ccde3aa1f1c0d0c4519c34cd7c998;hb=f57d93bf18a2d5c3b7a0b50da67cf6147aa389c3;hp=973462b629616b6775c2614e9baec022453ffedc;hpb=ed087197cef89ce79cbd6b4ab49f184f3b259602;p=jquery.git diff --git a/src/css.js b/src/css.js index 973462b..c32034d 100644 --- a/src/css.js +++ b/src/css.js @@ -3,7 +3,10 @@ var exclude = /z-?index|font-?weight|opacity|zoom|line-?height/i, // cache check for defaultView.getComputedStyle getComputedStyle = document.defaultView && document.defaultView.getComputedStyle, // normalize float css property - styleFloat = jQuery.support.cssFloat ? "cssFloat" : "styleFloat"; + styleFloat = jQuery.support.cssFloat ? "cssFloat" : "styleFloat", + fcamelCase = function(all, letter){ + return letter.toUpperCase(); + }; jQuery.fn.css = function( name, value ) { var options = name, isFunction = jQuery.isFunction( value ); @@ -21,6 +24,13 @@ jQuery.fn.css = function( name, value ) { options[ name ] = value; } } + + var isFunction = {}; + + // For each value, determine whether it's a Function so we don't + // need to determine it again for each element + for ( var prop in options ) + isFunction[prop] = jQuery.isFunction( options[prop] ); // For each element... for ( var i = 0, l = this.length; i < l; i++ ) { @@ -30,9 +40,7 @@ jQuery.fn.css = function( name, value ) { for ( var prop in options ) { value = options[prop]; - if ( isFunction ) { - value = value.call( elem, i ); - } + if ( isFunction[prop] ) value = value.call( elem, i ); if ( typeof value === "number" && !exclude.test(prop) ) { value = value + "px"; @@ -70,7 +78,7 @@ jQuery.extend({ } return style.filter && style.filter.indexOf("opacity=") >= 0 ? - (parseFloat( style.filter.match(/opacity=([^)]*)/)[1] ) / 100) + '': + (parseFloat( /opacity=([^)]*)/.exec(style.filter)[1] ) / 100) + '': ""; } @@ -78,9 +86,7 @@ jQuery.extend({ if ( /float/i.test( name ) ) name = styleFloat; - name = name.replace(/-([a-z])/ig, function(all, letter){ - return letter.toUpperCase(); - }); + name = name.replace(/-([a-z])/ig, fcamelCase); if ( set ) style[ name ] = value; @@ -124,7 +130,7 @@ jQuery.extend({ // IE uses filters for opacity if ( !jQuery.support.opacity && name === "opacity" && elem.currentStyle ) { - ret = (elem.currentStyle.filter || "").match(/opacity=([^)]*)/) ? + ret = /opacity=([^)]*)/.test(elem.currentStyle.filter || "") ? (parseFloat(RegExp.$1) / 100) + "" : ""; @@ -158,9 +164,7 @@ jQuery.extend({ ret = "1"; } else if ( elem.currentStyle ) { - var camelCase = name.replace(/\-(\w)/g, function(all, letter){ - return letter.toUpperCase(); - }); + var camelCase = name.replace(/\-(\w)/g, fcamelCase); ret = elem.currentStyle[ name ] || elem.currentStyle[ camelCase ]; @@ -202,4 +206,4 @@ jQuery.extend({ for ( var name in options ) elem.style[ name ] = old[ name ]; } -}); \ No newline at end of file +});