after: function(node) {
var insertion = this.getNodeInsertion(node);
this._$.after(insertion.ofNode.nativeNode);
- if(insertion.insertsNew) {
- this.triggerChangeEvent('nodeAdded', {node: insertion.ofNode});
- }
+ this.triggerChangeEvent(insertion.insertsNew ? 'nodeAdded' : 'nodeMoved', {node: insertion.ofNode});
return insertion.ofNode;
},
before: function(node) {
var insertion = this.getNodeInsertion(node);
this._$.before(insertion.ofNode.nativeNode);
- if(insertion.insertsNew) {
- this.triggerChangeEvent('nodeAdded', {node: insertion.ofNode});
- }
+ this.triggerChangeEvent(insertion.insertsNew ? 'nodeAdded' : 'nodeMoved', {node: insertion.ofNode});
return insertion.ofNode;
},
append: function(node) {
var insertion = this.getNodeInsertion(node);
this._$.append(insertion.ofNode.nativeNode);
- if(insertion.insertsNew) {
- this.triggerChangeEvent('nodeAdded', {node: insertion.ofNode});
- }
+ this.triggerChangeEvent(insertion.insertsNew ? 'nodeAdded' : 'nodeMoved', {node: insertion.ofNode});
return insertion.ofNode;
},
prepend: function(node) {
var insertion = this.getNodeInsertion(node);
this._$.prepend(insertion.ofNode.nativeNode);
- if(insertion.insertsNew) {
- this.triggerChangeEvent('nodeAdded', {node: insertion.ofNode});
- }
+ this.triggerChangeEvent(insertion.insertsNew ? 'nodeAdded' : 'nodeMoved', {node: insertion.ofNode});
return insertion.ofNode;
},
expect(event.meta.node.sameNode(appended)).to.be.true;
});
- it('doesn\'t emit nodeAdded when appending aready existing node', function() {
+ it('emits nodeMoved when appending aready existing node', function() {
var node = elementNodeFromXML('<div><a></a><b></b></div>'),
a = node.contents()[0],
b = node.contents()[1],
spy = sinon.spy();
node.document.on('change', spy);
- a.append(b);
- expect(spy.callCount).to.equal(0);
+
+ var appended = a.append(b),
+ event = spy.args[0][0];
+
+ expect(spy.callCount).to.equal(1);
+ expect(event.type).to.equal('nodeMoved');
+ expect(event.meta.node.sameNode(appended)).to.be.true;
});
it('emits nodeAdded event when prepending new node', function() {
expect(event.meta.node.sameNode(prepended)).to.be.true;
});
- it('doesn\'t emit nodeAdded when prepending aready existing node', function() {
+ it('emits nodeMoved when prepending aready existing node', function() {
var node = elementNodeFromXML('<div><a></a><b></b></div>'),
a = node.contents()[0],
b = node.contents()[1],
spy = sinon.spy();
node.document.on('change', spy);
- a.prepend(b);
- expect(spy.callCount).to.equal(0);
+
+ var prepended = a.prepend(b),
+ event = spy.args[0][0];
+ expect(spy.callCount).to.equal(1);
+ expect(event.type).to.equal('nodeMoved');
+ expect(event.meta.node.sameNode(prepended)).to.be.true;
});
it('emits nodeAdded event when inserting node after another', function() {
expect(event.meta.node.sameNode(inserted)).to.be.true;
});
- it('doesn\'t emit nodeAdded when inserting aready existing node after another', function() {
+ it('emits nodeMoved when inserting aready existing node after another', function() {
var node = elementNodeFromXML('<div><a></a><b></b></div>'),
a = node.contents()[0],
b = node.contents()[1],
spy = sinon.spy();
node.document.on('change', spy);
- b.after(a);
- expect(spy.callCount).to.equal(0);
+ var inserted = b.after(a),
+ event = spy.args[0][0];
+
+ expect(spy.callCount).to.equal(1);
+ expect(event.type).to.equal('nodeMoved');
+ expect(event.meta.node.sameNode(inserted)).to.be.true;
});
it('emits nodeAdded event when inserting node before another', function() {
expect(event.meta.node.sameNode(inserted)).to.be.true;
});
- it('doesn\'t emit nodeAdded when inserting aready existing node before another', function() {
+ it('emits nodeAdded when inserting aready existing node before another', function() {
var node = elementNodeFromXML('<div><a></a><b></b></div>'),
a = node.contents()[0],
b = node.contents()[1],
spy = sinon.spy();
node.document.on('change', spy);
- a.before(b);
- expect(spy.callCount).to.equal(0);
+ var inserted = a.before(b),
+ event = spy.args[0][0];
+
+ expect(spy.callCount).to.equal(1);
+ expect(event.type).to.equal('nodeMoved');
+ expect(event.meta.node.sameNode(inserted)).to.be.true;
});
});