24
24
}
25
25
} ( function ( $ ) {
26
26
27
- var baseClasses = "ui-button ui-widget" ,
28
- typeClasses = "ui-state-focus ui-radio-label ui-checkbox-label ui-state-active " +
29
- "ui-icon-beginning ui-icon-end ui-icon-top ui-icon-bottom ui-checkboxradio-radio-checked " +
30
- "ui-checkboxradio-checkbox-checked" ,
31
- formResetHandler = function ( ) {
27
+ var formResetHandler = function ( ) {
32
28
var form = $ ( this ) ;
33
29
setTimeout ( function ( ) {
34
30
form . find ( ".ui-checkboxradio" ) . checkboxradio ( "refresh" ) ;
@@ -59,11 +55,8 @@ $.widget( "ui.checkboxradio", {
59
55
label : null ,
60
56
icon : true ,
61
57
classes : {
62
- "ui-checkboxradio" : "" ,
63
58
"ui-checkboxradio-label" : "ui-corner-all" ,
64
- "ui-checkboxradio-radio-label" : "" ,
65
- "ui-checkboxradio-icon" : "ui-corner-all" ,
66
- "ui-checkboxradio-checked" : ""
59
+ "ui-checkboxradio-icon" : "ui-corner-all"
67
60
}
68
61
} ,
69
62
@@ -110,10 +103,10 @@ $.widget( "ui.checkboxradio", {
110
103
this . _on ( {
111
104
"change" : "_toggleClasses" ,
112
105
"focus" : function ( ) {
113
- this . label . addClass ( "ui-state-focus ui-visual-focus" ) ;
106
+ this . _addClass ( this . label , null , "ui-state-focus ui-visual-focus" ) ;
114
107
} ,
115
108
"blur" : function ( ) {
116
- this . label . removeClass ( "ui-state-focus ui-visual-focus" ) ;
109
+ this . _removeClass ( this . label , null , "ui-state-focus ui-visual-focus" ) ;
117
110
}
118
111
} ) ;
119
112
} ,
@@ -171,18 +164,15 @@ $.widget( "ui.checkboxradio", {
171
164
172
165
this . _setOption ( "disabled" , this . options . disabled ) ;
173
166
this . _updateIcon ( checked ) ;
174
- this . element . addClass ( "ui-helper-hidden-accessible " +
175
- this . _classes ( "ui-checkboxradio" ) ) ;
167
+ this . _addClass ( "ui-checkboxradio" , "ui-helper-hidden-accessible " ) ;
176
168
177
- this . label . addClass ( baseClasses + " " + this . _classes ( "ui-checkboxradio-label" ) ) ;
169
+ this . _addClass ( this . label , "ui-checkboxradio-label" , "ui-button ui-widget" ) ;
178
170
179
171
if ( this . type === "radio" ) {
180
- this . label . addClass ( "ui-checkboxradio-radio-label" ) ;
172
+ this . _addClass ( this . label , "ui-checkboxradio-radio-label" ) ;
181
173
}
182
-
183
174
if ( checked ) {
184
- this . label . addClass ( this . _classes ( "ui-checkboxradio-checked" ) +
185
- " ui-state-active" ) ;
175
+ this . _addClass ( this . label , "ui-checkboxradio-checked" , "ui-state-active" ) ;
186
176
}
187
177
if ( this . options . label && this . options . label !== this . originalLabel ) {
188
178
this . label . html ( this . icon ? this . icon : "" ) . append ( this . options . label ) ;
@@ -197,53 +187,29 @@ $.widget( "ui.checkboxradio", {
197
187
198
188
_toggleClasses : function ( ) {
199
189
var checked = this . element [ 0 ] . checked ;
200
- this . label . toggleClass ( this . _classes ( "ui-checkboxradio-checked" ) +
201
- " ui-state-active" , checked ) ;
190
+ this . _toggleClass ( this . label , "ui-checkboxradio-checked" , "ui-state-active" , checked ) ;
202
191
if ( this . options . icon && this . type === "checkbox" ) {
203
- this . icon
204
- . toggleClass ( "ui-icon-check" , checked )
205
- . toggleClass ( "ui-icon-blank" , ! checked ) ;
192
+ this . _toggleClass ( this . icon , null , "ui-icon-check" , checked )
193
+ . _toggleClass ( this . icon , null , "ui-icon-blank" , ! checked ) ;
206
194
}
207
195
if ( this . type === "radio" ) {
208
196
radioGroup ( this . element [ 0 ] )
209
197
. not ( this . element )
210
- . map ( function ( ) {
211
- return $ ( this ) . checkboxradio ( "widget" ) [ 0 ] ;
212
- } )
213
- . removeClass ( "ui-state-active " + this . _classes ( "ui-checkboxradio-checked" ) ) ;
198
+ . each ( function ( ) {
199
+ var instance = $ ( this ) . checkboxradio ( "instance" ) ;
200
+
201
+ if ( instance ) {
202
+ instance . _removeClass ( instance . label ,
203
+ "ui-checkboxradio-checked" , "ui-state-active" ) ;
204
+ }
205
+ } ) ;
214
206
}
215
207
} ,
216
208
217
209
_destroy : function ( ) {
218
- this . label . removeClass ( this . _classes ( "ui-checkboxradio-radio-label ui-checkboxradio-label" ) + " " +
219
- baseClasses + " " + typeClasses ) ;
220
210
if ( this . icon ) {
221
211
this . icon . remove ( ) ;
222
212
}
223
- this . element . removeClass ( this . _classes ( "ui-checkboxradio" ) +
224
- " ui-helper-hidden-accessible" ) ;
225
- } ,
226
-
227
- _elementsFromClassKey : function ( classKey ) {
228
- var parts = classKey . split ( "-" ) ,
229
- checkedType = parts [ 2 ] === this . type || parts [ 2 ] === undefined ,
230
- checkedClass = parts [ 3 ] === "checked" || this . element [ 0 ] . checked ;
231
- switch ( classKey ) {
232
- case "ui-checkboxradio" :
233
- case "ui-checkboxradio-radio-label" :
234
- case "ui-checkboxradio-label" :
235
- case "ui-checkboxradio-checked" :
236
- if ( checkedType && checkedClass ) {
237
- return this . label ;
238
- }
239
- return $ ( ) ;
240
- case "ui-checkboxradio-icon" :
241
- if ( this . icon ) {
242
- return this . icon ;
243
- }
244
- return $ ( ) ;
245
- }
246
- return this . _superApply ( arguments ) ;
247
213
} ,
248
214
249
215
_setOption : function ( key , value ) {
@@ -253,8 +219,8 @@ $.widget( "ui.checkboxradio", {
253
219
}
254
220
this . _super ( key , value ) ;
255
221
if ( key === "disabled" ) {
256
- this . label . toggleClass ( "ui-state-disabled" , ! ! value ) ;
257
- this . element [ 0 ] . disabled = ! ! value ;
222
+ this . _toggleClass ( this . label , null , "ui-state-disabled" , value ) ;
223
+ this . element [ 0 ] . disabled = value ;
258
224
return ;
259
225
}
260
226
if ( key === "label" && value === null ) {
@@ -264,11 +230,10 @@ $.widget( "ui.checkboxradio", {
264
230
} ,
265
231
266
232
_updateIcon : function ( checked ) {
267
- var toAdd = this . _classes ( "ui-checkboxradio-icon" ) +
268
- " ui-icon ui-icon-background " ;
233
+ var toAdd = "ui-icon ui-icon-background " ;
269
234
270
235
if ( this . options . icon ) {
271
- this . label . addClass ( "ui-icon-beginning" ) ;
236
+ this . _addClass ( this . label , null , "ui-icon-beginning" ) ;
272
237
if ( ! this . icon ) {
273
238
this . icon = $ ( "<span>" ) ;
274
239
}
@@ -278,9 +243,10 @@ $.widget( "ui.checkboxradio", {
278
243
} else {
279
244
toAdd += "ui-icon-blank" ;
280
245
}
281
- this . icon . addClass ( toAdd ) . appendTo ( this . label ) ;
246
+ this . _addClass ( this . icon , "ui-checkboxradio-icon" , toAdd ) ;
247
+ this . icon . appendTo ( this . label ) ;
282
248
} else if ( this . icon !== undefined ) {
283
- this . label . removeClass ( "ui-icon-beginning" ) ;
249
+ this . _removeClass ( this . label , null , "ui-icon-beginning" ) ;
284
250
this . icon . remove ( ) ;
285
251
delete this . icon ;
286
252
}
@@ -290,8 +256,7 @@ $.widget( "ui.checkboxradio", {
290
256
var checked = this . element [ 0 ] . checked ,
291
257
isDisabled = this . element [ 0 ] . disabled ;
292
258
this . _updateIcon ( checked ) ;
293
- this . label . toggleClass ( "ui-state-active " +
294
- this . _classes ( "ui-checkboxradio-checked" ) , checked ) ;
259
+ this . _toggleClass ( this . label , "ui-checkboxradio-checked" , "ui-state-active" , checked ) ;
295
260
if ( this . options . label !== null ) {
296
261
this . label . contents ( ) . not ( this . element . add ( this . icon ) ) . remove ( ) ;
297
262
this . label . append ( this . options . label ) ;
0 commit comments