simple-dom
Advanced tools
Comparing version 0.2.2 to 0.2.3
(function() { | ||
"use strict"; | ||
function $$document$node$$Node(nodeType, nodeName, nodeValue) { | ||
function simple$dom$document$node$$Node(nodeType, nodeName, nodeValue) { | ||
this.nodeType = nodeType; | ||
@@ -8,3 +8,3 @@ this.nodeName = nodeName; | ||
this.childNodes = new $$document$node$$ChildNodes(this); | ||
this.childNodes = new simple$dom$document$node$$ChildNodes(this); | ||
@@ -18,7 +18,7 @@ this.parentNode = null; | ||
$$document$node$$Node.prototype._cloneNode = function() { | ||
return new $$document$node$$Node(this.nodeType, this.nodeName, this.nodeValue); | ||
simple$dom$document$node$$Node.prototype._cloneNode = function() { | ||
return new simple$dom$document$node$$Node(this.nodeType, this.nodeName, this.nodeValue); | ||
}; | ||
$$document$node$$Node.prototype.cloneNode = function(deep) { | ||
simple$dom$document$node$$Node.prototype.cloneNode = function(deep) { | ||
var node = this._cloneNode(); | ||
@@ -39,5 +39,5 @@ | ||
$$document$node$$Node.prototype.appendChild = function(node) { | ||
if (node.nodeType === $$document$node$$Node.DOCUMENT_FRAGMENT_NODE) { | ||
$$document$node$$insertFragment(node, this, this.lastChild, null); | ||
simple$dom$document$node$$Node.prototype.appendChild = function(node) { | ||
if (node.nodeType === simple$dom$document$node$$Node.DOCUMENT_FRAGMENT_NODE) { | ||
simple$dom$document$node$$insertFragment(node, this, this.lastChild, null); | ||
return; | ||
@@ -60,3 +60,3 @@ } | ||
function $$document$node$$insertFragment(fragment, newParent, before, after) { | ||
function simple$dom$document$node$$insertFragment(fragment, newParent, before, after) { | ||
if (!fragment.firstChild) { return; } | ||
@@ -89,3 +89,3 @@ | ||
$$document$node$$Node.prototype.insertBefore = function(node, refNode) { | ||
simple$dom$document$node$$Node.prototype.insertBefore = function(node, refNode) { | ||
if (refNode == null) { | ||
@@ -95,4 +95,4 @@ return this.appendChild(node); | ||
if (node.nodeType === $$document$node$$Node.DOCUMENT_FRAGMENT_NODE) { | ||
$$document$node$$insertFragment(node, this, refNode ? refNode.previousSibling : null, refNode); | ||
if (node.nodeType === simple$dom$document$node$$Node.DOCUMENT_FRAGMENT_NODE) { | ||
simple$dom$document$node$$insertFragment(node, this, refNode ? refNode.previousSibling : null, refNode); | ||
return; | ||
@@ -107,2 +107,4 @@ } | ||
node.previousSibling = previousSibling; | ||
}else{ | ||
node.previousSibling = null | ||
} | ||
@@ -118,3 +120,3 @@ | ||
$$document$node$$Node.prototype.removeChild = function(refNode) { | ||
simple$dom$document$node$$Node.prototype.removeChild = function(refNode) { | ||
if (this.firstChild === refNode) { | ||
@@ -137,20 +139,20 @@ this.firstChild = refNode.nextSibling; | ||
$$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; | ||
simple$dom$document$node$$Node.ELEMENT_NODE = 1; | ||
simple$dom$document$node$$Node.ATTRIBUTE_NODE = 2; | ||
simple$dom$document$node$$Node.TEXT_NODE = 3; | ||
simple$dom$document$node$$Node.CDATA_SECTION_NODE = 4; | ||
simple$dom$document$node$$Node.ENTITY_REFERENCE_NODE = 5; | ||
simple$dom$document$node$$Node.ENTITY_NODE = 6; | ||
simple$dom$document$node$$Node.PROCESSING_INSTRUCTION_NODE = 7; | ||
simple$dom$document$node$$Node.COMMENT_NODE = 8; | ||
simple$dom$document$node$$Node.DOCUMENT_NODE = 9; | ||
simple$dom$document$node$$Node.DOCUMENT_TYPE_NODE = 10; | ||
simple$dom$document$node$$Node.DOCUMENT_FRAGMENT_NODE = 11; | ||
simple$dom$document$node$$Node.NOTATION_NODE = 12; | ||
function $$document$node$$ChildNodes(node) { | ||
function simple$dom$document$node$$ChildNodes(node) { | ||
this.node = node; | ||
} | ||
$$document$node$$ChildNodes.prototype.item = function(index) { | ||
simple$dom$document$node$$ChildNodes.prototype.item = function(index) { | ||
var child = this.node.firstChild; | ||
@@ -165,3 +167,3 @@ | ||
var $$document$node$$default = $$document$node$$Node; | ||
var simple$dom$document$node$$default = simple$dom$document$node$$Node; | ||
@@ -176,5 +178,5 @@ function $$document$element$$Element(tagName) { | ||
$$document$element$$Element.prototype = Object.create($$document$node$$default.prototype); | ||
$$document$element$$Element.prototype = Object.create(simple$dom$document$node$$default.prototype); | ||
$$document$element$$Element.prototype.constructor = $$document$element$$Element; | ||
$$document$element$$Element.prototype.nodeConstructor = $$document$node$$default; | ||
$$document$element$$Element.prototype.nodeConstructor = simple$dom$document$node$$default; | ||
@@ -243,5 +245,5 @@ $$document$element$$Element.prototype._cloneNode = function() { | ||
$$document$text$$Text.prototype = Object.create($$document$node$$default.prototype); | ||
$$document$text$$Text.prototype = Object.create(simple$dom$document$node$$default.prototype); | ||
$$document$text$$Text.prototype.constructor = $$document$text$$Text; | ||
$$document$text$$Text.prototype.nodeConstructor = $$document$node$$default; | ||
$$document$text$$Text.prototype.nodeConstructor = simple$dom$document$node$$default; | ||
@@ -258,5 +260,5 @@ var $$document$text$$default = $$document$text$$Text; | ||
$$document$comment$$Comment.prototype = Object.create($$document$node$$default.prototype); | ||
$$document$comment$$Comment.prototype = Object.create(simple$dom$document$node$$default.prototype); | ||
$$document$comment$$Comment.prototype.constructor = $$document$comment$$Comment; | ||
$$document$comment$$Comment.prototype.nodeConstructor = $$document$node$$default; | ||
$$document$comment$$Comment.prototype.nodeConstructor = simple$dom$document$node$$default; | ||
@@ -273,5 +275,5 @@ var $$document$comment$$default = $$document$comment$$Comment; | ||
$$document$document$fragment$$DocumentFragment.prototype = Object.create($$document$node$$default.prototype); | ||
$$document$document$fragment$$DocumentFragment.prototype = Object.create(simple$dom$document$node$$default.prototype); | ||
$$document$document$fragment$$DocumentFragment.prototype.constructor = $$document$document$fragment$$DocumentFragment; | ||
$$document$document$fragment$$DocumentFragment.prototype.nodeConstructor = $$document$node$$default; | ||
$$document$document$fragment$$DocumentFragment.prototype.nodeConstructor = simple$dom$document$node$$default; | ||
@@ -281,3 +283,3 @@ var $$document$document$fragment$$default = $$document$document$fragment$$DocumentFragment; | ||
function simple$dom$document$$Document() { | ||
this.nodeConstructor(this, 9, '#document', null); | ||
this.nodeConstructor(9, '#document', null); | ||
this.documentElement = new $$document$element$$default('html'); | ||
@@ -289,5 +291,5 @@ this.body = new $$document$element$$default('body'); | ||
simple$dom$document$$Document.prototype = Object.create($$document$node$$default.prototype); | ||
simple$dom$document$$Document.prototype = Object.create(simple$dom$document$node$$default.prototype); | ||
simple$dom$document$$Document.prototype.constructor = simple$dom$document$$Document; | ||
simple$dom$document$$Document.prototype.nodeConstructor = $$document$node$$default; | ||
simple$dom$document$$Document.prototype.nodeConstructor = simple$dom$document$node$$default; | ||
@@ -311,2 +313,15 @@ simple$dom$document$$Document.prototype.createElement = function(tagName) { | ||
var simple$dom$document$$default = simple$dom$document$$Document; | ||
QUnit.module('Document'); | ||
QUnit.test("creating a document node", function(assert) { | ||
var document = new simple$dom$document$$default(); | ||
// https://developer.mozilla.org/en-US/docs/Web/API/Node/nodeType | ||
assert.strictEqual(document.nodeType, 9, "document has node type of 9"); | ||
// https://developer.mozilla.org/en-US/docs/Web/API/Node/nodeName | ||
assert.strictEqual(document.nodeName, "#document", "document node has the name #document"); | ||
// https://developer.mozilla.org/en-US/docs/Web/API/Node/nodeValue | ||
assert.strictEqual(document.nodeValue, null, "for the document itself, nodeValue returns null"); | ||
}); | ||
function simple$dom$html$serializer$$HTMLSerializer(voidMap) { | ||
@@ -588,2 +603,23 @@ this.voidMap = voidMap; | ||
}); | ||
QUnit.module('Node'); | ||
QUnit.test("#insertBefore", function(assert) { | ||
var body = new simple$dom$document$node$$default(1, 'body'); | ||
var div = new simple$dom$document$node$$default(1, 'div'); | ||
var span = new simple$dom$document$node$$default(1, 'span'); | ||
var ul = new simple$dom$document$node$$default(1, 'ul'); | ||
span.previousSibling = new simple$dom$document$node$$default(1, 'p'); | ||
body.appendChild(div); | ||
body.insertBefore(span, div); | ||
assert.strictEqual(span.parentNode, body, "nodes parent is set"); | ||
assert.strictEqual(span.previousSibling, null, "nodes previous sibling is cleared"); | ||
assert.strictEqual(span.nextSibling, div, "nodes next sibling is set"); | ||
assert.strictEqual(div.previousSibling, span, "next sibling's previous sibling is set"); | ||
assert.strictEqual(div.nextSibling, null, "next sibling's next sibling is set"); | ||
assert.strictEqual(div.parentNode, body, "next sibling's parent is set"); | ||
assert.strictEqual(body.firstChild, span, "parents first child is set"); | ||
assert.strictEqual(body.lastChild, div, "parents last child is set"); | ||
}); | ||
function simple$dom$html$parser$$HTMLParser(tokenize, document, voidMap) { | ||
@@ -590,0 +626,0 @@ this.tokenize = tokenize; |
@@ -101,2 +101,4 @@ (function() { | ||
node.previousSibling = previousSibling; | ||
}else{ | ||
node.previousSibling = null | ||
} | ||
@@ -268,3 +270,3 @@ | ||
function simple$dom$document$$Document() { | ||
this.nodeConstructor(this, 9, '#document', null); | ||
this.nodeConstructor(9, '#document', null); | ||
this.documentElement = new simple$dom$document$element$$default('html'); | ||
@@ -271,0 +273,0 @@ this.body = new simple$dom$document$element$$default('body'); |
@@ -8,3 +8,3 @@ import Node from './document/node'; | ||
function Document() { | ||
this.nodeConstructor(this, 9, '#document', null); | ||
this.nodeConstructor(9, '#document', null); | ||
this.documentElement = new Element('html'); | ||
@@ -11,0 +11,0 @@ this.body = new Element('body'); |
@@ -99,2 +99,4 @@ function Node(nodeType, nodeName, nodeValue) { | ||
node.previousSibling = previousSibling; | ||
}else{ | ||
node.previousSibling = null | ||
} | ||
@@ -101,0 +103,0 @@ |
{ | ||
"name": "simple-dom", | ||
"version": "0.2.2", | ||
"version": "0.2.3", | ||
"description": "A simple JS DOM.", | ||
@@ -5,0 +5,0 @@ "main": "dist/simple-dom.js", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
282643
1927