From: Aleksander Ɓukasz Date: Wed, 23 Oct 2013 11:09:19 +0000 (+0200) Subject: smartxml: Fixing changing node's tag X-Git-Url: https://git.mdrn.pl/fnpeditor.git/commitdiff_plain/288441d605a219ce06595329e62673db39bf557f?ds=inline smartxml: Fixing changing node's tag --- 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); + }); });