Refactoring
authorAleksander Łukasz <aleksander.lukasz@nowoczesnapolska.org.pl>
Thu, 25 Jul 2013 07:14:41 +0000 (09:14 +0200)
committerAleksander Łukasz <aleksander.lukasz@nowoczesnapolska.org.pl>
Thu, 25 Jul 2013 12:34:38 +0000 (14:34 +0200)
modules/documentCanvas/canvas/documentElement.js

index 9359134..b2625e1 100644 (file)
@@ -200,23 +200,22 @@ $.extend(DocumentNodeElement.prototype, {
             childParts,
             prevChildParts;
 
             childParts,
             prevChildParts;
 
+        var containsPrefixAndSuffix = function(idx) {
+            if(idx === children.length - 1 && node.contents().length === 2)
+                return true;
+            if(prevChildParts && prevChildParts.length > 1 && prevChildParts[0].nodeType === Node.TEXT_NODE && prevChildParts[1].nodeType === Node.TEXT_NODE)
+                return true;
+            return false;
+        }
+
         for(var i = children.length - 1; i >= 0; i--) {
             childParts = children[i].toXML(level + 1);
             
         for(var i = children.length - 1; i >= 0; i--) {
             childParts = children[i].toXML(level + 1);
             
-            if(i === children.length - 1 && node.contents().length === 2) {
+            if(containsPrefixAndSuffix(i)) {
                 $(node.contents()[0]).after(childParts);
                 $(node.contents()[0]).after(childParts);
-                prevChildParts = childParts;
-                continue;
-            }
-
-            if(prevChildParts && prevChildParts.length > 1 && prevChildParts[0].nodeType === Node.TEXT_NODE && prevChildParts[1].nodeType === Node.TEXT_NODE) {
-                $(node.contents()[0]).after(childParts);
-                prevChildParts = childParts;
-                continue;
+            } else {
+                node.prepend(childParts);
             }
             }
-
-            node.prepend(childParts);
-
             prevChildParts = childParts;
         }
         return parts;
             prevChildParts = childParts;
         }
         return parts;