From 080240adecd1131b9d3c4e2a0b58a7f922c4ec80 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Aleksander=20=C5=81ukasz?= Date: Tue, 11 Feb 2014 12:06:51 +0100 Subject: [PATCH] smartxml: attaching previous parent of a moved node to nodeMoved event --- src/smartxml/core.js | 2 +- src/smartxml/smartxml.js | 3 +++ src/smartxml/smartxml.test.js | 1 + 3 files changed, 5 insertions(+), 1 deletion(-) 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() { -- 2.20.1