Support namespaced attributes with default attr binding #27
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
When using knockout to create manage SVG or XML nodes, it is sometimes desirable to have it manage attributes from specific namespaces. For example, links in SVG documents use the xlink namespace. Currently, the attr binding doesn't support attribute namespaces, as can be seen in this fiddle. The hardcoded xlink:href works as a link, while the xlink:href attribute created by knockout doesn't, because it doesn't have the right namespace.
This could certainly be compensated for by creating a attr-ns binding just to handle namespaced attributes, however not only would this have a high degree of code repetition, but this breaks the similarity between hardcoded attribute and attributes defined by attr. The HTML parser is smart enough to figure out which attributes have namespaces, why shouldn't knockout do the same? The DOM provides the Node.lookupNamespaceURI(), Node.setAttributeNS() and Node.removeAttributeNS() methods just for this purpose.
This pull request uses these API functions to add namespace support to the default attr binding. It also adds a test to the spec to check that namespace support is working properly.
ref: http://stackoverflow.com/questions/18083723/how-can-i-get-knockout-js-to-set-the-namespaceuri-for-attributes
ref: knockout/knockout#1066