min-document
Advanced tools
Comparing version 2.4.1 to 2.5.0
@@ -23,2 +23,7 @@ var DOMText = require("./dom-text.js") | ||
proto.createElementNS = function createElementNS(namespace, tagName) { | ||
var ns = namespace === null ? null : String(namespace) | ||
return new DOMElement(tagName, this, ns) | ||
} | ||
proto.createElement = function createElement(tagName) { | ||
@@ -25,0 +30,0 @@ return new DOMElement(tagName, this) |
@@ -5,5 +5,7 @@ var dispatchEvent = require("./event/dispatch-event.js") | ||
var htmlns = "http://www.w3.org/1999/xhtml" | ||
module.exports = DOMElement | ||
function DOMElement(tagName, owner) { | ||
function DOMElement(tagName, owner, namespace) { | ||
if (!(this instanceof DOMElement)) { | ||
@@ -13,3 +15,5 @@ return new DOMElement(tagName) | ||
this.tagName = String(tagName).toUpperCase() | ||
var ns = namespace === undefined ? htmlns : (namespace || null) | ||
this.tagName = ns === htmlns ? String(tagName).toUpperCase() : tagName | ||
this.className = "" | ||
@@ -20,3 +24,4 @@ this.dataset = {} | ||
this.style = {} | ||
this.ownerDocument = owner || null; | ||
this.ownerDocument = owner || null | ||
this.namespaceURI = ns | ||
} | ||
@@ -23,0 +28,0 @@ |
{ | ||
"name": "min-document", | ||
"version": "2.4.1", | ||
"version": "2.5.0", | ||
"description": "A minimal DOM implementation", | ||
@@ -21,2 +21,5 @@ "keywords": [], | ||
"devDependencies": { | ||
"run-browser": "git://github.com/Raynos/run-browser", | ||
"tap-dot": "^0.2.1", | ||
"tap-spec": "^0.1.8", | ||
"tape": "^2.12.3" | ||
@@ -31,3 +34,8 @@ }, | ||
"scripts": { | ||
"test": "node ./test/index.js" | ||
"test": "node ./test/index.js | tap-spec", | ||
"dot": "node ./test/index.js | tap-dot", | ||
"cover": "istanbul cover --report none --print detail ./test/index.js", | ||
"view-cover": "istanbul report html && google-chrome ./coverage/index.html", | ||
"browser": "run-browser test/index.js", | ||
"phantom": "run-browser test/index.js -b | tap-spec" | ||
}, | ||
@@ -34,0 +42,0 @@ "testling": { |
@@ -6,3 +6,9 @@ module.exports = serializeElement | ||
strings.push("<" + elem.tagName.toLowerCase() + | ||
var tagname = elem.tagName | ||
if (elem.namespaceURI === "http://www.w3.org/1999/xhtml") { | ||
tagname = tagname.toLowerCase() | ||
} | ||
strings.push("<" + tagname + | ||
properties(elem) + datasetify(elem) + ">") | ||
@@ -18,5 +24,5 @@ | ||
strings.push("</" + elem.tagName.toLowerCase() + ">") | ||
strings.push("</" + tagname + ">") | ||
return strings.join("\n") | ||
return strings.join("") | ||
} | ||
@@ -30,3 +36,3 @@ | ||
key !== "nodeName" && key !== "className" && key !== "tagName" && | ||
key !== "textContent" | ||
key !== "textContent" && key !== "namespaceURI" | ||
} | ||
@@ -33,0 +39,0 @@ |
@@ -1,119 +0,8 @@ | ||
var test = require("tape") | ||
var testDocument = require("./test-document") | ||
var document = require("../index") | ||
test("document is a Document", function (assert) { | ||
assert.equal(typeof document.createTextNode, "function") | ||
assert.equal(typeof document.createElement, "function") | ||
assert.equal(typeof document.createDocumentFragment, "function") | ||
testDocument(document) | ||
assert.end() | ||
}) | ||
test("can do stuff", function (assert) { | ||
var div = document.createElement("div") | ||
div.className = "foo bar" | ||
var span = document.createElement("span") | ||
div.appendChild(span) | ||
span.textContent = "Hello!" | ||
var html = String(div) | ||
assert.equal(html, "<div class=\"foo bar\">\n" + | ||
"<span>\nHello!\n</span>\n</div>") | ||
assert.end() | ||
}) | ||
test("can createDocumentFragment", function (assert) { | ||
var frag = document.createDocumentFragment() | ||
assert.equal(frag.nodeType, 11) | ||
var h1 = document.createElement("h1") | ||
var h2 = document.createElement("h2") | ||
assert.equal(h1.nodeType, 1) | ||
assert.equal(h1.nodeType, 1) | ||
frag.appendChild(h1) | ||
assert.equal(String(frag), "<h1>\n</h1>") | ||
frag.appendChild(h2) | ||
assert.equal(String(frag), "<h1>\n</h1><h2>\n</h2>") | ||
frag.removeChild(h1) | ||
assert.equal(String(frag), "<h2>\n</h2>") | ||
frag.replaceChild(h1, h2) | ||
assert.equal(String(frag), "<h1>\n</h1>") | ||
assert.end() | ||
}) | ||
test("can getElementById", function (assert) { | ||
function append_div(id, parent) { | ||
var div = document.createElement("div") | ||
div.id = id | ||
parent.appendChild(div) | ||
return div | ||
} | ||
var div1 = append_div(1, document.body) | ||
var div2 = append_div(2, document.body) | ||
var div3 = append_div(3, document.body) | ||
var div11 = append_div(11, div1) | ||
var div12 = append_div(12, div1) | ||
var div21 = append_div(21, div2) | ||
var div22 = append_div(22, div2) | ||
var div221 = append_div(221, div22) | ||
var div222 = append_div(222, div22) | ||
assert.equal(document.getElementById(1), div1) | ||
assert.equal(document.getElementById("2"), div2) | ||
assert.equal(document.getElementById(3), div3) | ||
assert.equal(document.getElementById(11), div11) | ||
assert.equal(document.getElementById(12), div12) | ||
assert.equal(document.getElementById(21), div21) | ||
assert.equal(document.getElementById(22), div22) | ||
assert.equal(document.getElementById(221), div221) | ||
assert.equal(document.getElementById(222), div222) | ||
assert.end() | ||
}) | ||
test("can create/manipulate textnodes", function (assert) { | ||
var textnode = document.createTextNode("hello") | ||
assert.equal(textnode.nodeType, 3) | ||
assert.equal(textnode.data, "hello") | ||
assert.equal(typeof textnode.replaceData, "function") | ||
textnode.replaceData(0, 7, "nightly") | ||
assert.equal(textnode.nodeType, 3) | ||
assert.equal(textnode.data, "nightly") | ||
assert.equal(typeof textnode.replaceData, "function") | ||
textnode.replaceData(1, 1, "ou") | ||
assert.equal(textnode.nodeType, 3) | ||
assert.equal(textnode.data, "noughtly") | ||
assert.end() | ||
}) | ||
test("owner document is set", function (assert) { | ||
var textnode = document.createTextNode("hello") | ||
var domnode = document.createElement("div") | ||
var fragment = document.createDocumentFragment() | ||
assert.equal(textnode.ownerDocument, document) | ||
assert.equal(domnode.ownerDocument, document) | ||
assert.equal(fragment.ownerDocument, document) | ||
assert.end() | ||
}) | ||
if (typeof window !== "undefined" && window.document) { | ||
testDocument(window.document) | ||
} |
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
22958
21
440
4