make sure toggleClass does not delete classNames when forcefully removing classes and they are already removed
This commit is contained in:
parent
5e6e53835e
commit
e45b41602f
|
@ -141,13 +141,12 @@ jQuery.each({
|
||||||
jQuery.className[ state ? "add" : "remove" ]( this, className );
|
jQuery.className[ state ? "add" : "remove" ]( this, className );
|
||||||
}
|
}
|
||||||
} else if ( type === "undefined" || type === "boolean" ) {
|
} else if ( type === "undefined" || type === "boolean" ) {
|
||||||
// toggle whole className
|
if ( this.className ) {
|
||||||
if ( this.className || classNames === false ) {
|
// store className if set
|
||||||
jQuery.data( this, "__className__", this.className );
|
jQuery.data( this, "__className__", this.className );
|
||||||
this.className = "";
|
|
||||||
} else {
|
|
||||||
this.className = jQuery.data( this, "__className__" ) || "";
|
|
||||||
}
|
}
|
||||||
|
// toggle whole className
|
||||||
|
this.className = this.className || classNames === false ? "" : jQuery.data( this, "__className__" ) || "";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}, function(name, fn){
|
}, function(name, fn){
|
||||||
|
|
|
@ -282,7 +282,7 @@ test("removeClass(String) - simple", function() {
|
||||||
});
|
});
|
||||||
|
|
||||||
test("toggleClass(String|boolean|undefined[, boolean])", function() {
|
test("toggleClass(String|boolean|undefined[, boolean])", function() {
|
||||||
expect(16);
|
expect(17);
|
||||||
|
|
||||||
var e = jQuery("#firstp");
|
var e = jQuery("#firstp");
|
||||||
ok( !e.is(".test"), "Assert class not present" );
|
ok( !e.is(".test"), "Assert class not present" );
|
||||||
|
@ -310,17 +310,23 @@ test("toggleClass(String|boolean|undefined[, boolean])", function() {
|
||||||
// toggleClass storage
|
// toggleClass storage
|
||||||
e.toggleClass(true);
|
e.toggleClass(true);
|
||||||
ok( e.get(0).className === "", "Assert class is empty (data was empty)" );
|
ok( e.get(0).className === "", "Assert class is empty (data was empty)" );
|
||||||
e.addClass("testD");
|
e.addClass("testD testE");
|
||||||
ok( e.is(".testD"), "Assert class present" );
|
ok( e.is(".testD.testE"), "Assert class present" );
|
||||||
e.toggleClass();
|
e.toggleClass();
|
||||||
ok( !e.is(".testD"), "Assert class not present" );
|
ok( !e.is(".testD.testE"), "Assert class not present" );
|
||||||
ok( e.data('__className__') === 'testD', "Assert data was stored" );
|
ok( e.data('__className__') === 'testD testE', "Assert data was stored" );
|
||||||
e.toggleClass();
|
e.toggleClass();
|
||||||
ok( e.is(".testD"), "Assert class present (restored from data)" );
|
ok( e.is(".testD.testE"), "Assert class present (restored from data)" );
|
||||||
e.toggleClass(false);
|
e.toggleClass(false);
|
||||||
ok( !e.is(".testD"), "Assert class not present" );
|
ok( !e.is(".testD.testE"), "Assert class not present" );
|
||||||
e.toggleClass(true);
|
e.toggleClass(true);
|
||||||
ok( e.is(".testD"), "Assert class present (restored from data)" );
|
ok( e.is(".testD.testE"), "Assert class present (restored from data)" );
|
||||||
|
e.toggleClass();
|
||||||
|
e.toggleClass(false);
|
||||||
|
e.toggleClass();
|
||||||
|
ok( e.is(".testD.testE"), "Assert class present (restored from data)" );
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// Cleanup
|
// Cleanup
|
||||||
e.removeClass("testD");
|
e.removeClass("testD");
|
||||||
|
|
Loading…
Reference in a new issue