]> source.dussan.org Git - jquery.git/commitdiff
Added test for toggleClass, fixed jQuery.className.has to accept both node and classN...
authorJörn Zaefferer <joern.zaefferer@gmail.com>
Mon, 8 Jan 2007 16:12:20 +0000 (16:12 +0000)
committerJörn Zaefferer <joern.zaefferer@gmail.com>
Mon, 8 Jan 2007 16:12:20 +0000 (16:12 +0000)
src/jquery/coreTest.js
src/jquery/jquery.js

index a189739035697f798f18416923a61fc163c947db..7be53f738338d7af3f66338ee6033627445c280f 100644 (file)
@@ -429,6 +429,15 @@ test("removeClass(String) - add three classes and remove again", function() {
        ok( pass, "Remove multiple classes" );\r
 });\r
 \r
+test("toggleClass(String)", function() {\r
+       var e = $("#firstp");\r
+       ok( !e.is(".test"), "Assert class not present" );\r
+       e.toggleClass("test");\r
+       ok( e.is(".test"), "Assert class present" ); \r
+       e.toggleClass("test");\r
+       ok( !e.is(".test"), "Assert class not present" );\r
+});\r
+\r
 test("removeAttr(String", function() {\r
        ok( $('#mark').removeAttr("class")[0].className == "", "remove class" );\r
 });\r
index c8dcdd217799b5061e32ef23e57cbe0b1fce74e6..4fb7f8e75b86a147be99c51b9833206eec61705c 100644 (file)
@@ -1227,20 +1227,24 @@ jQuery.extend({
        },
 
        className: {
+               // internal only, use addClass("class")
                add: function( elem, c ){
                        jQuery.each( c.split(/\s+/), function(i, cur){
                                if ( !jQuery.className.has( elem.className, cur ) )
                                        elem.className += ( elem.className ? " " : "" ) + cur;
                        });
                },
+               // internal only, use removeClass("class")
                remove: function( elem, c ){
             elem.className = c ?
                 jQuery.grep( elem.className.split(/\s+/), function(cur){
                                    return !jQuery.className.has( c, cur );     
                 }).join(' ') : "";
                },
-               has: function( classes, c ){
-                       return classes && new RegExp("(^|\\s)" + c + "(\\s|$)").test( classes );
+               // internal only, use is(".class")
+               has: function( t, c ) {
+                       t = t.className || t;
+                       return t && new RegExp("(^|\\s)" + c + "(\\s|$)").test( t );
                }
        },