Skip to content
Browse files

FIXED: staffNS.xml.js

  • Loading branch information...
1 parent 7246b08 commit 66f689401070ff08942f8434e22465a59bdc1471 @tmpvar tmpvar committed Jan 29, 2011
Showing with 29 additions and 12 deletions.
  1. +14 −5 lib/jsdom/level1/core.js
  2. +11 −7 lib/jsdom/level2/core.js
  3. +2 −0 test/level2/core.js
  4. +2 −0 test/level2/core/files/staffNS.xml.js
View
19 lib/jsdom/level1/core.js
@@ -236,12 +236,17 @@ core.DOMImplementation.prototype = {
};
-var attrCopy = function(src, dest) {
+var attrCopy = function(src, dest, fn) {
if (src.attributes) {
- var attrs = src.attributes, i, l = attrs.length, attr;
+ var attrs = src.attributes, i, l = attrs.length, attr, copied;
for (i=0;i<l;i++) {
attr = attrs[i];
- dest.setAttribute(attr.nodeName, attr.nodeValue);
+
+ copied = dest.setAttribute(attr.nodeName, attr.nodeValue);
+ if (typeof fn == "function") {
+ fn(attr, copied);
+ }
+
}
}
return dest;
@@ -651,13 +656,13 @@ core.Node.prototype = {
},
/* returns Node */
- cloneNode : function(/* bool */ deep) {
+ cloneNode : function(/* bool */ deep, fn) {
var object = null;
switch (this.nodeType) {
case this.ELEMENT_NODE:
- object = attrCopy(this,this._ownerDocument.createElement(this.tagName));
+ object = attrCopy(this,this._ownerDocument.createElement(this.tagName), fn);
break;
case this.TEXT_NODE:
@@ -719,6 +724,10 @@ core.Node.prototype = {
break;
}
+ if (typeof fn === "function") {
+ fn(this, object);
+ }
+
if (deep || this.nodeType === ATTRIBUTE_NODE) {
var clone = null;
for (var i=0,len=this._childNodes.length;i<len;i++)
View
18 lib/jsdom/level2/core.js
@@ -459,7 +459,17 @@ core.Document.prototype.importNode = function(/* Node */ importedNode,
}
var self = this,
- newNode = importedNode.cloneNode(deep);
+ newNode = importedNode.cloneNode(deep, function(a, b) {
+
+ if (a.namespaceURI) {
+ b.namespaceURI = a.namespaceURI;
+ }
+
+ if (a.qualifiedName) {
+ b.qualifiedName = a.qualifiedName;
+ }
+ console.log(b.name)
+ });
function setOwnerDocument(el) {
var attr;
@@ -488,13 +498,7 @@ core.Document.prototype.importNode = function(/* Node */ importedNode,
newNode._specified = true;
}
- if (importedNode.namespaceURI) {
- newNode.namespaceURI = importedNode.namespaceURI;
- }
- if (importedNode.qualifiedName) {
- newnode.qualifiedName = importedNode.qualifiedName;
- }
return newNode;
View
2 test/level2/core.js
@@ -2769,6 +2769,8 @@ newDoc = domImpl.createDocument(nullNS,"staff",nullDocType);
imported = newDoc.importNode(employeeElem,true);
attrNode = imported.getAttributeNodeNS(nullNS,"defaultAttr");
assertNull("defaultAttrNotImported",attrNode);
+
+ console.log(Object.keys(imported.attributes._nodes))
attrValue = imported.getAttributeNS("http://www.w3.org/2000/xmlns/","emp");
assertEquals("explicitAttrImported","http://www.nist.gov",attrValue);
View
2 test/level2/core/files/staffNS.xml.js
@@ -195,6 +195,8 @@ exports.staffNS = function() {
salary.appendChild(doc.createTextNode("95,000"));
address.setAttributeNS("http://www.nist.gov", "emp:domestic", "Yes");
address.setAttributeNS(null, "street", "Y");
+ address.getAttributeNodeNS(null, "street").appendChild(doc.createEntityReference('&ent1;'))
+
// This behavior appears to be undefined!
address.setAttributeNS("http://www.nist.gov", "emp:zone", "CANADA");

0 comments on commit 66f6894

Please sign in to comment.
Something went wrong with that request. Please try again.