@@ -301,10 +301,10 @@ $.Widget.prototype = {
301
301
this . uuid = widgetUuid ++ ;
302
302
this . eventNamespace = "." + this . widgetName + this . uuid ;
303
303
304
- this . bindings = $ ( ) ;
304
+ this . bindings = new Set ( ) ;
305
305
this . hoverable = $ ( ) ;
306
306
this . focusable = $ ( ) ;
307
- this . classesElementLookup = { } ;
307
+ this . classesElementLookup = Object . create ( null ) ;
308
308
309
309
if ( element !== this ) {
310
310
$ . data ( element , this . widgetFullName , this ) ;
@@ -355,7 +355,7 @@ $.Widget.prototype = {
355
355
356
356
this . _destroy ( ) ;
357
357
$ . each ( this . classesElementLookup , function ( key , value ) {
358
- that . _removeClass ( value , key ) ;
358
+ that . _removeClass ( $ ( Array . from ( value ) ) , key ) ;
359
359
} ) ;
360
360
361
361
// We can probably remove the unbind calls in 2.0
@@ -368,7 +368,7 @@ $.Widget.prototype = {
368
368
. removeAttr ( "aria-disabled" ) ;
369
369
370
370
// Clean up events and states
371
- this . bindings . off ( this . eventNamespace ) ;
371
+ $ ( Array . from ( this . bindings ) ) . off ( this . eventNamespace ) ;
372
372
} ,
373
373
374
374
_destroy : $ . noop ,
@@ -450,16 +450,12 @@ $.Widget.prototype = {
450
450
currentElements = this . classesElementLookup [ classKey ] ;
451
451
if ( value [ classKey ] === this . options . classes [ classKey ] ||
452
452
! currentElements ||
453
- ! currentElements . length ) {
453
+ ! currentElements . size ) {
454
454
continue ;
455
455
}
456
456
457
- // We are doing this to create a new jQuery object because the _removeClass() call
458
- // on the next line is going to destroy the reference to the current elements being
459
- // tracked. We need to save a copy of this collection so that we can add the new classes
460
- // below.
461
- elements = $ ( currentElements . get ( ) ) ;
462
- this . _removeClass ( currentElements , classKey ) ;
457
+ elements = $ ( Array . from ( currentElements ) ) ;
458
+ this . _removeClass ( elements , classKey ) ;
463
459
464
460
// We don't use _addClass() here, because that uses this.options.classes
465
461
// for generating the string of classes. We want to use the value passed in from
@@ -509,7 +505,7 @@ $.Widget.prototype = {
509
505
return elements ;
510
506
} )
511
507
. some ( function ( elements ) {
512
- return elements . is ( element ) ;
508
+ return elements . has ( element ) ;
513
509
} ) ;
514
510
515
511
if ( ! isTracked ) {
@@ -525,12 +521,24 @@ $.Widget.prototype = {
525
521
function processClassString ( classes , checkOption ) {
526
522
var current , i ;
527
523
for ( i = 0 ; i < classes . length ; i ++ ) {
528
- current = that . classesElementLookup [ classes [ i ] ] || $ ( ) ;
524
+ current = that . classesElementLookup [ classes [ i ] ] || new Set ( ) ;
529
525
if ( options . add ) {
530
526
bindRemoveEvent ( ) ;
531
- current = $ ( $ . uniqueSort ( current . get ( ) . concat ( options . element . get ( ) ) ) ) ;
527
+
528
+ // This function is invoked synchronously, so the reference
529
+ // to `current` is not an issue.
530
+ // eslint-disable-next-line no-loop-func
531
+ $ . each ( options . element , function ( _i , node ) {
532
+ current . add ( node ) ;
533
+ } ) ;
532
534
} else {
533
- current = $ ( current . not ( options . element ) . get ( ) ) ;
535
+
536
+ // This function is invoked synchronously, so the reference
537
+ // to `current` is not an issue.
538
+ // eslint-disable-next-line no-loop-func
539
+ $ . each ( options . element , function ( _i , node ) {
540
+ current . delete ( node ) ;
541
+ } ) ;
534
542
}
535
543
that . classesElementLookup [ classes [ i ] ] = current ;
536
544
full . push ( classes [ i ] ) ;
@@ -553,9 +561,7 @@ $.Widget.prototype = {
553
561
_untrackClassesElement : function ( event ) {
554
562
var that = this ;
555
563
$ . each ( that . classesElementLookup , function ( key , value ) {
556
- if ( $ . inArray ( event . target , value ) !== - 1 ) {
557
- that . classesElementLookup [ key ] = $ ( value . not ( event . target ) . get ( ) ) ;
558
- }
564
+ value . delete ( event . target ) ;
559
565
} ) ;
560
566
561
567
this . _off ( $ ( event . target ) ) ;
@@ -583,6 +589,7 @@ $.Widget.prototype = {
583
589
} ,
584
590
585
591
_on : function ( suppressDisabledCheck , element , handlers ) {
592
+ var i ;
586
593
var delegateElement ;
587
594
var instance = this ;
588
595
@@ -600,7 +607,11 @@ $.Widget.prototype = {
600
607
delegateElement = this . widget ( ) ;
601
608
} else {
602
609
element = delegateElement = $ ( element ) ;
603
- this . bindings = this . bindings . add ( element ) ;
610
+ for ( i = 0 ; i < element . length ; i ++ ) {
611
+ $ . each ( element , function ( _i , node ) {
612
+ instance . bindings . add ( node ) ;
613
+ } ) ;
614
+ }
604
615
}
605
616
606
617
$ . each ( handlers , function ( event , handler ) {
@@ -637,12 +648,17 @@ $.Widget.prototype = {
637
648
} ,
638
649
639
650
_off : function ( element , eventName ) {
651
+ var that = this ;
652
+
640
653
eventName = ( eventName || "" ) . split ( " " ) . join ( this . eventNamespace + " " ) +
641
654
this . eventNamespace ;
642
655
element . off ( eventName ) ;
643
656
657
+ $ . each ( element , function ( _i , node ) {
658
+ that . bindings . delete ( node ) ;
659
+ } ) ;
660
+
644
661
// Clear the stack to avoid memory leaks (#10056)
645
- this . bindings = $ ( this . bindings . not ( element ) . get ( ) ) ;
646
662
this . focusable = $ ( this . focusable . not ( element ) . get ( ) ) ;
647
663
this . hoverable = $ ( this . hoverable . not ( element ) . get ( ) ) ;
648
664
} ,
0 commit comments