From: Aleksander Ɓukasz Date: Fri, 25 Oct 2013 14:25:25 +0000 (+0200) Subject: smartxml: emitting nodeDetached event X-Git-Url: https://git.mdrn.pl/fnpeditor.git/commitdiff_plain/9ce300f6e7b27995b982c14b79785e8ca4bed4f0?ds=sidebyside;hp=24f79c15db362b3646ce15d0dc6d9c703040e892 smartxml: emitting nodeDetached event --- diff --git a/src/smartxml/smartxml.js b/src/smartxml/smartxml.js index cbb2ba8..18664c7 100644 --- a/src/smartxml/smartxml.js +++ b/src/smartxml/smartxml.js @@ -27,7 +27,9 @@ $.extend(DocumentNode.prototype, { }, detach: function() { + var parent = this.parent(); this._$.detach(); + this.triggerChangeEvent('nodeDetached', {parent: parent}); return this; }, diff --git a/src/smartxml/smartxml.test.js b/src/smartxml/smartxml.test.js index e7aa8d4..8154ff5 100644 --- a/src/smartxml/smartxml.test.js +++ b/src/smartxml/smartxml.test.js @@ -370,6 +370,20 @@ describe('smartxml', function() { }); describe('Events', function() { + it('emits nodeDetached event on node detach', function() { + var node = elementNodeFromXML('
'), + innerNode = node.contents()[0], + spy = sinon.spy(); + node.document.on('change', spy); + + var detached = innerNode.detach(), + event = spy.args[0][0]; + + expect(event.type).to.equal('nodeDetached'); + expect(event.meta.node.sameNode(detached, 'detached node in event meta')); + expect(event.meta.parent.sameNode(node), 'original parent node in event meta'); + }), + it('emits nodeAdded event when appending new node', function() { var node = elementNodeFromXML('
'), spy = sinon.spy();