From: Aleksander Ɓukasz Date: Thu, 26 Sep 2013 10:39:43 +0000 (+0200) Subject: getting root element X-Git-Url: https://git.mdrn.pl/fnpeditor.git/commitdiff_plain/6a770096a6f30ae819ec07c74e513770130f2721?ds=sidebyside;hp=54c2f0168226c06ca075858225568ab97004992b getting root element --- diff --git a/src/smartxml/smartxml.js b/src/smartxml/smartxml.js new file mode 100644 index 0000000..e996f76 --- /dev/null +++ b/src/smartxml/smartxml.js @@ -0,0 +1,32 @@ +define([ + 'libs/jquery' +], function($) { + +'use strict'; + + +var Document = function(xml) { + var $document = $(xml); + + + Object.defineProperty(this, 'root', {get: function() { return new ElementNode($document[0])}}); +} + + +var ElementNode = function(nativeNode) { + var myNode = nativeNode, + $myNode = $(nativeNode); + + + this.getTagName = function() { + return myNode.tagName.toLowerCase(); + } +}; + +return { + fromXML: function(xml) { + return new Document(xml); + } +}; + +}); \ No newline at end of file diff --git a/src/smartxml/smartxml.test.js b/src/smartxml/smartxml.test.js new file mode 100644 index 0000000..c4f99e8 --- /dev/null +++ b/src/smartxml/smartxml.test.js @@ -0,0 +1,19 @@ +define([ + 'libs/chai', + './smartxml.js' +], function(chai, smartxml) { + +'use strict'; + + +var expect = chai.expect; + + +describe.only('Basic use', function() { + it('exposes root element', function() { + var doc = smartxml.fromXML('
'); + expect(doc.root.getTagName()).to.equal('div'); + }); +}); + +}); \ No newline at end of file