html-element
Advanced tools
Comparing version 2.1.1 to 2.2.0
30
index.js
@@ -16,3 +16,3 @@ var ClassList = require('class-list') | ||
var el = new Element(); | ||
el.nodeName = nodeName; | ||
el.nodeName = el.tagName = nodeName; | ||
return el; | ||
@@ -152,2 +152,3 @@ } | ||
self.childNodes[index] = newChild; | ||
newChild.parentElement = this; | ||
replaced = true; | ||
@@ -165,3 +166,4 @@ } | ||
// use splice to keep a clean childNode array | ||
self.childNodes.splice(index, 1) | ||
self.childNodes.splice(index, 1); | ||
rChild.parentElement = null; | ||
removed = true; | ||
@@ -175,9 +177,16 @@ } | ||
var childNodes = this.childNodes; | ||
for (var i = 0, len = childNodes.length; i < len; i++) { | ||
var child = childNodes[i]; | ||
if (child === existingChild) { | ||
i === 0 ? childNodes.unshift(newChild) : childNodes.splice(i, 0, newChild); | ||
break; | ||
if (existingChild === null) { | ||
childNodes.push(newChild); | ||
} else { | ||
for (var i = 0, len = childNodes.length; i < len; i++) { | ||
var child = childNodes[i]; | ||
if (child === existingChild) { | ||
i === 0 ? childNodes.unshift(newChild) : childNodes.splice(i, 0, newChild); | ||
break; | ||
} | ||
} | ||
} | ||
newChild.parentElement = this; | ||
return newChild; | ||
@@ -305,2 +314,9 @@ } | ||
Element.prototype.__defineSetter__('textContent', function (v) { | ||
var textNode = new Text() | ||
textNode.textContent = v | ||
this.childNodes = [textNode] | ||
return v | ||
}) | ||
Element.prototype.addEventListener = function(t, l) {} | ||
@@ -307,0 +323,0 @@ |
{ | ||
"name": "html-element", | ||
"version": "2.1.1", | ||
"version": "2.2.0", | ||
"homepage": "https://github.com/1N50MN14/html-element", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
@@ -11,2 +11,37 @@ require('../global-shim'); | ||
test('Element attributes', function(t){ | ||
var div = document.createElement('div') | ||
t.equal(div.nodeName, 'div') | ||
t.equal(div.tagName, 'div') | ||
t.end() | ||
}) | ||
test('assign textContent to an Element', function(t){ | ||
var div = document.createElement('div') | ||
t.equal(clean(div.textContent), '') | ||
// adds and replaces text | ||
div.textContent = 'text 1' | ||
t.equal(clean(div.textContent), 'text 1') | ||
div.textContent = 'text 2' | ||
t.equal(clean(div.textContent), 'text 2') | ||
// replaces existing children | ||
div = document.createElement('div') | ||
var p1 = document.createElement('p') | ||
var p2 = document.createElement('p') | ||
div.appendChild(p1) | ||
div.appendChild(p2) | ||
t.same(div.childNodes[0], p1) | ||
t.same(div.childNodes[1], p2) | ||
t.equal(clean(div.textContent), '') | ||
div.textContent = 'replacement' | ||
t.equal(clean(div.textContent), 'replacement') | ||
t.equal(div.childNodes.length, 1) | ||
t.notSame(div.childNodes[0], p1) | ||
t.end() | ||
}) | ||
test('create a Text node', function(t){ | ||
@@ -243,2 +278,4 @@ var h1 = document.createElement('h1') | ||
t.same(children[1], div2) | ||
t.same(div2.parentNode, div) | ||
var div3 = document.createElement('div') | ||
@@ -248,3 +285,19 @@ div.insertBefore(div3, div2) | ||
t.same(children[2], div2) | ||
t.same(div2.parentNode, div) | ||
// If referenceNode is null, the newNode is inserted | ||
// at the end of the list of child nodes. | ||
var div4 = document.createElement('div') | ||
div.insertBefore(div4, null) | ||
t.same(children[2], div2) | ||
t.same(children[3], div4) | ||
t.same(div4.parentNode, div) | ||
// insertBefore should set parentNode | ||
var div5 = document.createElement('div') | ||
div.insertBefore(div5, div4) | ||
t.same(children[3], div5) | ||
t.same(div5.parentNode, div) | ||
t.end() | ||
}) |
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
29085
1054