Added test for toggleClass, fixed jQuery.className.has to accept both node and className (#762)
This commit is contained in:
parent
d97397d38e
commit
76d6d445bb
9
src/jquery/coreTest.js
vendored
9
src/jquery/coreTest.js
vendored
|
@ -429,6 +429,15 @@ test("removeClass(String) - add three classes and remove again", function() {
|
|||
ok( pass, "Remove multiple classes" );
|
||||
});
|
||||
|
||||
test("toggleClass(String)", function() {
|
||||
var e = $("#firstp");
|
||||
ok( !e.is(".test"), "Assert class not present" );
|
||||
e.toggleClass("test");
|
||||
ok( e.is(".test"), "Assert class present" );
|
||||
e.toggleClass("test");
|
||||
ok( !e.is(".test"), "Assert class not present" );
|
||||
});
|
||||
|
||||
test("removeAttr(String", function() {
|
||||
ok( $('#mark').removeAttr("class")[0].className == "", "remove class" );
|
||||
});
|
||||
|
|
8
src/jquery/jquery.js
vendored
8
src/jquery/jquery.js
vendored
|
@ -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 );
|
||||
}
|
||||
},
|
||||
|
||||
|
|
Loading…
Reference in a new issue