Simplifying the camelCase logic used in the CSS and Effects modules.

This commit is contained in:
John Resig 2010-09-17 14:53:10 -04:00
parent 6541eb9d80
commit 77e310b906
2 changed files with 8 additions and 9 deletions

View File

@ -64,7 +64,7 @@ jQuery.extend({
} }
// Make sure that we're working with the right name // 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 ]; style = elem.style, hooks = jQuery.cssHooks[ origName ];
name = jQuery.cssProps[ origName ] || origName; name = jQuery.cssProps[ origName ] || origName;
@ -94,7 +94,7 @@ jQuery.extend({
css: function( elem, name, extra ) { css: function( elem, name, extra ) {
// Make sure that we're working with the right name // 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 ]; hooks = jQuery.cssHooks[ origName ];
name = jQuery.cssProps[ origName ] || origName; name = jQuery.cssProps[ origName ] || origName;
@ -125,6 +125,10 @@ jQuery.extend({
for ( name in options ) { for ( name in options ) {
elem.style[ name ] = old[ name ]; elem.style[ name ] = old[ name ];
} }
},
camelCase: function( string ) {
return string.replace( rdashAlpha, fcamelCase );
} }
}); });

9
src/effects.js vendored
View File

@ -3,7 +3,6 @@
var elemdisplay = {}, var elemdisplay = {},
rfxtypes = /toggle|show|hide/, rfxtypes = /toggle|show|hide/,
rfxnum = /^([+\-]=)?([\d+.\-]+)(.*)$/, rfxnum = /^([+\-]=)?([\d+.\-]+)(.*)$/,
rdashAlpha = /-([a-z])/ig,
timerId, timerId,
fxAttrs = [ fxAttrs = [
// height animations // height animations
@ -12,11 +11,7 @@ var elemdisplay = {},
[ "width", "marginLeft", "marginRight", "paddingLeft", "paddingRight" ], [ "width", "marginLeft", "marginRight", "paddingLeft", "paddingRight" ],
// opacity animations // opacity animations
[ "opacity" ] [ "opacity" ]
], ];
fcamelCase = function( all, letter ) {
return letter.toUpperCase();
};
jQuery.fn.extend({ jQuery.fn.extend({
show: function( speed, callback ) { show: function( speed, callback ) {
@ -125,7 +120,7 @@ jQuery.fn.extend({
self = this; self = this;
for ( p in prop ) { for ( p in prop ) {
var name = p.replace(rdashAlpha, fcamelCase); var name = jQuery.camelCase( p );
if ( p !== name ) { if ( p !== name ) {
prop[ name ] = prop[ p ]; prop[ name ] = prop[ p ];