Skip to content
Permalink
Browse files

Fix #7717 and #7165. Thanks to dmethvin and iliakan for their help fi…

…xing these issues.
  • Loading branch information...
csnover committed Dec 19, 2010
1 parent 291b1ed commit faefbb1ad0b81e8001b582d06d5bd9c9236e62ce
Showing with 30 additions and 10 deletions.
  1. +6 −2 src/data.js
  2. +2 −2 src/manipulation.js
  3. +22 −6 test/unit/manipulation.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 ] );
@@ -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 ) {
@@ -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( '<div class="red"><span></span></div>' )).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("<label/>").wrap(val( "<li/>" ));
equals( j[0].nodeName.toUpperCase(), "LABEL", "Element is a label" );
equals( j[0].parentNode.nodeName.toUpperCase(), "LI", "Element has been wrapped" );

for (i in jQuery.cache) {
cacheLength--;
}
equals(cacheLength, 0, "No memory leak in jQuery.cache (bug #7165)");

// Wrap an element containing a text node
j = jQuery("<span/>").wrap("<div>test</div>");
equals( j[0].previousSibling.nodeType, 3, "Make sure the previous node is a text element" );
@@ -856,7 +866,7 @@ test("replaceAll(String|Element|Array&lt;Element&gt;|jQuery)", function() {
});

test("clone()", function() {
expect(36);
expect(37);
equals( 'This is a normal link: Yahoo', jQuery('#en').text(), 'Assert text for #en' );
var clone = jQuery('#yahoo').clone();
equals( 'Try them out:Yahoo', jQuery('#first').append(clone).text(), 'Check for clone' );
@@ -914,10 +924,16 @@ test("clone()", function() {
equals( clone.html(), div.html(), "Element contents cloned" );
equals( clone[0].nodeName.toUpperCase(), "DIV", "DIV element cloned" );

div = jQuery("<div/>").data({ a: true, b: true });
div = div.clone(true);
equals( div.data("a"), true, "Data cloned." );
equals( div.data("b"), true, "Data cloned." );
div = jQuery("<div/>").data({
a: true, b: true,
c: { nesty: ["Block", "Head"] }
});
var div2 = div.clone(true);
equals( div2.data("a"), true, "Data cloned." );
equals( div2.data("b"), true, "Data cloned." );
var c = div2.data("c");
c.nesty[0] = "Fish";
equals( div.data("c").nesty[0], "Block", "Ensure cloned element data is deep copied (Bug #7717)" );

var form = document.createElement("form");
form.action = "/test/";

0 comments on commit faefbb1

Please sign in to comment.
You can’t perform that action at this time.