From 471fbe0d1628d3f2baabd39e02a4e58f7d9bca5c Mon Sep 17 00:00:00 2001 From: =?utf8?q?Aleksander=20=C5=81ukasz?= Date: Thu, 23 Jan 2014 09:58:25 +0100 Subject: [PATCH] smartxml: refactoring Now that methods inserting nodes handle text merging by themselves, we don't need to worry about that here. --- src/smartxml/core.js | 33 +++++++++------------------------ 1 file changed, 9 insertions(+), 24 deletions(-) diff --git a/src/smartxml/core.js b/src/smartxml/core.js index a2dd0aa..17af8ac 100644 --- a/src/smartxml/core.js +++ b/src/smartxml/core.js @@ -3,8 +3,7 @@ define(function(require) { 'use strict'; /* globals Node */ -var _ = require('libs/underscore'), - TEXT_NODE = Node.TEXT_NODE; +var _ = require('libs/underscore'); var INSERTION = function(implementation) { @@ -177,30 +176,16 @@ var elementNodeTransformations = { return this.detach(); } - var prev = this.prev(), - next = this.next(), - shiftRange, leftMerged; - if(prev && (prev.nodeType === TEXT_NODE) && (myContents[0].nodeType === TEXT_NODE)) { - prev.appendText(myContents[0].getText()); - myContents[0].detach(); - shiftRange = true; - leftMerged = true; - } else { - leftMerged = false; - } - - if(!(leftMerged && myContents.length === 1)) { - var lastContents = _.last(myContents); - if(next && (next.nodeType === TEXT_NODE) && (lastContents.nodeType === TEXT_NODE)) { - next.prependText(lastContents.getText()); - lastContents.detach(); - } - } - - var childrenLength = this.contents().length; + var childrenLength = this.contents().length, + first = true, + shiftRange = false; this.contents().forEach(function(child) { - this.before(child); + var returned = this.before(child); + if(first && !(returned.sameNode(child))) { + shiftRange = true; + first = false; + } }.bind(this)); this.detach(); -- 2.20.1