Commit 2929f8aa authored by John Resig's avatar John Resig

Landing the .clone() rewrite by Brandon (also includes the new event cloning...

Landing the .clone() rewrite by Brandon (also includes the new event cloning functionality .clone(true)).
parent cc22c04c
...@@ -228,44 +228,25 @@ jQuery.fn = jQuery.prototype = { ...@@ -228,44 +228,25 @@ jQuery.fn = jQuery.prototype = {
jQuery.unique( data ) : data ); jQuery.unique( data ) : data );
}, },
clone: function() { clone: function(events) {
var $this = this.add(this.find("*"));
if (jQuery.browser.msie) {
// Need to remove events on the element and its descendants
$this.each(function() {
this._$events = {};
for (var type in this.$events)
this._$events[type] = jQuery.extend({},this.$events[type]);
}).unbind();
}
// Do the clone // Do the clone
var r = this.pushStack( jQuery.map( this, function(a){ var ret = this.map(function(){
return a.cloneNode( true ); return this.outerHTML ? jQuery(this.outerHTML)[0] : this.cloneNode(true);
}) ); });
if (jQuery.browser.msie) { if (events === true) {
$this.each(function() { var clone = ret.find("*").andSelf();
// Add the events back to the original and its descendants
var events = this._$events; this.find("*").andSelf().each(function(i) {
for (var type in events) var events = this.$events;
for (var handler in events[type]) for ( var type in events )
jQuery.event.add(this, type, events[type][handler], events[type][handler].data); for ( var handler in events[type] )
this._$events = null; jQuery.event.add(clone[i], type, events[type][handler], events[type][handler].data);
}); });
} }
// copy form values over
var inputs = r.add(r.find('*')).filter('select,input[@type=checkbox]');
$this.filter('select,input[@type=checkbox]').each(function(i) {
if (this.selectedIndex)
inputs[i].selectedIndex = this.selectedIndex;
if (this.checked)
inputs[i].checked = true;
});
// Return the cloned set // Return the cloned set
return r; return ret;
}, },
filter: function(t) { filter: function(t) {
......
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