fixing wrapping DocumentElements
authorAleksander Łukasz <aleksander.lukasz@nowoczesnapolska.org.pl>
Wed, 10 Jul 2013 14:27:10 +0000 (16:27 +0200)
committerAleksander Łukasz <aleksander.lukasz@nowoczesnapolska.org.pl>
Wed, 10 Jul 2013 14:27:10 +0000 (16:27 +0200)
modules/documentCanvas/canvas/canvas.test3.js
modules/documentCanvas/canvas/documentElement.js

index 6f28439..32e6190 100644 (file)
@@ -358,6 +358,8 @@ describe('Canvas', function() {
 
                     expect(returned.sameNode(parent)).to.be.true;
                     expect(returned.sameNode(parent2)).to.be.true;
 
                     expect(returned.sameNode(parent)).to.be.true;
                     expect(returned.sameNode(parent2)).to.be.true;
+                    expect(returned.getWlxmlTag()).to.equal('header');
+                    expect(returned.getWlxmlClass()).to.equal('some.class');
                 });
                 it('wraps DocumentTextElement', function() {
                     var c = canvas.fromXML('<section>Alice</section>'),
                 });
                 it('wraps DocumentTextElement', function() {
                     var c = canvas.fromXML('<section>Alice</section>'),
@@ -369,6 +371,8 @@ describe('Canvas', function() {
 
                     expect(returned.sameNode(parent)).to.be.true;
                     expect(returned.sameNode(parent2)).to.be.true;
 
                     expect(returned.sameNode(parent)).to.be.true;
                     expect(returned.sameNode(parent2)).to.be.true;
+                    expect(returned.getWlxmlTag()).to.equal('header');
+                    expect(returned.getWlxmlClass()).to.equal('some.class');
                 });
                 
                 it('wraps part of DocumentTextElement', function() {
                 });
                 
                 it('wraps part of DocumentTextElement', function() {
@@ -384,6 +388,8 @@ describe('Canvas', function() {
                     expect(children[0].getText()).to.equal('Alice');
 
                     expect(children[1].sameNode(returned)).to.be.true;
                     expect(children[0].getText()).to.equal('Alice');
 
                     expect(children[1].sameNode(returned)).to.be.true;
+                    expect(returned.getWlxmlTag()).to.equal('header');
+                    expect(returned.getWlxmlClass()).to.equal('some.class');
                     expect(children[1].children().length).to.equal(1);
                     expect(children[1].children()[0].getText()).to.equal(' has a ');
 
                     expect(children[1].children().length).to.equal(1);
                     expect(children[1].children()[0].getText()).to.equal(' has a ');
 
index 88287b8..f2ef09c 100644 (file)
@@ -49,8 +49,10 @@ $.extend(DocumentElement.prototype, {
     },
 
     wrapWithNodeElement: function(wlxmlNode) {
     },
 
     wrapWithNodeElement: function(wlxmlNode) {
-        this.$element.wrap($('<' + wlxmlNode.tag + ' class="' + wlxmlNode.klass.replace('.', '-') + '">')[0]);
-        return documentElementFromHTMLElement(this.$element.parent().get(0), this.canvas);
+        var wrapper = DocumentNodeElement.create({tag: wlxmlNode.tag, klass: wlxmlNode.klass});
+        this.$element.replaceWith(wrapper.dom());
+        wrapper.append(this);
+        return wrapper;
     },
 
     childIndex: function(child) {
     },
 
     childIndex: function(child) {