simple-dom
Advanced tools
Comparing version 0.1.0 to 0.1.1
@@ -8,2 +8,4 @@ (function() { | ||
this.childNodes = new $$document$node$$ChildNodes(this); | ||
this.parentNode = null; | ||
@@ -17,2 +19,13 @@ this.previousSibling = null; | ||
$$document$node$$Node.prototype.appendChild = function(node) { | ||
if (node.nodeType === $$document$node$$Node.DOCUMENT_FRAGMENT_NODE) { | ||
/*jshint boss:true*/ | ||
for (var frag = node; node = frag.firstChild;) { | ||
this.appendChild(node); | ||
} | ||
return; | ||
} | ||
if (node.parentNode) { node.parentNode.removeChild(node); } | ||
node.parentNode = this; | ||
@@ -34,5 +47,14 @@ var refNode = this.lastChild; | ||
} | ||
node.parentNode = this; | ||
var previousSibling = refNode.previousSibling; | ||
if (previousSibling) { | ||
previousSibling.nextSibling = node; | ||
node.previousSibling = previousSibling; | ||
} | ||
refNode.previousSibling = node; | ||
node.nextSibling = refNode; | ||
if (this.firstChild === refNode) { | ||
@@ -57,9 +79,41 @@ this.firstChild = node; | ||
refNode.parentNode = null; | ||
refNode.nextSibling = null; | ||
refNode.previousSibling = null; | ||
}; | ||
$$document$node$$Node.ELEMENT_NODE = 1; | ||
$$document$node$$Node.ATTRIBUTE_NODE = 2; | ||
$$document$node$$Node.TEXT_NODE = 3; | ||
$$document$node$$Node.CDATA_SECTION_NODE = 4; | ||
$$document$node$$Node.ENTITY_REFERENCE_NODE = 5; | ||
$$document$node$$Node.ENTITY_NODE = 6; | ||
$$document$node$$Node.PROCESSING_INSTRUCTION_NODE = 7; | ||
$$document$node$$Node.COMMENT_NODE = 8; | ||
$$document$node$$Node.DOCUMENT_NODE = 9; | ||
$$document$node$$Node.DOCUMENT_TYPE_NODE = 10; | ||
$$document$node$$Node.DOCUMENT_FRAGMENT_NODE = 11; | ||
$$document$node$$Node.NOTATION_NODE = 12; | ||
function $$document$node$$ChildNodes(node) { | ||
this.node = node; | ||
} | ||
$$document$node$$ChildNodes.prototype.item = function(index) { | ||
var child = this.node.firstChild; | ||
for (var i = 0; child && index !== i; i++) { | ||
child = child.nextSibling; | ||
} | ||
return child; | ||
}; | ||
var $$document$node$$default = $$document$node$$Node; | ||
function $$document$element$$Element(tagName) { | ||
this.nodeConstructor(1, tagName.toUpperCase(), null); | ||
tagName = tagName.toUpperCase(); | ||
this.nodeConstructor(1, tagName, null); | ||
this.attributes = []; | ||
this.tagName = tagName; | ||
} | ||
@@ -174,2 +228,65 @@ | ||
var simple$dom$document$$default = simple$dom$document$$Document; | ||
QUnit.module('Element'); | ||
// See http://www.w3.org/TR/2000/WD-DOM-Level-1-20000929/level-one-core.html#ID-B63ED1A3 | ||
QUnit.test("appending a document fragment appends the fragment's children and not the fragment itself", function(assert) { | ||
var document = new simple$dom$document$$default(); | ||
var frag = document.createDocumentFragment(); | ||
var elem = document.createElement('div'); | ||
var body = document.body; | ||
assert.strictEqual(body.firstChild, null, "body has no children"); | ||
frag.appendChild(elem); | ||
body.appendChild(frag); | ||
assert.strictEqual(body.firstChild.tagName, "DIV", "fragment's child is added as child of document"); | ||
}); | ||
// http://www.w3.org/TR/DOM-Level-3-Core/core.html#ID-536297177 | ||
QUnit.test("child nodes can be access via item()", function(assert) { | ||
var document = new simple$dom$document$$default(); | ||
var parent = document.createElement('div'); | ||
var child1 = document.createElement('p'); | ||
var child2 = document.createElement('img'); | ||
assert.strictEqual(parent.childNodes.item(0), null, "attempting to access an item that doesn't exist returns null"); | ||
parent.appendChild(child1); | ||
parent.appendChild(child2); | ||
assert.strictEqual(parent.childNodes.item(0), child1); | ||
assert.strictEqual(parent.childNodes.item(1), child2); | ||
assert.strictEqual(parent.childNodes.item(2), null); | ||
parent.removeChild(child1); | ||
assert.strictEqual(parent.childNodes.item(0), child2); | ||
assert.strictEqual(parent.childNodes.item(1), null); | ||
parent.removeChild(child2); | ||
assert.strictEqual(parent.childNodes.item(0), null); | ||
assert.strictEqual(parent.childNodes.item(1), null); | ||
}); | ||
QUnit.test("insertBefore can insert before the last child node", function(assert) { | ||
var document = new simple$dom$document$$default(); | ||
var parent = document.createElement('div'); | ||
var child1 = document.createElement('p'); | ||
var child2 = document.createElement('img'); | ||
var child3 = document.createElement('span'); | ||
parent.appendChild(child1); | ||
parent.appendChild(child2); | ||
parent.insertBefore(child3, child2); | ||
assert.strictEqual(parent.childNodes.item(1), child3); | ||
}); | ||
var $$support$$document = (function (root){ | ||
@@ -176,0 +293,0 @@ if (root.document) { |
@@ -8,2 +8,4 @@ (function() { | ||
this.childNodes = new $$document$node$$ChildNodes(this); | ||
this.parentNode = null; | ||
@@ -17,2 +19,13 @@ this.previousSibling = null; | ||
$$document$node$$Node.prototype.appendChild = function(node) { | ||
if (node.nodeType === $$document$node$$Node.DOCUMENT_FRAGMENT_NODE) { | ||
/*jshint boss:true*/ | ||
for (var frag = node; node = frag.firstChild;) { | ||
this.appendChild(node); | ||
} | ||
return; | ||
} | ||
if (node.parentNode) { node.parentNode.removeChild(node); } | ||
node.parentNode = this; | ||
@@ -34,5 +47,14 @@ var refNode = this.lastChild; | ||
} | ||
node.parentNode = this; | ||
var previousSibling = refNode.previousSibling; | ||
if (previousSibling) { | ||
previousSibling.nextSibling = node; | ||
node.previousSibling = previousSibling; | ||
} | ||
refNode.previousSibling = node; | ||
node.nextSibling = refNode; | ||
if (this.firstChild === refNode) { | ||
@@ -57,9 +79,41 @@ this.firstChild = node; | ||
refNode.parentNode = null; | ||
refNode.nextSibling = null; | ||
refNode.previousSibling = null; | ||
}; | ||
$$document$node$$Node.ELEMENT_NODE = 1; | ||
$$document$node$$Node.ATTRIBUTE_NODE = 2; | ||
$$document$node$$Node.TEXT_NODE = 3; | ||
$$document$node$$Node.CDATA_SECTION_NODE = 4; | ||
$$document$node$$Node.ENTITY_REFERENCE_NODE = 5; | ||
$$document$node$$Node.ENTITY_NODE = 6; | ||
$$document$node$$Node.PROCESSING_INSTRUCTION_NODE = 7; | ||
$$document$node$$Node.COMMENT_NODE = 8; | ||
$$document$node$$Node.DOCUMENT_NODE = 9; | ||
$$document$node$$Node.DOCUMENT_TYPE_NODE = 10; | ||
$$document$node$$Node.DOCUMENT_FRAGMENT_NODE = 11; | ||
$$document$node$$Node.NOTATION_NODE = 12; | ||
function $$document$node$$ChildNodes(node) { | ||
this.node = node; | ||
} | ||
$$document$node$$ChildNodes.prototype.item = function(index) { | ||
var child = this.node.firstChild; | ||
for (var i = 0; child && index !== i; i++) { | ||
child = child.nextSibling; | ||
} | ||
return child; | ||
}; | ||
var $$document$node$$default = $$document$node$$Node; | ||
function $$document$element$$Element(tagName) { | ||
this.nodeConstructor(1, tagName.toUpperCase(), null); | ||
tagName = tagName.toUpperCase(); | ||
this.nodeConstructor(1, tagName, null); | ||
this.attributes = []; | ||
this.tagName = tagName; | ||
} | ||
@@ -66,0 +120,0 @@ |
import Node from './node'; | ||
function Element(tagName) { | ||
this.nodeConstructor(1, tagName.toUpperCase(), null); | ||
tagName = tagName.toUpperCase(); | ||
this.nodeConstructor(1, tagName, null); | ||
this.attributes = []; | ||
this.tagName = tagName; | ||
} | ||
@@ -54,2 +57,2 @@ | ||
export default Element; | ||
export default Element; |
@@ -6,2 +6,4 @@ function Node(nodeType, nodeName, nodeValue) { | ||
this.childNodes = new ChildNodes(this); | ||
this.parentNode = null; | ||
@@ -15,2 +17,13 @@ this.previousSibling = null; | ||
Node.prototype.appendChild = function(node) { | ||
if (node.nodeType === Node.DOCUMENT_FRAGMENT_NODE) { | ||
/*jshint boss:true*/ | ||
for (var frag = node; node = frag.firstChild;) { | ||
this.appendChild(node); | ||
} | ||
return; | ||
} | ||
if (node.parentNode) { node.parentNode.removeChild(node); } | ||
node.parentNode = this; | ||
@@ -32,5 +45,14 @@ var refNode = this.lastChild; | ||
} | ||
node.parentNode = this; | ||
var previousSibling = refNode.previousSibling; | ||
if (previousSibling) { | ||
previousSibling.nextSibling = node; | ||
node.previousSibling = previousSibling; | ||
} | ||
refNode.previousSibling = node; | ||
node.nextSibling = refNode; | ||
if (this.firstChild === refNode) { | ||
@@ -55,4 +77,33 @@ this.firstChild = node; | ||
refNode.parentNode = null; | ||
refNode.nextSibling = null; | ||
refNode.previousSibling = null; | ||
}; | ||
export default Node; | ||
Node.ELEMENT_NODE = 1; | ||
Node.ATTRIBUTE_NODE = 2; | ||
Node.TEXT_NODE = 3; | ||
Node.CDATA_SECTION_NODE = 4; | ||
Node.ENTITY_REFERENCE_NODE = 5; | ||
Node.ENTITY_NODE = 6; | ||
Node.PROCESSING_INSTRUCTION_NODE = 7; | ||
Node.COMMENT_NODE = 8; | ||
Node.DOCUMENT_NODE = 9; | ||
Node.DOCUMENT_TYPE_NODE = 10; | ||
Node.DOCUMENT_FRAGMENT_NODE = 11; | ||
Node.NOTATION_NODE = 12; | ||
function ChildNodes(node) { | ||
this.node = node; | ||
} | ||
ChildNodes.prototype.item = function(index) { | ||
var child = this.node.firstChild; | ||
for (var i = 0; child && index !== i; i++) { | ||
child = child.nextSibling; | ||
} | ||
return child; | ||
}; | ||
export default Node; |
{ | ||
"name": "simple-dom", | ||
"version": "0.1.0", | ||
"version": "0.1.1", | ||
"description": "A simple JS DOM.", | ||
"main": "index.js", | ||
"main": "dist/simple-dom.js", | ||
"scripts": { | ||
@@ -16,3 +16,2 @@ "prepublish": "bin/build.sh", | ||
], | ||
"main": "dist/simple-dom.js", | ||
"author": "Kris Selden", | ||
@@ -26,2 +25,3 @@ "license": "MIT", | ||
"es6-module-transpiler": "^0.9.6", | ||
"qunitjs": "^1.16.0", | ||
"simple-html-tokenizer": "^0.1.1", | ||
@@ -28,0 +28,0 @@ "testem": "^0.6.24" |
@@ -1,2 +0,2 @@ | ||
# About | ||
# About [![Build Status](https://travis-ci.org/krisselden/simple-dom.svg)](https://travis-ci.org/krisselden/simple-dom) | ||
@@ -3,0 +3,0 @@ A minimal DOM JS implementation focused on making a DOM helper for HTMLBars that gets morph running on server. |
Sorry, the diff of this file is not supported yet
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
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
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
237557
1722
4
1