can-attribute-observable
Advanced tools
Comparing version 2.0.0-pre.1 to 2.0.0
@@ -168,2 +168,29 @@ var testHelpers = require("../test/helpers"); | ||
}); | ||
testIfRealDocument("should use setAttributeNS instead of setAttribute for namespaced-attributes", function(assert) { | ||
var svgNamespaceURI = "http://www.w3.org/2000/svg"; | ||
var xlinkHrefAttrNamespaceURI = "http://www.w3.org/1999/xlink"; | ||
var xlinkHrefAttr = "xlink:href"; | ||
var origValue = "icons.svg#logo"; | ||
var newValue = "icons.svg#pointDown"; | ||
var svg = document.createElementNS(svgNamespaceURI, "svg"); | ||
var svgUse = document.createElementNS(svgNamespaceURI, "use"); | ||
svgUse.setAttributeNS(xlinkHrefAttrNamespaceURI, xlinkHrefAttr, origValue); | ||
svg.appendChild(svgUse); | ||
var ta = this.fixture; | ||
ta.appendChild(svg); | ||
var obs = new AttributeObservable(svgUse, xlinkHrefAttr); | ||
// test get | ||
var origValueNS = obs.get(xlinkHrefAttr); | ||
assert.equal(origValueNS, origValue, "get should match origValue"); | ||
// test set | ||
obs.set(newValue); | ||
assert.equal(svgUse.getAttributeNS(xlinkHrefAttrNamespaceURI, "href"), newValue, "getAttributeNS() should match newValue"); | ||
assert.equal(svgUse.getAttribute(xlinkHrefAttr), newValue, "getAttribute() should match newValue"); | ||
}); | ||
}); |
@@ -13,2 +13,10 @@ 'use strict'; | ||
var xmlnsAttrNamespaceURI = "http://www.w3.org/2000/xmlns/"; | ||
var xlinkHrefAttrNamespaceURI = "http://www.w3.org/1999/xlink"; | ||
var attrsNamespacesURI = { | ||
'xmlns': xmlnsAttrNamespaceURI, | ||
'xlink:href': xlinkHrefAttrNamespaceURI | ||
}; | ||
var formElements = {"INPUT": true, "TEXTAREA": true, "SELECT": true, "BUTTON": true}, | ||
@@ -500,3 +508,7 @@ // Used to convert values to strings. | ||
set: function(val) { | ||
domMutateNode.setAttribute.call(this, attrName, val); | ||
if (attrsNamespacesURI[attrName]) { | ||
domMutateNode.setAttributeNS.call(this, attrsNamespacesURI[attrName], attrName, val); | ||
} else { | ||
domMutateNode.setAttribute.call(this, attrName, val); | ||
} | ||
} | ||
@@ -503,0 +515,0 @@ }; |
{ | ||
"name": "can-attribute-observable", | ||
"version": "2.0.0-pre.1", | ||
"version": "2.0.0", | ||
"description": "Create observables from HTML attributes.", | ||
@@ -5,0 +5,0 @@ "main": "can-attribute-observable", |
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
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
49673
1159
1