From: Aleksander Ɓukasz Date: Thu, 25 Jul 2013 07:14:41 +0000 (+0200) Subject: Refactoring X-Git-Url: https://git.mdrn.pl/fnpeditor.git/commitdiff_plain/3862e230ab784fa164875fd594c277da9ad87315?ds=sidebyside Refactoring --- diff --git a/modules/documentCanvas/canvas/documentElement.js b/modules/documentCanvas/canvas/documentElement.js index 9359134..b2625e1 100644 --- a/modules/documentCanvas/canvas/documentElement.js +++ b/modules/documentCanvas/canvas/documentElement.js @@ -200,23 +200,22 @@ $.extend(DocumentNodeElement.prototype, { 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); - if(i === children.length - 1 && node.contents().length === 2) { + if(containsPrefixAndSuffix(i)) { $(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;