min-document
Advanced tools
Comparing version 2.6.0 to 2.6.1
@@ -36,2 +36,4 @@ var dispatchEvent = require("./event/dispatch-event.js") | ||
child.parentNode = this | ||
return child | ||
} | ||
@@ -52,2 +54,4 @@ | ||
elem.parentNode = this | ||
return needle | ||
} | ||
@@ -59,27 +63,29 @@ | ||
var index = this.childNodes.indexOf(elem) | ||
this.childNodes.splice(index, 1) | ||
this.childNodes[index].parentNode = null | ||
this.childNodes.splice(index, 1) | ||
elem.parentNode = null | ||
return elem | ||
} | ||
DOMElement.prototype.insertBefore = | ||
function _Element_insertBefore(newElement, referenceElement) { | ||
function _Element_insertBefore(elem, needle) { | ||
// TODO: Throw NotFoundError if referenceElement is a dom node | ||
// and parentNode !== this | ||
if (newElement.parentNode) { | ||
newElement.parentNode.removeChild(newElement) | ||
if (elem.parentNode) { | ||
elem.parentNode.removeChild(elem) | ||
} | ||
var index = referenceElement ? | ||
this.childNodes.indexOf(referenceElement) : | ||
-1 | ||
var index = needle === null || needle === undefined ? | ||
-1 : | ||
this.childNodes.indexOf(needle) | ||
if (index > -1) { | ||
this.childNodes.splice(index, 0, newElement) | ||
this.childNodes.splice(index, 0, elem) | ||
} else { | ||
this.childNodes.push(newElement) | ||
this.childNodes.push(elem) | ||
} | ||
newElement.parentNode = this | ||
elem.parentNode = this | ||
return elem | ||
} | ||
@@ -86,0 +92,0 @@ |
{ | ||
"name": "min-document", | ||
"version": "2.6.0", | ||
"version": "2.6.1", | ||
"description": "A minimal DOM implementation", | ||
@@ -5,0 +5,0 @@ "keywords": [], |
@@ -169,3 +169,4 @@ var test = require("tape") | ||
rootNode.appendChild(child) | ||
rootNode.insertBefore(newElement, child) | ||
var el = rootNode.insertBefore(newElement, child) | ||
assert.equal(el, newElement) | ||
assert.equal(rootNode.childNodes.length, 2) | ||
@@ -182,3 +183,4 @@ assert.equal(rootNode.childNodes[0], newElement) | ||
rootNode.appendChild(child) | ||
rootNode.insertBefore(newElement, null) | ||
var el = rootNode.insertBefore(newElement, null) | ||
assert.equal(el, newElement) | ||
assert.equal(rootNode.childNodes.length, 2) | ||
@@ -201,11 +203,14 @@ assert.equal(rootNode.childNodes[0], child) | ||
rootNode.appendChild(c1) | ||
var node1 = rootNode.appendChild(c1) | ||
assert.equal(node1, c1) | ||
assert.equal(parent.childNodes.length, 2) | ||
assert.equal(c1.parentNode, rootNode) | ||
rootNode.insertBefore(c2, c1) | ||
var node2 = rootNode.insertBefore(c2, c1) | ||
assert.equal(node2, c2) | ||
assert.equal(parent.childNodes.length, 1) | ||
assert.equal(c2.parentNode, rootNode) | ||
rootNode.replaceChild(c3, c2) | ||
var node3 = rootNode.replaceChild(c3, c2) | ||
assert.equal(node3, c2) | ||
assert.equal(parent.childNodes.length, 0) | ||
@@ -212,0 +217,0 @@ assert.equal(c3.parentNode, rootNode) |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
26574
532