From 422314851c0b7ce1f0a5209ca09960a47856d173 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Aleksander=20=C5=81ukasz?= Date: Thu, 26 Sep 2013 17:29:49 +0200 Subject: [PATCH 1/1] refactor --- src/smartxml/smartxml.js | 34 ++++++++++++++++------------------ 1 file changed, 16 insertions(+), 18 deletions(-) diff --git a/src/smartxml/smartxml.js b/src/smartxml/smartxml.js index 8eeca1a..865f928 100644 --- a/src/smartxml/smartxml.js +++ b/src/smartxml/smartxml.js @@ -19,12 +19,24 @@ var Document = function(nativeNode) { } -var ElementNode = function(nativeNode) { +var DocumentNode = function(nativeNode) { this.nativeNode = nativeNode; this._$ = $(nativeNode); +} + +$.extend(DocumentNode.prototype, { + detach: function() { this._$.detach(); }, + + sameNode: function(otherNode) { + return this.nativeNode === otherNode.nativeNode; + } +}) + +var ElementNode = function(nativeNode) { + DocumentNode.apply(this, arguments); }; -$.extend(ElementNode.prototype, { +$.extend(ElementNode.prototype, DocumentNode.prototype, { nodeType: Node.ELEMENT_NODE, getTagName: function() { @@ -50,19 +62,10 @@ $.extend(ElementNode.prototype, { return toret; }, - - sameNode: function(otherNode) { - return this.nativeNode === otherNode.nativeNode; - }, - indexOf: function(node) { return this._$.contents().index(node._$); }, - detach: function() { - this._$.detach(); - }, - parent: function() { return new ElementNode(this._$.parent()); }, @@ -114,17 +117,12 @@ $.extend(ElementNode.prototype, { }); var TextNode = function(nativeNode) { - this.nativeNode = nativeNode; - this._$ = $(nativeNode); + DocumentNode.apply(this, arguments); } -$.extend(TextNode.prototype, { +$.extend(TextNode.prototype, DocumentNode.prototype, { nodeType: Node.TEXT_NODE, - detach: function() { - this._$.detach(); - }, - getText: function() { return this.nativeNode.data; }, -- 2.20.1