diff options
author | Colin Snover <github.com@zetafleet.com> | 2011-01-17 15:31:43 -0600 |
---|---|---|
committer | Colin Snover <github.com@zetafleet.com> | 2011-01-17 15:31:43 -0600 |
commit | e78d3a7e2d47e9796f87c18b76f8178b0bee42c5 (patch) | |
tree | 1fced65554ceddbe4a2f30ba7102696c219c7815 /src/manipulation.js | |
parent | f01ef93aab1d2e90efbcacc71b01180f7f33656b (diff) | |
parent | 57cc182a40e909868d41f9b1bb405b06138f6cae (diff) | |
download | jquery-e78d3a7e2d47e9796f87c18b76f8178b0bee42c5.tar.gz jquery-e78d3a7e2d47e9796f87c18b76f8178b0bee42c5.zip |
Merge in data_nocollide branch. Fixes #6968, improves unit testing framework checks for leaky stuff.
Diffstat (limited to 'src/manipulation.js')
-rw-r--r-- | src/manipulation.js | 33 |
1 files changed, 20 insertions, 13 deletions
diff --git a/src/manipulation.js b/src/manipulation.js index cf533c818..596a45736 100644 --- a/src/manipulation.js +++ b/src/manipulation.js @@ -346,7 +346,7 @@ jQuery.fn.extend({ table ? root(this[i], first) : this[i], - i > 0 || results.cacheable || this.length > 1 ? + i > 0 || results.cacheable || (this.length > 1 && i > 0) ? jQuery(fragment).clone(true)[0] : fragment ); @@ -381,17 +381,24 @@ function cloneCopyEvent(orig, ret) { throw "Cloned data mismatch"; } - var oldData = jQuery.data( orig[nodeIndex] ), - curData = jQuery.data( this, oldData ), - events = oldData && oldData.events; + var internalKey = jQuery.expando, + oldData = jQuery.data( orig[nodeIndex] ), + curData = jQuery.data( this, oldData ); - if ( events ) { - delete curData.handle; - curData.events = {}; + // Switch to use the internal data object, if it exists, for the next + // stage of data copying + if ( (oldData = oldData[ internalKey ]) ) { + var events = oldData.events; + curData = curData[ internalKey ] = jQuery.extend({}, oldData); - for ( var type in events ) { - for ( var i = 0, l = events[ type ].length; i < l; i++ ) { - jQuery.event.add( this, type, events[ type ][ i ], events[ type ][ i ].data ); + if ( events ) { + delete curData.handle; + curData.events = {}; + + for ( var type in events ) { + for ( var i = 0, l = events[ type ].length; i < l; i++ ) { + jQuery.event.add( this, type, events[ type ][ i ], events[ type ][ i ].data ); + } } } } @@ -608,8 +615,7 @@ jQuery.extend({ }, cleanData: function( elems ) { - var data, id, cache = jQuery.cache, - special = jQuery.event.special, + var data, id, cache = jQuery.cache, internalKey = jQuery.expando, special = jQuery.event.special, deleteExpando = jQuery.support.deleteExpando; for ( var i = 0, elem; (elem = elems[i]) != null; i++ ) { @@ -620,13 +626,14 @@ jQuery.extend({ id = elem[ jQuery.expando ]; if ( id ) { - data = cache[ id ]; + data = cache[ id ] && cache[ id ][ internalKey ]; if ( data && data.events ) { for ( var type in data.events ) { if ( special[ type ] ) { jQuery.event.remove( elem, type ); + // This is a shortcut to avoid jQuery.event.remove's overhead } else { jQuery.removeEvent( elem, type, data.handle ); } |