Skip to content

Commit

Permalink
Add a spec to support namespaces in attr binding.
Browse files Browse the repository at this point in the history
Attribute namespaces can be defined by `xmlns:<i>prefix</i>="namespace-url"`
attributes, and allow all descendents of that element to define
`<i>prefix</i>:name="value"` attributes.
  • Loading branch information
rampion committed Aug 7, 2013
1 parent 77de67e commit 6d3d744
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion spec/defaultBindings/attrBehaviors.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,24 @@ describe('Binding: Attr', function() {
expect(testNode.childNodes[0].getAttribute("second-attribute")).toEqual("true");
});

it('Should be able to set namespaced attribute values', function() {
var model = { myValue: "first value" };
testNode.innerHTML = [
'<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">',
'<g>',
'<a data-bind="attr: { \'xlink:href\': myValue }">',
'<text>foo</text>',
'</a>',
'</g>',
'</svg>'
].join('');

ko.applyBindings(model, testNode);
var anchor = testNode.childNodes[0]/*svg*/.childNodes[0]/*g*/.childNodes[0]/*a*/;
expect( anchor.getAttributeNode('xlink:href').value ).toEqual( 'first value' );
expect( anchor.getAttributeNode('xlink:href').namespaceURI ).toEqual( 'http://www.w3.org/1999/xlink' );
});

it('Should be able to set \"name\" attribute, even on IE6-7', function() {
var myValue = ko.observable("myName");
testNode.innerHTML = "<input data-bind='attr: { name: myValue }' />";
Expand Down Expand Up @@ -62,4 +80,4 @@ describe('Binding: Attr', function() {
expect(testNode.childNodes[0].className).toEqual("");
expect(testNode.childNodes[0].getAttribute("class")).toEqual(null);
});
});
});

0 comments on commit 6d3d744

Please sign in to comment.