]> source.dussan.org Git - jquery.git/commitdiff
Fix for #921 (IE clones events)
authorBrandon Aaron <brandon.aaron@gmail.com>
Mon, 14 May 2007 17:46:00 +0000 (17:46 +0000)
committerBrandon Aaron <brandon.aaron@gmail.com>
Mon, 14 May 2007 17:46:00 +0000 (17:46 +0000)
src/jquery/jquery.js

index 61a190e80e1d2b6ce8cb05e6a0518d8a044f5906..fbd569629ce8946dff0d5fe1abd0b9fc246e16a6 100644 (file)
@@ -852,11 +852,30 @@ jQuery.fn = jQuery.prototype = {
         * @cat DOM/Manipulation
         */
        clone: function(deep) {
-               return this.pushStack( jQuery.map( this, function(a){
-                       a = a.cloneNode( deep != undefined ? deep : true );
-                       a.$events = null; // drop $events expando to avoid firing incorrect events
-                       return a;
+               // Need to remove events on the element and its descendants
+               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();
+
+               // Do the clone
+               var r = this.pushStack( jQuery.map( this, function(a){
+                       return a.cloneNode( deep != undefined ? deep : true );
                }) );
+
+               // 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;
+               });
+
+               // Return the cloned set
+               return r;
        },
 
        /**