[Pkg-javascript-commits] [ltx] 328/469: With c() and clone() we weren't using DOMElement

Jonas Smedegaard dr at jones.dk
Wed Aug 31 13:03:22 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 e2e87efb11c0ae18478a45a3599faf202f0433e4
Author: Lloyd Watkin <lloyd.watkin at surevine.com>
Date:   Fri Mar 28 10:28:37 2014 +0000

    With c() and clone() we weren't using DOMElement
---
 lib/dom-element.js   |  5 +++++
 lib/element.js       | 11 ++++++++---
 ltx-browser.js       | 15 +++++++++++++--
 test/element-test.js |  9 ++++++++-
 4 files changed, 34 insertions(+), 6 deletions(-)

diff --git a/lib/dom-element.js b/lib/dom-element.js
index 9f22aad..2117d2c 100644
--- a/lib/dom-element.js
+++ b/lib/dom-element.js
@@ -12,6 +12,11 @@ function DOMElement(name, attrs) {
 
 util.inherits(DOMElement, Element)
 
+DOMElement.prototype._getElement = function(name, attrs) {
+    var element = new DOMElement(name, attrs)
+    return element
+}
+
 Object.defineProperty(DOMElement.prototype, 'localName', {
     get: function () {
         return this.getName()
diff --git a/lib/element.js b/lib/element.js
index 7968a5e..5376fa3 100644
--- a/lib/element.js
+++ b/lib/element.js
@@ -196,9 +196,14 @@ Element.prototype.up = function() {
         return this
 }
 
+Element.prototype._getElement = function(name, attrs) {
+    var element = new Element(name, attrs)
+    return element
+}
+
 /** create child node and return it */
 Element.prototype.c = function(name, attrs) {
-    return this.cnode(new Element(name, attrs))
+    return this.cnode(this._getElement(name, attrs))
 }
 
 Element.prototype.cnode = function(child) {
@@ -246,7 +251,7 @@ Element.prototype.remove = function(el, xmlns) {
  * doing. Building XML with ltx is easy!
  */
 Element.prototype.clone = function() {
-    var clone = new Element(this.name, {})
+    var clone = this._getElement(this.name, {})
     for (var k in this.attrs) {
         if (this.attrs.hasOwnProperty(k))
             clone.attrs[k] = this.attrs[k]
@@ -347,4 +352,4 @@ function escapeXmlText(s) {
 }
 
 exports.Element = Element
-exports.escapeXml = escapeXml
\ No newline at end of file
+exports.escapeXml = escapeXml
diff --git a/ltx-browser.js b/ltx-browser.js
index 9a850b3..30a8f8e 100644
--- a/ltx-browser.js
+++ b/ltx-browser.js
@@ -13,6 +13,11 @@ function DOMElement(name, attrs) {
 
 util.inherits(DOMElement, Element)
 
+DOMElement.prototype._getElement = function(name, attrs) {
+    var element = new DOMElement(name, attrs)
+    return element
+}
+
 Object.defineProperty(DOMElement.prototype, 'localName', {
     get: function () {
         return this.getName()
@@ -291,9 +296,14 @@ Element.prototype.up = function() {
         return this
 }
 
+Element.prototype._getElement = function(name, attrs) {
+    var element = new Element(name, attrs)
+    return element
+}
+
 /** create child node and return it */
 Element.prototype.c = function(name, attrs) {
-    return this.cnode(new Element(name, attrs))
+    return this.cnode(this._getElement(name, attrs))
 }
 
 Element.prototype.cnode = function(child) {
@@ -341,7 +351,7 @@ Element.prototype.remove = function(el, xmlns) {
  * doing. Building XML with ltx is easy!
  */
 Element.prototype.clone = function() {
-    var clone = new Element(this.name, {})
+    var clone = this._getElement(this.name, {})
     for (var k in this.attrs) {
         if (this.attrs.hasOwnProperty(k))
             clone.attrs[k] = this.attrs[k]
@@ -443,6 +453,7 @@ function escapeXmlText(s) {
 
 exports.Element = Element
 exports.escapeXml = escapeXml
+
 },{}],3:[function(require,module,exports){
 'use strict';
 
diff --git a/test/element-test.js b/test/element-test.js
index 1cc35fe..8171897 100644
--- a/test/element-test.js
+++ b/test/element-test.js
@@ -184,5 +184,12 @@ vows.describe('ltx').addBatch({
         'getChild unprefixed': function(el) {
             assert.equal(el.getChild('foo').getText(), 'bar')
         }
+    },
+
+    'issue-37: Element instanceof Fails': {
+        'instanceof': function() {
+            var el = new ltx.Element('root').c('children')
+            assert.ok(el instanceof ltx.Element)
+        }
     }
-}).export(module)
\ No newline at end of file
+}).export(module)

-- 
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