From 98b0bc99617ca0f8cc6354aa91306f6437e3eb4d Mon Sep 17 00:00:00 2001 From: =?utf8?q?Aleksander=20=C5=81ukasz?= Date: Tue, 19 Nov 2013 17:10:31 +0100 Subject: [PATCH] smartxml: refactor --- src/smartxml/smartxml.js | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/src/smartxml/smartxml.js b/src/smartxml/smartxml.js index 1d9fdd0..637fda6 100644 --- a/src/smartxml/smartxml.js +++ b/src/smartxml/smartxml.js @@ -82,6 +82,12 @@ $.extend(DocumentNode.prototype, { return myIdx < parentContents.length - 1 ? parentContents[myIdx+1] : null; }, + isSurroundedByTextElements: function() { + var prev = this.prev(), + next = this.next(); + return prev && (prev.nodeType === Node.TEXT_NODE) && next && (next.nodeType === Node.TEXT_NODE); + }, + after: INSERTION(function(nativeNode) { return this._$.after(nativeNode); }), @@ -151,13 +157,11 @@ $.extend(ElementNode.prototype, { nodeType: Node.ELEMENT_NODE, detach: function() { - var prev = this.prev(), + var next; + if(parent && this.isSurroundedByTextElements()) { next = this.next(); - if(parent) { - if(prev && prev.nodeType === Node.TEXT_NODE && next && next.nodeType === Node.TEXT_NODE) { - prev.appendText(next.getText()); - next.detach(); - } + this.prev().appendText(next.getText()); + next.detach(); } return DocumentNode.prototype.detach.call(this); }, -- 2.20.1