From 6a770096a6f30ae819ec07c74e513770130f2721 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Aleksander=20=C5=81ukasz?= Date: Thu, 26 Sep 2013 12:39:43 +0200 Subject: [PATCH] getting root element --- src/smartxml/smartxml.js | 32 ++++++++++++++++++++++++++++++++ src/smartxml/smartxml.test.js | 19 +++++++++++++++++++ 2 files changed, 51 insertions(+) create mode 100644 src/smartxml/smartxml.js create mode 100644 src/smartxml/smartxml.test.js 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 -- 2.20.1