From: Aleksander Ɓukasz Date: Fri, 25 Oct 2013 08:28:01 +0000 (+0200) Subject: smartxml: ElementNode.prepend X-Git-Url: https://git.mdrn.pl/fnpeditor.git/commitdiff_plain/9156bcda05de78865d7f2ef202824dd2a1a03ea1?ds=inline smartxml: ElementNode.prepend --- diff --git a/src/smartxml/smartxml.js b/src/smartxml/smartxml.js index 56e78af..91dd8bb 100644 --- a/src/smartxml/smartxml.js +++ b/src/smartxml/smartxml.js @@ -154,6 +154,11 @@ $.extend(ElementNode.prototype, { this._$.append(node.nativeNode); }, + prepend: function(node) { + node = node instanceof DocumentNode ? node : this.document.createElementNode(node); + this._$.prepend(node.nativeNode); + }, + unwrapContent: function() { var parent = this.parent(); if(!parent) { diff --git a/src/smartxml/smartxml.test.js b/src/smartxml/smartxml.test.js index 7880017..29c4244 100644 --- a/src/smartxml/smartxml.test.js +++ b/src/smartxml/smartxml.test.js @@ -258,6 +258,16 @@ describe('smartxml', function() { expect(node1.contents()[0].sameNode(node2)).to.be.true; }); + it('prepends element node to another element node', function() { + var node1 = elementNodeFromParams({tag: 'div'}), + node2 = elementNodeFromParams({tag: 'a'}), + node3 = elementNodeFromParams({tag: 'p'}); + node1.prepend(node2); + node1.prepend(node3); + expect(node1.contents()[0].sameNode(node3)).to.be.true; + expect(node1.contents()[1].sameNode(node2)).to.be.true; + }); + it('wraps element node with another element node', function() { var node = elementNodeFromXML('
'), wrapper = elementNodeFromXML('');