From be2c8ef28fbbcf62764e5bdedf9131a1aad8317b Mon Sep 17 00:00:00 2001 From: =?utf8?q?Aleksander=20=C5=81ukasz?= Date: Fri, 5 Jul 2013 16:35:01 +0200 Subject: [PATCH 1/1] comparing nodes --- modules/documentCanvas/canvas/canvas.test3.js | 12 ++++++++++++ modules/documentCanvas/canvas/documentElement.js | 4 ++++ 2 files changed, 16 insertions(+) diff --git a/modules/documentCanvas/canvas/canvas.test3.js b/modules/documentCanvas/canvas/canvas.test3.js index 8f779d3..b041bac 100644 --- a/modules/documentCanvas/canvas/canvas.test3.js +++ b/modules/documentCanvas/canvas/canvas.test3.js @@ -32,6 +32,18 @@ describe('Canvas', function() { }); }); + describe('DocumentElements comparison', function() { + it('reports dwo DocumentElements to be the same when they represent the same wlxml document element', function() { + var c = canvas.fromXML('
'), + first_div1 = c.doc().children()[0], + first_div2 = c.doc().children()[0], + second_div = c.doc().children()[1]; + expect(first_div1.sameNode(first_div1)).to.be.true; + expect(first_div1.sameNode(first_div2)).to.be.true; + expect(first_div1.sameNode(second_div)).to.be.false; + }); + }); + describe('traversing', function() { it('reports element nodes', function() { var c = canvas.fromXML('
'), diff --git a/modules/documentCanvas/canvas/documentElement.js b/modules/documentCanvas/canvas/documentElement.js index 637da5f..2225e0c 100644 --- a/modules/documentCanvas/canvas/documentElement.js +++ b/modules/documentCanvas/canvas/documentElement.js @@ -31,6 +31,10 @@ $.extend(DocumentElement.prototype, { toret.push(element); }); return toret; + }, + + sameNode: function(other) { + return other && (typeof other === typeof this) && other.$element[0] === this.$element[0]; } }); -- 2.20.1