expect(children[0].sameNode(appended));
});
+ it('can put new TextElement at the end', function() {
+ var c = canvas.fromXML('<section></section>'),
+ appended = c.doc().append({text: 'Alice'}),
+ children = c.doc().children();
+
+ expect(children.length).to.equal(1);
+ expect(children[0].sameNode(appended));
+ expect(children[0].getText()).to.equal('Alice');
+ });
+
it('can put new NodeElement after another NodeElement', function() {
var c = canvas.fromXML('<section><div></div></section>'),
div = c.doc().children()[0],
$.extend(DocumentNodeElement.prototype, {
append: function(params) {
- var to_append = DocumentNodeElement.createDOM(params.tag, params.klass);
+ var to_append = DocumentNodeElement.createDOM(params);
this.$element.append(to_append);
return documentElementFromHTMLElement(to_append);
},
before: function(params) {
- var to_append = DocumentNodeElement.createDOM(params.tag, params.klass);
+ var to_append = DocumentNodeElement.createDOM(params);
this.$element.before(to_append);
return documentElementFromHTMLElement(to_append);
},
after: function(params) {
- var to_append = DocumentNodeElement.createDOM(params.tag, params.klass);
+ var to_append = DocumentNodeElement.createDOM(params);
this.$element.after(to_append);
return documentElementFromHTMLElement(to_append);
}
});
-DocumentNodeElement.createDOM = function(tag, klass) {
- var dom = $('<' + tag + '>');
- if(klass)
- dom.attr('class', klass);
+DocumentNodeElement.createDOM = function(params) {
+ var dom;
+ if(params.text) {
+ dom = $(document.createTextNode(params.text));
+ } else {
+ dom = $('<' + params.tag + '>');
+ if(params.klass)
+ dom.attr('class', params.klass);
+ }
return dom;
};