smartxml: data cloning handler gets reference to the cloned node
authorAleksander Łukasz <aleksander.lukasz@nowoczesnapolska.org.pl>
Thu, 16 Jan 2014 14:37:43 +0000 (15:37 +0100)
committerAleksander Łukasz <aleksander.lukasz@nowoczesnapolska.org.pl>
Fri, 17 Jan 2014 14:24:55 +0000 (15:24 +0100)
src/smartxml/smartxml.js

index e525c14..d168e6d 100644 (file)
@@ -33,14 +33,17 @@ $.extend(DocumentNode.prototype, {
     },
 
     clone: function() {
     },
 
     clone: function() {
-        var clone = this._$.clone(true, true);
+        var clone = this._$.clone(true, true),
+            node = this;
         clone.find('*').addBack().each(function() {
         clone.find('*').addBack().each(function() {
-            var clonedData = $(this).data();
+            var el = this,
+                clonedData = $(this).data();
+
             _.pairs(clonedData).forEach(function(pair) {
                 var key = pair[0],
                     value = pair[1];
                 if(_.isFunction(value.clone)) {
             _.pairs(clonedData).forEach(function(pair) {
                 var key = pair[0],
                     value = pair[1];
                 if(_.isFunction(value.clone)) {
-                    clonedData[key] = value.clone();
+                    clonedData[key] = value.clone(node.document.createDocumentNode(el));
                 }
             });
         });
                 }
             });
         });