]> source.dussan.org Git - jquery.git/commitdiff
Landing pull request 383. Relocating jQuery.camelCase to core; Fixes #9368.
authorrwldrn <waldron.rick@gmail.com>
Wed, 25 May 2011 19:10:49 +0000 (15:10 -0400)
committertimmywil <tim.willison@thisismedium.com>
Wed, 25 May 2011 19:10:49 +0000 (15:10 -0400)
More Details:
 - https://github.com/jquery/jquery/pull/383
 - http://bugs.jquery.com/ticket/9368

src/core.js
src/css.js
test/unit/core.js

index 056fb88fbb0e36ef2d70b36070fc0fc267f6f31e..3a32d6f0c4e29394adead24b90b07fd486f9edd5 100644 (file)
@@ -44,6 +44,14 @@ var jQuery = function( selector, context ) {
        rmsie = /(msie) ([\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
        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 ) {
                return elem.nodeName && elem.nodeName.toUpperCase() === name.toUpperCase();
        },
index 661d800d707adca0b07e8a26c6f84b4864de7b34..46f6bf31f8ba6111194fb447982c34c44e40eb48 100644 (file)
@@ -2,7 +2,6 @@
 
 var ralpha = /alpha\([^)]*\)/i,
        ropacity = /opacity=([^)]*)/,
-       rdashAlpha = /-([a-z])/ig,
        // fixed for IE9, see #8346
        rupper = /([A-Z]|^ms)/g,
        rnumpx = /^-?\d+(?:px)?$/i,
@@ -16,11 +15,7 @@ var ralpha = /alpha\([^)]*\)/i,
        curCSS,
 
        getComputedStyle,
-       currentStyle,
-
-       fcamelCase = function( all, letter ) {
-               return letter.toUpperCase();
-       };
+       currentStyle;
 
 jQuery.fn.css = function( name, value ) {
        // Setting 'undefined' is a no-op
@@ -164,10 +159,6 @@ jQuery.extend({
                for ( name in options ) {
                        elem.style[ name ] = old[ name ];
                }
-       },
-
-       camelCase: function( string ) {
-               return string.replace( rdashAlpha, fcamelCase );
        }
 });
 
index 75d3e0e2c138ebffb9e0be3f3830a6e75fdaeaa9..3a15535264e2107eef68d023faf07a185bd5a7ea 100644 (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 );
+       });
+});