From: Aleksander Ɓukasz Date: Tue, 19 Nov 2013 09:23:35 +0000 (+0100) Subject: smartxml: Fixing Document.containsNode X-Git-Url: https://git.mdrn.pl/fnpeditor.git/commitdiff_plain/03a3f51f2a8fd57f90b09a14001e91a4295b5278 smartxml: Fixing Document.containsNode --- diff --git a/src/smartxml/smartxml.js b/src/smartxml/smartxml.js index a357977..6e754de 100644 --- a/src/smartxml/smartxml.js +++ b/src/smartxml/smartxml.js @@ -358,7 +358,7 @@ $.extend(Document.prototype, Backbone.Events, { }, containsNode: function(node) { - return node._$.parents().index(this.root._$) !== -1; + return this.root && (node.nativeNode === this.root.nativeNode || node._$.parents().index(this.root._$) !== -1); }, wrapNodes: function(params) { diff --git a/src/smartxml/smartxml.test.js b/src/smartxml/smartxml.test.js index db9777f..2666ae2 100644 --- a/src/smartxml/smartxml.test.js +++ b/src/smartxml/smartxml.test.js @@ -40,6 +40,17 @@ describe('smartxml', function() { doc.loadXML('
'); expect(doc.root.getTagName()).to.equal('header'); }); + + it('knows if it contains an ElementNode in its tree', function() { + var doc = getDocumentFromXML('text'), + root = doc.root, + a = root.contents()[0], + text = root.contents()[1]; + + expect(doc.containsNode(root)).to.equal(true, 'contains its root'); + expect(doc.containsNode(a)).to.equal(true, 'contains Element Node'); + expect(doc.containsNode(text)).to.equal(true, 'contains Text Node'); + }); }); describe('Basic ElementNode properties', function() {