domhandler
Advanced tools
Comparing version 2.2.0 to 2.2.1
46
index.js
var ElementType = require("domelementtype"); | ||
var re_whitespace = /\s+/g; | ||
var NodePrototype = require("./lib/node"); | ||
var ElementPrototype = require("./lib/element"); | ||
@@ -62,3 +64,3 @@ function DomHandler(callback, options, elementCB){ | ||
if (this._options.withDomLvl1) { | ||
element.__proto__ = NodePrototype; | ||
element.__proto__ = element.type === "tag" ? ElementPrototype : NodePrototype; | ||
} | ||
@@ -77,44 +79,2 @@ | ||
// This object will be used as the prototype for Nodes when creating a | ||
// DOM-Level-1-compliant structure. | ||
var NodePrototype = { | ||
get firstChild() { | ||
var children = this.children; | ||
return children && children[0] || null; | ||
}, | ||
get lastChild() { | ||
var children = this.children; | ||
return children && children[children.length - 1] || null; | ||
}, | ||
get nodeType() { | ||
return nodeTypes[this.type] || nodeTypes.element; | ||
} | ||
}; | ||
var domLvl1 = { | ||
tagName: "name", | ||
childNodes: "children", | ||
parentNode: "parent", | ||
previousSibling: "prev", | ||
nextSibling: "next", | ||
nodeValue: "data" | ||
}; | ||
var nodeTypes = { | ||
element: 1, | ||
text: 3, | ||
cdata: 4, | ||
comment: 8 | ||
}; | ||
Object.keys(domLvl1).forEach(function(key) { | ||
var shorthand = domLvl1[key]; | ||
Object.defineProperty(NodePrototype, key, { | ||
get: function() { | ||
return this[shorthand] || null; | ||
}, | ||
set: function(val) { | ||
this[shorthand] = val; | ||
return val; | ||
} | ||
}); | ||
}); | ||
DomHandler.prototype.onopentag = function(name, attribs){ | ||
@@ -121,0 +81,0 @@ var element = { |
{ | ||
"name": "domhandler", | ||
"version": "2.2.0", | ||
"version": "2.2.1", | ||
"description": "handler for htmlparser2 that turns pages into a dom", | ||
@@ -14,3 +14,3 @@ "main": "index.js", | ||
"type": "git", | ||
"url": "git://github.com/fb55/domhandler.git" | ||
"url": "git://github.com/fb55/DomHandler.git" | ||
}, | ||
@@ -17,0 +17,0 @@ "keywords": [ |
@@ -17,2 +17,3 @@ { | ||
"nodeType": 3, | ||
"tagName": null, | ||
"data": "some stray text", | ||
@@ -35,2 +36,3 @@ "nodeValue": "some stray text", | ||
"nodeType": 3, | ||
"tagName": null, | ||
"data": "Hello, world.", | ||
@@ -46,2 +48,3 @@ "nodeValue": "Hello, world.", | ||
"nodeType": 3, | ||
"tagName": null, | ||
"data": "Hello, world.", | ||
@@ -56,2 +59,3 @@ "nodeValue": "Hello, world.", | ||
"nodeType": 3, | ||
"tagName": null, | ||
"data": "Hello, world.", | ||
@@ -67,2 +71,3 @@ "nodeValue": "Hello, world.", | ||
"nodeType": 8, | ||
"tagName": null, | ||
"data": " comment node ", | ||
@@ -87,2 +92,3 @@ "nodeValue": " comment node ", | ||
"type": "text", | ||
"tagName": null, | ||
"data": "more stray text" | ||
@@ -92,2 +98,3 @@ }, | ||
"type": "text", | ||
"tagName": null, | ||
"data": "more stray text" | ||
@@ -99,2 +106,3 @@ } | ||
"nodeType": 3, | ||
"tagName": null, | ||
"data": "more stray text", | ||
@@ -112,2 +120,3 @@ "nodeValue": "more stray text", | ||
"nodeType": 3, | ||
"tagName": null, | ||
"data": "some stray text", | ||
@@ -122,2 +131,3 @@ "nodeValue": "some stray text", | ||
"nodeType": 3, | ||
"tagName": null, | ||
"data": "more stray text", | ||
@@ -124,0 +134,0 @@ "nodeValue": "more stray text", |
Sorry, the diff of this file is not supported yet
24298
31
884