return this.nativeNode.parentNode ? this.document.createElementNode(this.nativeNode.parentNode) : null;
},
+ after: function(node) {
+ node = node instanceof ElementNode ? node : this.document.createElementNode(node);
+ this._$.after(node.nativeNode);
+ return node;
+ },
+
before: function(node) {
+ node = node instanceof ElementNode ? node : this.document.createElementNode(node);
this._$.before(node.nativeNode);
+ return node;
},
wrapWith: function(node) {
createElementNode: function(from) {
if(!(from instanceof HTMLElement)) {
- from = $('<' + from.tagName + '>')[0];
+ if(from.text) {
+ from = document.createTextNode(from.text);
+ } else {
+ from = $('<' + from.tagName + '>')[0];
+ }
}
return new this.ElementNodeFactory(from, this);
},
expect(event.type).to.equal('nodeTextChange');
});
+ it('puts NodeElement after itself', function() {
+ var node = elementNodeFromXML('<div>Alice</div>'),
+ textNode = node.contents()[0],
+ returned = textNode.after({tagName:'div'});
+ expect(returned.sameNode(node.contents()[1])).to.be.true;
+ });
+
+ it('puts NodeElement before itself', function() {
+ var node = elementNodeFromXML('<div>Alice</div>'),
+ textNode = node.contents()[0],
+ returned = textNode.before({tagName:'div'});
+ expect(returned.sameNode(node.contents()[0])).to.be.true;
+ });
+
describe('Wrapping TextNode contents', function() {
it('wraps DocumentTextElement', function() {