@@ -292,7 +292,15 @@ $.Widget.prototype = {
292
292
_init : $ . noop ,
293
293
294
294
destroy : function ( ) {
295
+ var that = this ;
295
296
this . _destroy ( ) ;
297
+
298
+ this . _gcClasses ( ) ;
299
+
300
+ $ . each ( this . classObject , function ( key , value ) {
301
+ that . _removeClass ( value , key ) ;
302
+ } ) ;
303
+
296
304
// we can probably remove the unbind calls in 2.0
297
305
// all event bindings should go through this._on()
298
306
this . element
@@ -304,9 +312,7 @@ $.Widget.prototype = {
304
312
this . widget ( )
305
313
. unbind ( this . eventNamespace )
306
314
. removeAttr ( "aria-disabled" )
307
- . removeClass (
308
- this . widgetFullName + "-disabled " +
309
- "ui-state-disabled" ) ;
315
+ . removeClass ( this . widgetFullName + "-disabled " + "ui-state-disabled" ) ;
310
316
311
317
// clean up events and states
312
318
this . bindings . unbind ( this . eventNamespace ) ;
@@ -401,25 +407,39 @@ $.Widget.prototype = {
401
407
} ,
402
408
403
409
_constructClasses : function ( element , keys , add , object ) {
404
- var i ,
410
+ var i , current ,
405
411
full = [ ] ,
406
412
keyArray = keys . split ( " " ) ;
407
413
408
414
object = object || this . options . classes ;
409
415
410
416
for ( i = 0 ; i < keyArray . length ; i ++ ) {
411
- this . classObject [ keyArray [ i ] ] = this . classObject [ keyArray [ i ] ] || $ ( ) ;
412
- this . classObject [ keyArray [ i ] ] [ add ? "add" : "filter" ] ( element ) ;
413
-
417
+ current = this . classObject [ keyArray [ i ] ] ;
418
+ this . classObject [ keyArray [ i ] ] = this . classObject [ keyArray [ i ] ] ? this . classObject [ keyArray [ i ] ] . add ( element ) : $ ( ) . add ( element ) ;
414
419
full . push ( keyArray [ i ] ) ;
415
420
416
421
if ( this . options . classes [ keyArray [ i ] ] ) {
417
- full . push ( this . options . classes [ keyArray [ i ] ] ) ;
422
+ full . push ( object [ keyArray [ i ] ] ) ;
418
423
}
419
424
}
420
425
return full . join ( " " ) ;
421
426
} ,
422
427
428
+ _gcClasses : function ( keys ) {
429
+ var that = this ;
430
+ keys = keys ? keys . split ( " " ) : this . classObject ;
431
+ $ . each ( keys , function ( key , value ) {
432
+ var classKey = ( typeof value === "string" ) ? value : key ;
433
+ if ( classKey && that . classObject [ classKey ] ) {
434
+ that . classObject [ classKey ] . each ( function ( ) {
435
+ if ( this !== that . element [ 0 ] && ( ! this . parentNode || ! this . parentNode . parentNode ) ) {
436
+ that . classObject [ classKey ] = that . classObject [ classKey ] . filter ( this ) ;
437
+ }
438
+ } ) ;
439
+ }
440
+ } ) ;
441
+ } ,
442
+
423
443
_removeClass : function ( element , keys , extra ) {
424
444
if ( typeof element === "string" ) {
425
445
extra = keys ;
0 commit comments