From 62436f4b292aadfe5419f897d7b8504054ab1c8c Mon Sep 17 00:00:00 2001 From: jeresig Date: Wed, 2 Dec 2009 17:15:09 -0500 Subject: [PATCH] Extracted the logic for copying events from one jQuery set to another, makes it easier to work with disconnected DOM nodes. --- src/manipulation.js | 35 ++++++++++++++++++++--------------- 1 file changed, 20 insertions(+), 15 deletions(-) diff --git a/src/manipulation.js b/src/manipulation.js index 105a0a9..baf99d5 100644 --- a/src/manipulation.js +++ b/src/manipulation.js @@ -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; -- 1.7.10.4