X-Git-Url: http://git.asbjorn.biz/?a=blobdiff_plain;f=src%2Fjquery%2Fjquery.js;h=8a2c6b2c0c2e36b88f2e8e0e2a7f9d7202a6b6d2;hb=a65a811ce03b2f7900ae0daa18d4d9fc213acbfd;hp=d6d3d6a2ded2f13762808a4c9421497fa5a1c96e;hpb=480aae72d3fe7c10eb51e310b88acc37c34f8bd8;p=jquery.git diff --git a/src/jquery/jquery.js b/src/jquery/jquery.js index d6d3d6a..8a2c6b2 100644 --- a/src/jquery/jquery.js +++ b/src/jquery/jquery.js @@ -852,27 +852,43 @@ jQuery.fn = jQuery.prototype = { * @cat DOM/Manipulation */ clone: function(deep) { - // Need to remove events on the element and its descendants + deep = deep != undefined ? deep : true var $this = this.add(this.find("*")); - $this.each(function() { - this._$events = {}; - for (var type in this.$events) - this._$events[type] = jQuery.extend({},this.$events[type]); - }).unbind(); + 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 var r = this.pushStack( jQuery.map( this, function(a){ - return a.cloneNode( deep != undefined ? deep : true ); + return a.cloneNode( deep ); }) ); - // Add the events back to the original and its descendants - $this.each(function() { - var events = this._$events; - for (var type in events) - for (var handler in events[type]) - jQuery.event.add(this, type, events[type][handler], events[type][handler].data); - this._$events = null; - }); + if (jQuery.browser.msie) { + $this.each(function() { + // Add the events back to the original and its descendants + var events = this._$events; + for (var type in events) + for (var handler in events[type]) + jQuery.event.add(this, type, events[type][handler], events[type][handler].data); + this._$events = null; + }); + } + + // copy form values over + if (deep) { + 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 r;