From e5ac28c20d0e89d662c6fcf5da4ecc87f8011211 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Aleksander=20=C5=81ukasz?= Date: Mon, 8 Jul 2013 10:46:23 +0200 Subject: [PATCH 1/1] wrapping document node and text element --- modules/documentCanvas/canvas/canvas.test3.js | 27 +++++++++++++++++++ .../documentCanvas/canvas/documentElement.js | 5 ++++ 2 files changed, 32 insertions(+) diff --git a/modules/documentCanvas/canvas/canvas.test3.js b/modules/documentCanvas/canvas/canvas.test3.js index b6cc42e..76550cd 100644 --- a/modules/documentCanvas/canvas/canvas.test3.js +++ b/modules/documentCanvas/canvas/canvas.test3.js @@ -116,6 +116,33 @@ describe('Canvas', function() { }); }) + describe('manipulation api', function() { + describe('wrapping', function() { + it('wraps DocumentNodeElement', function() { + var c = canvas.fromXML('
'), + div = c.doc().children()[0]; + + var returned = div.wrapWithNodeElement({tag: 'header', klass: 'some.class'}), + parent = div.parent(), + parent2 = c.doc().children()[0]; + + expect(returned.sameNode(parent)).to.be.true; + expect(returned.sameNode(parent2)).to.be.true; + }); + it('wraps DocumentTextElement', function() { + var c = canvas.fromXML('
Alice
'), + text = c.doc().children()[0]; + + var returned = text.wrapWithNodeElement({tag: 'header', klass: 'some.class'}), + parent = text.parent(), + parent2 = c.doc().children()[0]; + + expect(returned.sameNode(parent)).to.be.true; + expect(returned.sameNode(parent2)).to.be.true; + }); + }) + }); + }); }); diff --git a/modules/documentCanvas/canvas/documentElement.js b/modules/documentCanvas/canvas/documentElement.js index cd94759..530f854 100644 --- a/modules/documentCanvas/canvas/documentElement.js +++ b/modules/documentCanvas/canvas/documentElement.js @@ -38,6 +38,11 @@ $.extend(DocumentElement.prototype, { sameNode: function(other) { return other && (typeof other === typeof this) && other.$element[0] === this.$element[0]; + }, + + wrapWithNodeElement: function(wlxmlNode) { + this.$element.wrap($('<' + wlxmlNode.tag + ' class="' + wlxmlNode.klass + '"">')[0]); + return documentElementFromHTMLElement(this.$element.parent().get(0)); } }); -- 2.20.1