From 9156bcda05de78865d7f2ef202824dd2a1a03ea1 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Aleksander=20=C5=81ukasz?= Date: Fri, 25 Oct 2013 10:28:01 +0200 Subject: [PATCH 1/1] smartxml: ElementNode.prepend --- src/smartxml/smartxml.js | 5 +++++ src/smartxml/smartxml.test.js | 10 ++++++++++ 2 files changed, 15 insertions(+) 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(''); -- 2.20.1