From: Aleksander Ɓukasz Date: Tue, 11 Feb 2014 11:06:51 +0000 (+0100) Subject: smartxml: attaching previous parent of a moved node to nodeMoved event X-Git-Url: https://git.mdrn.pl/fnpeditor.git/commitdiff_plain/080240adecd1131b9d3c4e2a0b58a7f922c4ec80 smartxml: attaching previous parent of a moved node to nodeMoved event --- diff --git a/src/smartxml/core.js b/src/smartxml/core.js index 665f9d5..ec2c643 100644 --- a/src/smartxml/core.js +++ b/src/smartxml/core.js @@ -13,7 +13,7 @@ var INSERTION = function(implementation) { nodeParent, returned; options = options || {}; - if(!(this.document.containsNode(this))) { + if(!(this.document.containsNode(this)) || !insertion.isNew) { nodeParent = insertion.ofNode.parent(); } returned = implementation.call(this, insertion.ofNode); diff --git a/src/smartxml/smartxml.js b/src/smartxml/smartxml.js index 9227e0f..102a506 100644 --- a/src/smartxml/smartxml.js +++ b/src/smartxml/smartxml.js @@ -123,6 +123,9 @@ $.extend(DocumentNode.prototype, { var node = (metaData && metaData.node) ? metaData.node : this, event = new events.ChangeEvent(type, $.extend({node: node}, metaData || {})); if(type === 'nodeDetached' || this.document.containsNode(event.meta.node)) { + if(type === 'nodeMoved') { + event.meta.parent = origParent; + } this.document.trigger('change', event); } if((type === 'nodeAdded' || type === 'nodeMoved') && !this.document.containsNode(this) && nodeWasContained) { diff --git a/src/smartxml/smartxml.test.js b/src/smartxml/smartxml.test.js index 7b42580..1e778ce 100644 --- a/src/smartxml/smartxml.test.js +++ b/src/smartxml/smartxml.test.js @@ -932,6 +932,7 @@ describe('smartxml', function() { expect(spy.callCount).to.equal(1); expect(event.type).to.equal('nodeMoved'); expect(event.meta.node.sameNode(appended)).to.be.true; + expect(node.document.root.sameNode(event.meta.parent)).to.equal(true, 'previous parent attached to event meta'); }); it('emits nodeAdded event when prepending new node', function() {