aboutsummaryrefslogtreecommitdiffstats
path: root/ui/widget.js
diff options
context:
space:
mode:
authorScott González <scott.gonzalez@gmail.com>2016-11-16 14:42:34 -0500
committerScott González <scott.gonzalez@gmail.com>2017-04-19 12:53:53 -0400
commitef2e9bab92ae898311baa295590cd487d9071319 (patch)
tree240707b3d6c490bc0c3f63e0ff5bc75bd5639146 /ui/widget.js
parentc426b9a203271ab5e5e5f165a1d686c8281164bf (diff)
downloadjquery-ui-ef2e9bab92ae898311baa295590cd487d9071319.tar.gz
jquery-ui-ef2e9bab92ae898311baa295590cd487d9071319.zip
Widget: Improve `remove` event bindings for `classes` options
Fixes #15078 Fixes #15082 Fixes #15095 Fixes #15136 Fixes #15152 Closes gh-1769
Diffstat (limited to 'ui/widget.js')
-rw-r--r--ui/widget.js26
1 files changed, 21 insertions, 5 deletions
diff --git a/ui/widget.js b/ui/widget.js
index 726f70735..f87675712 100644
--- a/ui/widget.js
+++ b/ui/widget.js
@@ -493,11 +493,29 @@ $.Widget.prototype = {
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() );
@@ -510,10 +528,6 @@ $.Widget.prototype = {
}
}
- this._on( options.element, {
- "remove": "_untrackClassesElement"
- } );
-
if ( options.keys ) {
processClassString( options.keys.match( /\S+/g ) || [], true );
}
@@ -531,6 +545,8 @@ $.Widget.prototype = {
that.classesElementLookup[ key ] = $( value.not( event.target ).get() );
}
} );
+
+ this._off( $( event.target ) );
},
_removeClass: function( element, keys, extra ) {
@@ -611,7 +627,7 @@ $.Widget.prototype = {
_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() );