Permalink
Browse files

Added an _addIds method to reverse the _removeIds to handle appending…

… a structure that had children with ids so all ids get placed into the _ids cache on the document
  • Loading branch information...
1 parent 6a08748 commit 6995721d6aaf0a1981204b709886da69352143a9 @davglass committed Jan 31, 2011
Showing with 26 additions and 10 deletions.
  1. +26 −10 lib/jsdom/level1/core.js
View
@@ -455,6 +455,9 @@ core.Node.prototype = {
} else {
children.splice(i, 0, newChild);
newChild._parentNode = this;
+ if (newChild._addIds) {
+ newChild._addIds();
+ }
this._modified();
}
found = true;
@@ -521,9 +524,15 @@ core.Node.prototype = {
for (var j = 0;j<newChild._childNodes.length;j++) {
child = newChild._childNodes[j];
this._childNodes.splice(i+j,0, child);
+ if (child._addIds) {
+ child._addIds();
+ }
}
} else {
this._childNodes.splice(i,0, newChild);
+ if (newChild._addIds) {
+ newChild._addIds();
+ }
}
this._modified();
@@ -534,6 +543,19 @@ core.Node.prototype = {
}, //raises(DOMException);
/* returns void */
+ _addIds : function(){
+ if (this.id) {
+ if (this._ownerDocument._ids) {
+ this._ownerDocument._ids[this.id] = this;
+ }
+ }
+ for (var i=0;i<this._childNodes.length;i++) {
+ if (this._childNodes[i]._addIds) {
+ this._childNodes[i]._addIds();
+ }
+ }
+ },
+ /* returns void */
_removeIds : function(){
if (this.id) {
if (this._ownerDocument._ids) {
@@ -638,12 +660,8 @@ core.Node.prototype = {
newChild._parentNode = this;
this._childNodes.push(newChild);
this._modified();
-
- if (newChild.id) {
- if (!this._ownerDocument._ids) {
- this._ownerDocument._ids = {};
- }
- this._ownerDocument._ids[newChild.id] = newChild;
+ if (newChild._addIds) {
+ newChild._addIds();
}
}
@@ -1017,12 +1035,10 @@ core.Element.prototype = {
}
attributes.setNamedItem(attr);
}
-
if (name === 'id') {
- if (!this._ownerDocument._ids) {
- this._ownerDocument._ids = {};
+ if (this._addIds) {
+ this._addIds();
}
- this._ownerDocument._ids[value] = this;
}
attr._ownerElement = this;

0 comments on commit 6995721

Please sign in to comment.