11import jQuery from "../core.js" ;
22import stripAndCollapse from "../core/stripAndCollapse.js" ;
33import rnothtmlwhite from "../var/rnothtmlwhite.js" ;
4- import dataPriv from "../data/var/dataPriv.js" ;
54
65import "../core/init.js" ;
76
@@ -103,13 +102,6 @@ jQuery.fn.extend( {
103102 } ,
104103
105104 toggleClass : function ( value , stateVal ) {
106- var type = typeof value ,
107- isValidValue = type === "string" || Array . isArray ( value ) ;
108-
109- if ( typeof stateVal === "boolean" && isValidValue ) {
110- return stateVal ? this . addClass ( value ) : this . removeClass ( value ) ;
111- }
112-
113105 if ( typeof value === "function" ) {
114106 return this . each ( function ( i ) {
115107 jQuery ( this ) . toggleClass (
@@ -119,45 +111,25 @@ jQuery.fn.extend( {
119111 } ) ;
120112 }
121113
114+ if ( typeof stateVal === "boolean" ) {
115+ return stateVal ? this . addClass ( value ) : this . removeClass ( value ) ;
116+ }
117+
122118 return this . each ( function ( ) {
123119 var className , i , self , classNames ;
124120
125- if ( isValidValue ) {
126-
127- // Toggle individual class names
128- i = 0 ;
129- self = jQuery ( this ) ;
130- classNames = classesToArray ( value ) ;
131-
132- while ( ( className = classNames [ i ++ ] ) ) {
133-
134- // Check each className given, space separated list
135- if ( self . hasClass ( className ) ) {
136- self . removeClass ( className ) ;
137- } else {
138- self . addClass ( className ) ;
139- }
140- }
141-
142- // Toggle whole class name
143- } else if ( value === undefined || type === "boolean" ) {
144- className = getClass ( this ) ;
145- if ( className ) {
121+ // Toggle individual class names
122+ i = 0 ;
123+ self = jQuery ( this ) ;
124+ classNames = classesToArray ( value ) ;
146125
147- // Store className if set
148- dataPriv . set ( this , "__className__" , className ) ;
149- }
126+ while ( ( className = classNames [ i ++ ] ) ) {
150127
151- // If the element has a class name or if we're passed `false`,
152- // then remove the whole classname (if there was one, the above saved it).
153- // Otherwise bring back whatever was previously saved (if anything),
154- // falling back to the empty string if nothing was stored.
155- if ( this . setAttribute ) {
156- this . setAttribute ( "class" ,
157- className || value === false ?
158- "" :
159- dataPriv . get ( this , "__className__" ) || ""
160- ) ;
128+ // Check each className given, space separated list
129+ if ( self . hasClass ( className ) ) {
130+ self . removeClass ( className ) ;
131+ } else {
132+ self . addClass ( className ) ;
161133 }
162134 }
163135 } ) ;
0 commit comments