Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

keeping defaults unspecified, namespaceURIs, localNames, etc

  • Loading branch information...
commit 8ce71ff5891e38dd285c3377b0678b1506c8e276 1 parent f878752
@tmpvar tmpvar authored
Showing with 48 additions and 27 deletions.
  1. +48 −27 lib/jsdom/level2/core.js
View
75 lib/jsdom/level2/core.js
@@ -249,13 +249,14 @@ core.NamedNodeMap.prototype.removeNamedItemNS = function(/*string */ namespaceUR
if (defaultAttr) {
clone = defaultAttr.cloneNode(true);
- clone._created = false;
- clone._namespaceURI = found._namespaceURI;
- clone._nodeName = found.name;
- clone._localName = found._localName;
- clone._prefix = found._prefix
+ clone._created = false;
+ clone._namespaceURI = found._namespaceURI;
+ clone._nodeName = found.name;
+ clone._localName = found._localName;
+ clone._prefix = found._prefix
this._nodes[clone._nodeName] = clone;
- clone._created = true;
+ clone._created = true;
+ clone._specified = false;
}
}
@@ -336,9 +337,9 @@ core.Element.prototype.setAttributeNS = function(/* string */ namespaceURI,
{
return true;
}
- });
+ })[0] || null;
- if (!found || !found[0]) {
+ if (!found) {
attr = this.setAttribute(qualifiedName, value);
if (attr) {
attr.namespaceURI = namespaceURI;
@@ -346,10 +347,9 @@ core.Element.prototype.setAttributeNS = function(/* string */ namespaceURI,
attr._prefix = prefix;
}
} else {
- attr = found[0];
- attr.qualifiedName = qualifiedName;
- attr.value = value;
- attr._localName = local;
+ found.qualifiedName = qualifiedName;
+ found.value = value;
+ found._localName = local;
}
attr._created = true;
@@ -395,6 +395,7 @@ core.Element.prototype.removeAttributeNS = function(/* string */ namespaceURI,
clone.namespaceURI = found.namespaceURI;
clone.qualifiedName = found.name;
this.setAttributeNodeNS(clone);
+ clone._specified = false;
}
return found;
@@ -508,19 +509,20 @@ core.Document.prototype.importNode = function(/* Node */ importedNode,
var self = this,
newNode = importedNode.cloneNode(deep, function(a, b) {
+ b._namespaceURI = a._namespaceURI;
+ b._nodeName = a._nodeName;
+ b._localName = a._localName;
+ }),
+ defaults = false,
+ defaultEl;
- if (a.namespaceURI) {
- b.namespaceURI = a.namespaceURI;
- }
-
- if (a._nodeName) {
- b._nodeName = a._nodeName;
- }
+ if (this.doctype && this.doctype._attributes) {
+ defaults = this.doctype._attributes;
+ }
- });
+ function lastChance(el) {
+ var attr, defaultEl;
- function setOwnerDocument(el) {
- var attr;
el._ownerDocument = self;
if (el.id) {
self._ids[el.id] = el;
@@ -533,22 +535,41 @@ core.Document.prototype.importNode = function(/* Node */ importedNode,
attr._specified = true;
}
}
+ if (defaults) {
+
+ defaultEl = defaults.getNamedItemNS(el._namespaceURI,
+ el._localName);
+
+ // TODO: This could use some love
+ if (defaultEl) {
+ defaultEl.attributes._map(function(defaultAttr) {
+ if (!el.hasAttributeNS(defaultAttr.namespaceURL,
+ defaultAttr.localName))
+ {
+ var clone = defaultAttr.cloneNode(true);
+ clone._namespaceURI = defaultAttr._namespaceURI;
+ clone._prefix = defaultAttr._prefix;
+ clone._localName = defaultAttr._localName;
+ el.setAttributeNodeNS(clone);
+ clone._specified = false;
+ }
+ });
+ }
+ }
+
}
if (deep) {
- core.visitTree(newNode, setOwnerDocument);
+ core.visitTree(newNode, lastChance);
}
else {
- setOwnerDocument(newNode);
+ lastChance(newNode);
}
if (newNode.nodeType == newNode.ATTRIBUTE_NODE) {
newNode._specified = true;
}
-
-
-
return newNode;
};
Please sign in to comment.
Something went wrong with that request. Please try again.