@@ -20,45 +20,43 @@ function classesToArray( value ) {
20
20
21
21
jQuery . fn . extend ( {
22
22
addClass : function ( value ) {
23
- var classes , elem , cur , curValue , clazz , j , finalValue ,
24
- i = 0 ;
23
+ var classNames , cur , curValue , className , i , finalValue ;
25
24
26
25
if ( typeof value === "function" ) {
27
26
return this . each ( function ( j ) {
28
27
jQuery ( this ) . addClass ( value . call ( this , j , getClass ( this ) ) ) ;
29
28
} ) ;
30
29
}
31
30
32
- classes = classesToArray ( value ) ;
31
+ classNames = classesToArray ( value ) ;
33
32
34
- if ( classes . length ) {
35
- while ( ( elem = this [ i ++ ] ) ) {
36
- curValue = getClass ( elem ) ;
37
- cur = elem . nodeType === 1 && ( " " + stripAndCollapse ( curValue ) + " " ) ;
33
+ if ( classNames . length ) {
34
+ return this . each ( function ( ) {
35
+ curValue = getClass ( this ) ;
36
+ cur = this . nodeType === 1 && ( " " + stripAndCollapse ( curValue ) + " " ) ;
38
37
39
38
if ( cur ) {
40
- j = 0 ;
41
- while ( ( clazz = classes [ j ++ ] ) ) {
42
- if ( cur . indexOf ( " " + clazz + " " ) < 0 ) {
43
- cur += clazz + " " ;
39
+ for ( i = 0 ; i < classNames . length ; i ++ ) {
40
+ className = classNames [ i ] ;
41
+ if ( cur . indexOf ( " " + className + " " ) < 0 ) {
42
+ cur += className + " " ;
44
43
}
45
44
}
46
45
47
46
// Only assign if different to avoid unneeded rendering.
48
47
finalValue = stripAndCollapse ( cur ) ;
49
48
if ( curValue !== finalValue ) {
50
- elem . setAttribute ( "class" , finalValue ) ;
49
+ this . setAttribute ( "class" , finalValue ) ;
51
50
}
52
51
}
53
- }
52
+ } ) ;
54
53
}
55
54
56
55
return this ;
57
56
} ,
58
57
59
58
removeClass : function ( value ) {
60
- var classes , elem , cur , curValue , clazz , j , finalValue ,
61
- i = 0 ;
59
+ var classNames , cur , curValue , className , i , finalValue ;
62
60
63
61
if ( typeof value === "function" ) {
64
62
return this . each ( function ( j ) {
@@ -70,38 +68,40 @@ jQuery.fn.extend( {
70
68
return this . attr ( "class" , "" ) ;
71
69
}
72
70
73
- classes = classesToArray ( value ) ;
71
+ classNames = classesToArray ( value ) ;
74
72
75
- if ( classes . length ) {
76
- while ( ( elem = this [ i ++ ] ) ) {
77
- curValue = getClass ( elem ) ;
73
+ if ( classNames . length ) {
74
+ return this . each ( function ( ) {
75
+ curValue = getClass ( this ) ;
78
76
79
77
// This expression is here for better compressibility (see addClass)
80
- cur = elem . nodeType === 1 && ( " " + stripAndCollapse ( curValue ) + " " ) ;
78
+ cur = this . nodeType === 1 && ( " " + stripAndCollapse ( curValue ) + " " ) ;
81
79
82
80
if ( cur ) {
83
- j = 0 ;
84
- while ( ( clazz = classes [ j ++ ] ) ) {
81
+ for ( i = 0 ; i < classNames . length ; i ++ ) {
82
+ className = classNames [ i ] ;
85
83
86
84
// Remove *all* instances
87
- while ( cur . indexOf ( " " + clazz + " " ) > - 1 ) {
88
- cur = cur . replace ( " " + clazz + " " , " " ) ;
85
+ while ( cur . indexOf ( " " + className + " " ) > - 1 ) {
86
+ cur = cur . replace ( " " + className + " " , " " ) ;
89
87
}
90
88
}
91
89
92
90
// Only assign if different to avoid unneeded rendering.
93
91
finalValue = stripAndCollapse ( cur ) ;
94
92
if ( curValue !== finalValue ) {
95
- elem . setAttribute ( "class" , finalValue ) ;
93
+ this . setAttribute ( "class" , finalValue ) ;
96
94
}
97
95
}
98
- }
96
+ } ) ;
99
97
}
100
98
101
99
return this ;
102
100
} ,
103
101
104
102
toggleClass : function ( value , stateVal ) {
103
+ var classNames , className , i , self ;
104
+
105
105
if ( typeof value === "function" ) {
106
106
return this . each ( function ( i ) {
107
107
jQuery ( this ) . toggleClass (
@@ -115,24 +115,28 @@ jQuery.fn.extend( {
115
115
return stateVal ? this . addClass ( value ) : this . removeClass ( value ) ;
116
116
}
117
117
118
- return this . each ( function ( ) {
119
- var className , i , self , classNames ;
118
+ classNames = classesToArray ( value ) ;
120
119
121
- // Toggle individual class names
122
- i = 0 ;
123
- self = jQuery ( this ) ;
124
- classNames = classesToArray ( value ) ;
120
+ if ( classNames . length ) {
121
+ return this . each ( function ( ) {
125
122
126
- while ( ( className = classNames [ i ++ ] ) ) {
123
+ // Toggle individual class names
124
+ self = jQuery ( this ) ;
127
125
128
- // Check each className given, space separated list
129
- if ( self . hasClass ( className ) ) {
130
- self . removeClass ( className ) ;
131
- } else {
132
- self . addClass ( className ) ;
126
+ for ( i = 0 ; i < classNames . length ; i ++ ) {
127
+ className = classNames [ i ] ;
128
+
129
+ // Check each className given, space separated list
130
+ if ( self . hasClass ( className ) ) {
131
+ self . removeClass ( className ) ;
132
+ } else {
133
+ self . addClass ( className ) ;
134
+ }
133
135
}
134
- }
135
- } ) ;
136
+ } ) ;
137
+ }
138
+
139
+ return this ;
136
140
} ,
137
141
138
142
hasClass : function ( selector ) {
0 commit comments