From faefbb1ad0b81e8001b582d06d5bd9c9236e62ce Mon Sep 17 00:00:00 2001 From: Colin Snover Date: Sun, 19 Dec 2010 15:33:53 -0600 Subject: [PATCH 001/110] Fix #7717 and #7165. Thanks to dmethvin and iliakan for their help fixing these issues. --- src/data.js | 8 ++++++-- src/manipulation.js | 4 ++-- test/unit/manipulation.js | 28 ++++++++++++++++++++++------ 3 files changed, 30 insertions(+), 10 deletions(-) diff --git a/src/data.js b/src/data.js index f1e031fff..120fe718d 100644 --- a/src/data.js +++ b/src/data.js @@ -9,7 +9,7 @@ jQuery.extend({ // Please use with caution uuid: 0, - // Unique for each copy of jQuery on the page + // Unique for each copy of jQuery on the page expando: "jQuery" + jQuery.now(), // The following elements throw uncatchable exceptions if you @@ -21,6 +21,10 @@ jQuery.extend({ "applet": true }, + hasData: function( elem ) { + return !elem.nodeType || (elem[ jQuery.expando ] && !jQuery.isEmptyObject(jQuery.cache[ elem[jQuery.expando] ])); + }, + data: function( elem, name, data ) { if ( !jQuery.acceptData( elem ) ) { return; @@ -144,7 +148,7 @@ jQuery.fn.extend({ var attr = this[0].attributes, name; for ( var i = 0, l = attr.length; i < l; i++ ) { name = attr[i].name; - + if ( name.indexOf( "data-" ) === 0 ) { name = name.substr( 5 ); dataAttr( this[0], name, data[ name ] ); diff --git a/src/manipulation.js b/src/manipulation.js index 7dea3493c..c23f62ed1 100644 --- a/src/manipulation.js +++ b/src/manipulation.js @@ -373,12 +373,12 @@ function cloneCopyEvent(orig, ret) { var i = 0; ret.each(function() { - if ( this.nodeType !== 1 || this.nodeName !== (orig[i] && orig[i].nodeName) ) { + if ( this.nodeType !== 1 || this.nodeName !== (orig[i] && orig[i].nodeName) || !jQuery.hasData(orig[i]) ) { return; } var oldData = jQuery.data( orig[i++] ), - curData = jQuery.data( this, oldData ), + curData = jQuery.data( this, jQuery.extend(true, {}, oldData) ), events = oldData && oldData.events; if ( events ) { diff --git a/test/unit/manipulation.js b/test/unit/manipulation.js index d49029eb8..52f76ed69 100644 --- a/test/unit/manipulation.js +++ b/test/unit/manipulation.js @@ -51,7 +51,7 @@ test("text(Function) with incoming value", function() { }); var testWrap = function(val) { - expect(18); + expect(19); var defaultText = 'Try them out:' var result = jQuery('#first').wrap(val( '
' )).text(); equals( defaultText, result, 'Check for wrapping of on-the-fly html' ); @@ -80,10 +80,20 @@ var testWrap = function(val) { equals( jQuery("#nonnodes > i").text(), j.text(), "Check node,textnode,comment wraps doesn't hurt text" ); // Try wrapping a disconnected node + var cacheLength = 0; + for (var i in jQuery.cache) { + cacheLength++; + } + j = jQuery("