Landing pull request 383. Relocating jQuery.camelCase to core; Fixes #9368.

More Details:
 - https://github.com/jquery/jquery/pull/383
 - http://bugs.jquery.com/ticket/9368
This commit is contained in:
rwldrn 2011-05-25 15:10:49 -04:00 committed by timmywil
parent b8fc9d14a1
commit 408c98fb4b
3 changed files with 29 additions and 10 deletions

View file

@ -44,6 +44,14 @@ var jQuery = function( selector, context ) {
rmsie = /(msie) ([\w.]+)/, rmsie = /(msie) ([\w.]+)/,
rmozilla = /(mozilla)(?:.*? rv:([\w.]+))?/, rmozilla = /(mozilla)(?:.*? rv:([\w.]+))?/,
// Matches dashed string for camelizing
rdashAlpha = /-([a-z])/ig,
// Used by jQuery.camelCase as callback to replace()
fcamelCase = function( all, letter ) {
return letter.toUpperCase();
},
// Keep a UserAgent string for use with jQuery.browser // Keep a UserAgent string for use with jQuery.browser
userAgent = navigator.userAgent, userAgent = navigator.userAgent,
@ -582,6 +590,12 @@ jQuery.extend({
} }
}, },
// Converts a dashed string to camelCased string;
// Used by both the css and data modules
camelCase: function( string ) {
return string.replace( rdashAlpha, fcamelCase );
},
nodeName: function( elem, name ) { nodeName: function( elem, name ) {
return elem.nodeName && elem.nodeName.toUpperCase() === name.toUpperCase(); return elem.nodeName && elem.nodeName.toUpperCase() === name.toUpperCase();
}, },

View file

@ -2,7 +2,6 @@
var ralpha = /alpha\([^)]*\)/i, var ralpha = /alpha\([^)]*\)/i,
ropacity = /opacity=([^)]*)/, ropacity = /opacity=([^)]*)/,
rdashAlpha = /-([a-z])/ig,
// fixed for IE9, see #8346 // fixed for IE9, see #8346
rupper = /([A-Z]|^ms)/g, rupper = /([A-Z]|^ms)/g,
rnumpx = /^-?\d+(?:px)?$/i, rnumpx = /^-?\d+(?:px)?$/i,
@ -16,11 +15,7 @@ var ralpha = /alpha\([^)]*\)/i,
curCSS, curCSS,
getComputedStyle, getComputedStyle,
currentStyle, currentStyle;
fcamelCase = function( all, letter ) {
return letter.toUpperCase();
};
jQuery.fn.css = function( name, value ) { jQuery.fn.css = function( name, value ) {
// Setting 'undefined' is a no-op // Setting 'undefined' is a no-op
@ -164,10 +159,6 @@ 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 );
} }
}); });

View file

@ -1104,3 +1104,17 @@ test("jQuery.sub() - .fn Methods", function(){
}); });
}); });
test("jQuery.camelCase()", function() {
var tests = {
"foo-bar": "fooBar",
"foo-bar-baz": "fooBarBaz"
};
expect(2);
jQuery.each( tests, function( key, val ) {
equal( jQuery.camelCase( key ), val, "Converts: " + key + " => " + val );
});
});