return parents;
},
+ prev: function() {
+ var myIdx = this.getIndex();
+ return myIdx > 0 ? this.parent().contents()[myIdx-1] : null;
+ },
+
+ next: function() {
+ if(this.isRoot()) {
+ return null;
+ }
+ var myIdx = this.getIndex(),
+ parentContents = this.parent().contents();
+ return myIdx < parentContents.length - 1 ? parentContents[myIdx+1] : null;
+ },
+
after: INSERTION(function(nativeNode) {
return this._$.after(nativeNode);
}),
$.extend(ElementNode.prototype, {
nodeType: Node.ELEMENT_NODE,
+ detach: function() {
+ var prev = this.prev(),
+ next = this.next();
+ if(parent) {
+ if(prev && prev.nodeType === Node.TEXT_NODE && next && next.nodeType === Node.TEXT_NODE) {
+ prev.appendText(next.getText());
+ next.detach();
+ }
+ }
+ return DocumentNode.prototype.detach.call(this);
+ },
+
setData: function(key, value) {
if(value !== undefined) {
this._$.data(key, value);
describe('Manipulations', function() {
+ it('merges adjacent text nodes resulting from detaching an element node in between', function() {
+ var doc = getDocumentFromXML('<div>Alice <span>has</span>a cat</div>'),
+ span = doc.root.contents()[1];
+
+ span.detach();
+
+ var rootContents = doc.root.contents();
+ expect(rootContents).to.have.length(1, 'one child left');
+ expect(rootContents[0].getText()).to.equal('Alice a cat');
+ });
+
it('appends element node to another element node', function() {
var node1 = elementNodeFromParams({tag: 'div'}),
node2 = elementNodeFromParams({tag: 'a'}),