aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorjeresig <jeresig@gmail.com>2009-12-02 17:15:09 -0500
committerjeresig <jeresig@gmail.com>2009-12-02 17:15:09 -0500
commit62436f4b292aadfe5419f897d7b8504054ab1c8c (patch)
tree160cb72da79480f4b64065b01512b97078f63a7d /src
parent391f83b2a251abd5ab27aeb52a647a853906ce66 (diff)
downloadjquery-62436f4b292aadfe5419f897d7b8504054ab1c8c.tar.gz
jquery-62436f4b292aadfe5419f897d7b8504054ab1c8c.zip
Extracted the logic for copying events from one jQuery set to another, makes it easier to work with disconnected DOM nodes.
Diffstat (limited to 'src')
-rw-r--r--src/manipulation.js35
1 files changed, 20 insertions, 15 deletions
diff --git a/src/manipulation.js b/src/manipulation.js
index 105a0a949..baf99d52d 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;