Commit 4b70f006 authored by John Resig's avatar John Resig

Made .clone(true) also copy over element data. Fixes #4191.

parent f6a0bf68
...@@ -277,13 +277,7 @@ function cloneCopyEvent(orig, ret) { ...@@ -277,13 +277,7 @@ function cloneCopyEvent(orig, ret) {
return; return;
} }
var events = jQuery.data( orig[i], "events" ); jQuery.data( this, jQuery.data( orig[i++] ) );
for ( var type in events ) {
for ( var handler in events[ type ] ) {
jQuery.event.add( this, type, events[ type ][ handler ], events[ type ][ handler ].data );
}
}
}); });
} }
......
...@@ -549,7 +549,7 @@ test("replaceAll(String|Element|Array<Element>|jQuery)", function() { ...@@ -549,7 +549,7 @@ test("replaceAll(String|Element|Array<Element>|jQuery)", function() {
}); });
test("clone()", function() { test("clone()", function() {
expect(28); expect(30);
equals( 'This is a normal link: Yahoo', jQuery('#en').text(), 'Assert text for #en' ); equals( 'This is a normal link: Yahoo', jQuery('#en').text(), 'Assert text for #en' );
var clone = jQuery('#yahoo').clone(); var clone = jQuery('#yahoo').clone();
equals( 'Try them out:Yahoo', jQuery('#first').append(clone).text(), 'Check for clone' ); equals( 'Try them out:Yahoo', jQuery('#first').append(clone).text(), 'Check for clone' );
...@@ -594,6 +594,11 @@ test("clone()", function() { ...@@ -594,6 +594,11 @@ test("clone()", function() {
div = div.clone(true); div = div.clone(true);
equals( div.length, 1, "One element cloned" ); equals( div.length, 1, "One element cloned" );
equals( div[0].nodeName.toUpperCase(), "DIV", "DIV element cloned" ); equals( div[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." );
}); });
if (!isLocal) { if (!isLocal) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment