Skip to content

Commit ef2e9ba

Browse files
committed
Widget: Improve remove event bindings for classes options
Fixes #15078 Fixes #15082 Fixes #15095 Fixes #15136 Fixes #15152 Closes jquerygh-1769
1 parent c426b9a commit ef2e9ba

File tree

1 file changed

+21
-5
lines changed

1 file changed

+21
-5
lines changed

ui/widget.js

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -493,11 +493,29 @@ $.Widget.prototype = {
493493
classes: this.options.classes || {}
494494
}, options );
495495

496+
function bindRemoveEvent() {
497+
options.element.each( function( _, element ) {
498+
var isTracked = $.map( that.classesElementLookup, function( elements ) {
499+
return elements;
500+
} )
501+
.some( function( elements ) {
502+
return elements.is( element );
503+
} );
504+
505+
if ( !isTracked ) {
506+
that._on( $( element ), {
507+
remove: "_untrackClassesElement"
508+
} );
509+
}
510+
} );
511+
}
512+
496513
function processClassString( classes, checkOption ) {
497514
var current, i;
498515
for ( i = 0; i < classes.length; i++ ) {
499516
current = that.classesElementLookup[ classes[ i ] ] || $();
500517
if ( options.add ) {
518+
bindRemoveEvent();
501519
current = $( $.unique( current.get().concat( options.element.get() ) ) );
502520
} else {
503521
current = $( current.not( options.element ).get() );
@@ -510,10 +528,6 @@ $.Widget.prototype = {
510528
}
511529
}
512530

513-
this._on( options.element, {
514-
"remove": "_untrackClassesElement"
515-
} );
516-
517531
if ( options.keys ) {
518532
processClassString( options.keys.match( /\S+/g ) || [], true );
519533
}
@@ -531,6 +545,8 @@ $.Widget.prototype = {
531545
that.classesElementLookup[ key ] = $( value.not( event.target ).get() );
532546
}
533547
} );
548+
549+
this._off( $( event.target ) );
534550
},
535551

536552
_removeClass: function( element, keys, extra ) {
@@ -611,7 +627,7 @@ $.Widget.prototype = {
611627
_off: function( element, eventName ) {
612628
eventName = ( eventName || "" ).split( " " ).join( this.eventNamespace + " " ) +
613629
this.eventNamespace;
614-
element.off( eventName ).off( eventName );
630+
element.off( eventName );
615631

616632
// Clear the stack to avoid memory leaks (#10056)
617633
this.bindings = $( this.bindings.not( element ).get() );

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy