Attributes: Remove undocumented .toggleClass( boolean ) signature

Fixes gh-2491
Close gh-2618
This commit is contained in:
Dave Methvin
2015-09-25 17:11:01 -04:00
committed by Timmy Willison
parent 67d7a2eefe
commit 53f798cf4d
2 changed files with 21 additions and 76 deletions

View File

@@ -1,9 +1,8 @@
define( [
"../core",
"../var/rnotwhite",
"../data/var/dataPriv",
"../core/init"
], function( jQuery, rnotwhite, dataPriv ) {
], function( jQuery, rnotwhite ) {
var rclass = /[\t\r\n\f]/g;
@@ -100,60 +99,29 @@ jQuery.fn.extend( {
},
toggleClass: function( value, stateVal ) {
var type = typeof value;
var type = typeof value,
classNames = type === "string" ? value.match( rnotwhite ) : "",
checker = typeof stateVal === "boolean" ?
function() { return !stateVal; } :
jQuery.fn.hasClass;
if ( typeof stateVal === "boolean" && type === "string" ) {
return stateVal ? this.addClass( value ) : this.removeClass( value );
}
return this.each( function( i ) {
var className,
self = jQuery( this ),
c = 0;
if ( jQuery.isFunction( value ) ) {
return this.each( function( i ) {
jQuery( this ).toggleClass(
value.call( this, i, getClass( this ), stateVal ),
stateVal
);
} );
}
if ( type === "function" ) {
classNames = value.call( this, i, getClass( this ), stateVal )
.match( rnotwhite ) || [];
}
return this.each( function() {
var className, i, self, classNames;
// Toggle individual class names based on presence or stateVal
while ( ( className = classNames[ c++ ] ) ) {
if ( type === "string" ) {
// Toggle individual class names
i = 0;
self = jQuery( this );
classNames = value.match( rnotwhite ) || [];
while ( ( className = classNames[ i++ ] ) ) {
// Check each className given, space separated list
if ( self.hasClass( className ) ) {
self.removeClass( className );
} else {
self.addClass( className );
}
}
// Toggle whole class name
} else if ( value === undefined || type === "boolean" ) {
className = getClass( this );
if ( className ) {
// Store className if set
dataPriv.set( this, "__className__", className );
}
// If the element has a class name or if we're passed `false`,
// then remove the whole classname (if there was one, the above saved it).
// Otherwise bring back whatever was previously saved (if anything),
// falling back to the empty string if nothing was stored.
if ( this.setAttribute ) {
this.setAttribute( "class",
className || value === false ?
"" :
dataPriv.get( this, "__className__" ) || ""
);
if ( checker.call( self, className ) ) {
self.removeClass( className );
} else {
self.addClass( className );
}
}
} );