From 288441d605a219ce06595329e62673db39bf557f Mon Sep 17 00:00:00 2001 From: =?utf8?q?Aleksander=20=C5=81ukasz?= Date: Wed, 23 Oct 2013 13:09:19 +0200 Subject: [PATCH] smartxml: Fixing changing node's tag --- src/smartxml/smartxml.js | 4 +++- src/smartxml/smartxml.test.js | 6 ++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/src/smartxml/smartxml.js b/src/smartxml/smartxml.js index aa04fd7..b90a042 100644 --- a/src/smartxml/smartxml.js +++ b/src/smartxml/smartxml.js @@ -100,7 +100,8 @@ $.extend(ElementNode.prototype, DocumentNode.prototype, { setTag: function(tagName) { var node = this.document.createElementNode({tagName: tagName}), - oldTagName = this.getTagName(); + oldTagName = this.getTagName(), + myContents = this._$.contents(); this.getAttrs().forEach(function(attribute) { node.setAttr(attribute.name, attribute.value, true); @@ -112,6 +113,7 @@ $.extend(ElementNode.prototype, DocumentNode.prototype, { } this._$.replaceWith(node._$); this._setNativeNode(node._$[0]); + this._$.append(myContents); this.triggerChangeEvent('nodeTagChange', {oldTagName: oldTagName, newTagName: this.getTagName()}); }, diff --git a/src/smartxml/smartxml.test.js b/src/smartxml/smartxml.test.js index e58e754..597c107 100644 --- a/src/smartxml/smartxml.test.js +++ b/src/smartxml/smartxml.test.js @@ -111,6 +111,12 @@ describe('smartxml', function() { doc.root.setTag('span'); expect(doc.root.getTagName()).to.equal('span'); }); + + it('keeps contents', function() { + var node = elementNodeFromXML('
'); + node.setTag('header'); + expect(node.contents()).to.have.length(1); + }); }); -- 2.20.1