expect(children[0].getText()).to.equal('Alice');
});
+ it('can put new NodeElement at the beginning', function() {
+ var c = canvas.fromXML('<section><div></div></section>'),
+ prepended = c.doc().prepend({tag: 'header', klass: 'some.class'}),
+ children = c.doc().children();
+
+ expect(children).to.have.length(2);
+ expect(children[0].sameNode(prepended)).to.be.true;
+ });
+
+ it('can put new TextElement at the beginning', function() {
+ var c = canvas.fromXML('<section><div></div></section>'),
+ prepended = c.doc().prepend({text: 'Alice'}),
+ children = c.doc().children();
+
+ expect(children).to.have.length(2)
+ expect(children[0].sameNode(prepended)).to.be.true;
+ 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],
} else {
element = DocumentElement.create(params);
}
- var target = action === 'append' ? e._container() : e.dom();
+ var target = (action === 'append' || action === 'prepend') ? e._container() : e.dom();
target[action](element.dom());
return element;
};
this.data('orig-end', undefined);
return manipulate(this, params, 'append');
},
+ prepend: function(params) {
+ return manipulate(this, params, 'prepend');
+ },
before: function(params) {
return manipulate(this, params, 'before');