min-document
Advanced tools
Comparing version 2.12.0 to 2.13.0
@@ -96,21 +96,40 @@ var dispatchEvent = require("./event/dispatch-event.js") | ||
DOMElement.prototype.setAttribute = | ||
function _Element_setAttribute(name, value) { | ||
this._attributes[name] = value | ||
DOMElement.prototype.setAttributeNS = | ||
function _Element_setAttributeNS(namespace, name, value) { | ||
var colonPosition = name.indexOf(":") | ||
var localName = colonPosition > -1 ? name.substr(colonPosition + 1) : name | ||
var attributes = this._attributes[namespace] || (this._attributes[namespace] = {}) | ||
attributes[localName] = value | ||
} | ||
DOMElement.prototype.getAttribute = | ||
function _Element_getAttribute(name) { | ||
if (typeof this._attributes[name] !== "string") { | ||
DOMElement.prototype.getAttributeNS = | ||
function _Element_getAttributeNS(namespace, name) { | ||
var attributes = this._attributes[namespace]; | ||
if (!(attributes && typeof attributes[name] === "string")) { | ||
return null | ||
} | ||
return this._attributes[name] | ||
return attributes[name] | ||
} | ||
DOMElement.prototype.removeAttribute = | ||
function _Element_removeAttribute(name) { | ||
delete this._attributes[name] | ||
DOMElement.prototype.removeAttributeNS = | ||
function _Element_removeAttributeNS(namespace, name) { | ||
var attributes = this._attributes[namespace]; | ||
if (attributes) { | ||
delete attributes[name] | ||
} | ||
} | ||
DOMElement.prototype.setAttribute = function _Element_setAttribute(name, value) { | ||
return this.setAttributeNS(null, name, value) | ||
} | ||
DOMElement.prototype.getAttribute = function _Element_getAttribute(name) { | ||
return this.getAttributeNS(null, name) | ||
} | ||
DOMElement.prototype.removeAttribute = function _Element_removeAttribute(name) { | ||
return this.removeAttributeNS(null, name) | ||
} | ||
DOMElement.prototype.removeEventListener = removeEventListener | ||
@@ -117,0 +136,0 @@ DOMElement.prototype.addEventListener = addEventListener |
{ | ||
"name": "min-document", | ||
"version": "2.12.0", | ||
"version": "2.13.0", | ||
"description": "A minimal DOM implementation", | ||
@@ -5,0 +5,0 @@ "keywords": [], |
@@ -332,2 +332,38 @@ var test = require("tape") | ||
test("can set and get namespaced attributes", function(assert) { | ||
var elem = document.createElement("div") | ||
var ns = "http://ns.com/my" | ||
assert.equal(elem.getAttributeNS(ns, "myattr"), blankAttributeNS()) | ||
elem.setAttributeNS(ns, "myns:myattr", "the value") | ||
assert.equal(elem.getAttributeNS(ns, "myattr"), "the value") | ||
elem.removeAttributeNS(ns, "myattr") | ||
assert.equal(elem.getAttributeNS(ns, "myattr"), blankAttributeNS()) | ||
// Should work much like get/setAttribute when namespace is null. | ||
assert.equal(elem.getAttributeNS(null, "foo"), blankAttributeNS()) | ||
assert.equal(elem.getAttribute("foo"), null) | ||
elem.setAttributeNS(null, "foo", "bar") | ||
assert.equal(elem.getAttributeNS(null, "foo"), "bar") | ||
assert.equal(elem.getAttribute("foo"), "bar") | ||
elem.removeAttributeNS(null, "foo") | ||
assert.equal(elem.getAttributeNS(null, "foo"), blankAttributeNS()) | ||
assert.equal(elem.getAttribute("foo"), null) | ||
assert.end() | ||
}) | ||
function blankAttributeNS() { | ||
// Most browsers conform to the latest version of the DOM spec, | ||
// which requires `getAttributeNS` to return `null` when the attribute | ||
// doesn't exist, but some browsers (including phantomjs) implement the | ||
// old version of the spec and return an empty string instead, see: | ||
// https://developer.mozilla.org/en-US/docs/Web/API/element.getAttributeNS#Return_value | ||
var div = document.createElement("div") | ||
var blank = div.getAttributeNS(null, "foo") | ||
if (!(blank === null || blank === "")) { | ||
throw "Expected blank attribute to be either null or empty string" | ||
} | ||
return blank; | ||
} | ||
function elemString(element) { | ||
@@ -334,0 +370,0 @@ var html = String(element) || "[]" |
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
39797
25
794