Skip to content
This repository has been archived by the owner on May 25, 2023. It is now read-only.

Commit

Permalink
Improve remove event bindings for classes options.
Browse files Browse the repository at this point in the history
  • Loading branch information
blueimp committed Feb 20, 2020
1 parent d5dfbc6 commit 5fd2f73
Showing 1 changed file with 21 additions and 5 deletions.
26 changes: 21 additions & 5 deletions js/vendor/jquery.ui.widget.js
Original file line number Diff line number Diff line change
Expand Up @@ -509,11 +509,29 @@
classes: this.options.classes || {}
}, options );

function bindRemoveEvent() {
options.element.each( function( _, element ) {
var isTracked = $.map( that.classesElementLookup, function( elements ) {
return elements;
} )
.some( function( elements ) {
return elements.is( element );
} );

if ( !isTracked ) {
that._on( $( element ), {
remove: "_untrackClassesElement"
} );
}
} );
}

function processClassString( classes, checkOption ) {
var current, i;
for ( i = 0; i < classes.length; i++ ) {
current = that.classesElementLookup[ classes[ i ] ] || $();
if ( options.add ) {
bindRemoveEvent();
current = $( $.unique( current.get().concat( options.element.get() ) ) );
} else {
current = $( current.not( options.element ).get() );
Expand All @@ -526,10 +544,6 @@
}
}

this._on( options.element, {
"remove": "_untrackClassesElement"
} );

if ( options.keys ) {
processClassString( options.keys.match( /\S+/g ) || [], true );
}
Expand All @@ -547,6 +561,8 @@
that.classesElementLookup[ key ] = $( value.not( event.target ).get() );
}
} );

this._off( $( event.target ) );
},

_removeClass: function( element, keys, extra ) {
Expand Down Expand Up @@ -627,7 +643,7 @@
_off: function( element, eventName ) {
eventName = ( eventName || "" ).split( " " ).join( this.eventNamespace + " " ) +
this.eventNamespace;
element.off( eventName ).off( eventName );
element.off( eventName );

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

0 comments on commit 5fd2f73

Please sign in to comment.