aboutsummaryrefslogtreecommitdiffstats
path: root/src/manipulation.js
diff options
context:
space:
mode:
authorColin Snover <github.com@zetafleet.com>2011-01-09 15:52:33 -0600
committerColin Snover <github.com@zetafleet.com>2011-01-09 15:52:33 -0600
commit8e59a99e0ade75dec434f246f52e8b3f7393f359 (patch)
treefa4368b2445650070c78122102b7c85d5293116b /src/manipulation.js
parent1d1d4fe112c49cbd704d880b27cc646f2bfe1737 (diff)
downloadjquery-8e59a99e0ade75dec434f246f52e8b3f7393f359.tar.gz
jquery-8e59a99e0ade75dec434f246f52e8b3f7393f359.zip
Change the way jQuery.data works so that there is no longer a chance of collision between user data and internal data. Fixes #6968.
Diffstat (limited to 'src/manipulation.js')
-rw-r--r--src/manipulation.js35
1 files changed, 21 insertions, 14 deletions
diff --git a/src/manipulation.js b/src/manipulation.js
index 96caa02d0..657aef7d1 100644
--- a/src/manipulation.js
+++ b/src/manipulation.js
@@ -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;
-
- 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 );
+ var internalKey = jQuery.expando,
+ oldData = jQuery.data( orig[nodeIndex] ),
+ curData = jQuery.data( this, oldData );
+
+ // 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);
+
+ 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 );
+ }
}
}
}
@@ -594,8 +601,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++ ) {
@@ -606,13 +612,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 );
}