X-Git-Url: https://git.mdrn.pl/fnpeditor.git/blobdiff_plain/bb2c206bdd17b1f42cfdcdd62b105873a1b8f9a2..2d132ea97a8773dcb5d9f077718698996cf1b320:/src/smartxml/smartxml.js diff --git a/src/smartxml/smartxml.js b/src/smartxml/smartxml.js index 4bb5afe..f6fae64 100644 --- a/src/smartxml/smartxml.js +++ b/src/smartxml/smartxml.js @@ -18,33 +18,48 @@ var Document = function(nativeNode) { var ElementNode = function(nativeNode) { - var myNode = nativeNode, - $myNode = $(nativeNode); + this.nativeNode = nativeNode; + this._$ = $(nativeNode); +}; - this._$myNode = $myNode; - this._myNode= myNode; +$.extend(ElementNode.prototype, { + nodeType: Node.ELEMENT_NODE, - this.getTagName = function() { - return myNode.tagName.toLowerCase(); - }; + getTagName: function() { + return this.nativeNode.tagName.toLowerCase(); + }, - this.append = function(documentNode) { - this._$myNode.append(documentNode._$myNode); - }; + append: function(documentNode) { + this._$.append(documentNode.nativeNode); + }, - this.contents = function() { + contents: function() { var toret = []; - this._$myNode.contents().each(function() { + this._$.contents().each(function() { if(this.nodeType === Node.ELEMENT_NODE) toret.push(new ElementNode(this)); + else if(this.nodeType === Node.TEXT_NODE) + toret.push(new TextNode(this)); }); return toret; - }; + }, + - this.sameNode = function(otherNode) { - return this._myNode === otherNode._myNode; + sameNode: function(otherNode) { + return this.nativeNode === otherNode.nativeNode; } -}; + +}); + +var TextNode = function(nativeNode) { + this.nativeNode = nativeNode; + this._$ = $(nativeNode); +} + +$.extend(TextNode.prototype, { + nodeType: Node.TEXT_NODE +}) + return { documentFromXML: function(xml) {