]> source.dussan.org Git - jquery.git/commitdiff
Extracted the logic for copying events from one jQuery set to another, makes it easie...
authorjeresig <jeresig@gmail.com>
Wed, 2 Dec 2009 22:15:09 +0000 (17:15 -0500)
committerjeresig <jeresig@gmail.com>
Wed, 2 Dec 2009 22:15:09 +0000 (17:15 -0500)
src/manipulation.js

index 105a0a949bbfc4da1ada191d2ccf89324923478b..baf99d52d90626792b8c966b6dda28e45dd6e097 100644 (file)
@@ -168,21 +168,8 @@ jQuery.fn.extend({
 
                // Copy the events from the original to the clone
                if ( events === true ) {
-                       var orig = this.find("*").andSelf(), i = 0;
-
-                       ret.find("*").andSelf().each(function(){
-                               if ( this.nodeName !== orig[i].nodeName ) { return; }
-
-                               var events = jQuery.data( orig[i], "events" );
-
-                               for ( var type in events ) {
-                                       for ( var handler in events[ type ] ) {
-                                               jQuery.event.add( this, type, events[ type ][ handler ], events[ type ][ handler ].data );
-                                       }
-                               }
-
-                               i++;
-                       });
+                       cloneCopyEvent( this, ret );
+                       cloneCopyEvent( this.find("*"), ret.find("*") );
                }
 
                // Return the cloned set
@@ -284,6 +271,24 @@ jQuery.fn.extend({
        }
 });
 
+function cloneCopyEvent(orig, ret) {
+       var i = 0;
+
+       ret.each(function(){
+               if ( this.nodeName !== orig[i].nodeName ) {
+                       return;
+               }
+
+               var events = jQuery.data( orig[i], "events" );
+
+               for ( var type in events ) {
+                       for ( var handler in events[ type ] ) {
+                               jQuery.event.add( this, type, events[ type ][ handler ], events[ type ][ handler ].data );
+                       }
+               }
+       });
+}
+
 function buildFragment(args, nodes, scripts){
        var fragment, cacheable, cached, cacheresults, doc;