[Pkg-javascript-commits] [ltx] 299/469: Use DOMElement

Jonas Smedegaard dr at jones.dk
Wed Aug 31 13:03:19 UTC 2016


This is an automated email from the git hooks/post-receive script.

js pushed a commit to branch master
in repository ltx.

commit 5a4261c688ac79c566eccc6d9b6a36bf3b0ad34e
Author: Lloyd Watkin <lloyd at evilprofessor.co.uk>
Date:   Sun Feb 16 18:42:50 2014 +0000

    Use DOMElement
---
 lib/dom-element.js | 91 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
 lib/parse.js       |  7 +++--
 2 files changed, 95 insertions(+), 3 deletions(-)

diff --git a/lib/dom-element.js b/lib/dom-element.js
new file mode 100644
index 0000000..6cdf9d1
--- /dev/null
+++ b/lib/dom-element.js
@@ -0,0 +1,91 @@
+var util = require('util')
+  , Element = require('./element')
+
+function DOMElement(name, attrs) {
+    Element.call(this, name, attrs)
+
+    this.nodeType = 1
+    this.nodeName = this.localName
+}
+
+util.inherits(DOMElement, ltx.Element)
+
+Object.defineProperty(DOMElement.prototype, 'localName', {
+    get: function () {
+        return this.getName()
+    }
+})
+
+Object.defineProperty(DOMElement.prototype, 'namespaceURI', {
+    get: function () {
+        return this.getNS()
+    }
+})
+
+Object.defineProperty(DOMElement.prototype, 'parentNode', {
+    get: function () {
+        return this.parent
+    }
+})
+
+Object.defineProperty(DOMElement.prototype, 'childNodes', {
+    get: function () {
+        return this.children
+    }
+})
+
+Object.defineProperty(DOMElement.prototype, 'textContent', {
+    get: function () {
+        return this.getText()
+    },
+    set: function (value) {
+        this.children.push(value)
+    }
+})
+
+DOMElement.prototype.getElementsByTagName = function (name) {
+    var res = this.getChildren(name)
+    return this.getChildren(name)
+}
+
+DOMElement.prototype.getAttribute = function (name) {
+    return this.getAttr(name)
+}
+
+DOMElement.prototype.setAttribute = function (name, value) {
+    this.attr(name, value)
+}
+
+DOMElement.prototype.getAttributeNS = function (ns, name) {
+    if (ns === 'http://www.w3.org/XML/1998/namespace') {
+        return this.getAttr(['xml', name].join(':'))
+    }
+    return this.getAttr(name, ns)
+}
+
+DOMElement.prototype.setAttributeNS = function (ns, name, value) {
+    var prefix
+    if (ns === 'http://www.w3.org/XML/1998/namespace') {
+        prefix = 'xml'
+    } else {
+        var nss = this.getXmlns()
+        prefix = nss[ns] || ''
+    }
+    if (prefix) {
+        this.attr([prefix, name].join(':'), value)
+    }
+}
+
+DOMElement.prototype.removeAttribute = function (name) {
+    this.attr(name, null)
+}
+
+DOMElement.prototype.appendChild = function (el) {
+    this.cnode(el)
+}
+
+DOMElement.prototype.removeChild = function (el) {
+    this.remove(el)
+}
+
+module.exports = DOMElement
diff --git a/lib/parse.js b/lib/parse.js
index 29cdfb1..17eb3ee 100644
--- a/lib/parse.js
+++ b/lib/parse.js
@@ -17,8 +17,9 @@ exports.bestSaxParser = null;
 	if (!exports.bestSaxParser)
 	    exports.bestSaxParser = mod;
     }
-});
-var element = require('./element');
+})
+
+var DOMElement = require('./dom-element')
 
 exports.Parser = function(saxParser) {
     events.EventEmitter.call(this);
@@ -31,7 +32,7 @@ exports.Parser = function(saxParser) {
 
     var el;
     this.parser.addListener('startElement', function(name, attrs) {
-        var child = new element.Element(name, attrs);
+        var child = new DOMElement.Element(name, attrs)
         if (!el) {
             el = child;
         } else {

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/ltx.git



More information about the Pkg-javascript-commits mailing list