Permalink
Browse files

Widget: Improve performance of cleanData method

Fixes #9546
Closes gh-1291
  • Loading branch information...
felvhage authored and scottgonzalez committed Jul 24, 2014
1 parent c399f1f commit f7429edfe96d322cdec850f7207efba8125767a6
Showing with 9 additions and 2 deletions.
  1. +9 −2 ui/widget.js
View
@@ -25,9 +25,16 @@ var widget_uuid = 0,
$.cleanData = (function( orig ) {
return function( elems ) {
- for ( var i = 0, elem; (elem = elems[i]) != null; i++ ) {
+ var events, elem, i;
+ for ( i = 0; (elem = elems[i]) != null; i++ ) {
try {
- $( elem ).triggerHandler( "remove" );
+
+ // Only trigger remove when necessary to save time
+ events = $._data( elem, "events" );
+ if ( events && events.remove ) {
+ $( elem ).triggerHandler( "remove" );
+ }
+
// http://bugs.jquery.com/ticket/8235
} catch( e ) {}
}

0 comments on commit f7429ed

Please sign in to comment.