Merge pull request #133 from harrywincup/126-svg-foreignobject

126 svg foreignobject
pull/134/head
Simon Friis Vindum 9 years ago committed by GitHub
commit e202d11344

@ -1,11 +1,12 @@
var VNode = require('./vnode');
var is = require('./is');
function addNS(data, children) {
function addNS(data, children, sel) {
data.ns = 'http://www.w3.org/2000/svg';
if (children !== undefined) {
if (sel !== 'foreignObject' && children !== undefined) {
for (var i = 0; i < children.length; ++i) {
addNS(children[i].data, children[i].children);
addNS(children[i].data, children[i].children, children[i].sel);
}
}
}
@ -27,7 +28,7 @@ module.exports = function h(sel, b, c) {
}
}
if (sel[0] === 's' && sel[1] === 'v' && sel[2] === 'g') {
addNS(data, children);
addNS(data, children, sel);
}
return VNode(sel, data, children, text, undefined);
};

@ -73,8 +73,21 @@ describe('snabbdom', function() {
assert.equal(elm.firstChild.id, 'unique');
});
it('has correct namespace', function() {
elm = patch(vnode0, h('div', [h('div', {ns: 'http://www.w3.org/2000/svg'})])).elm;
assert.equal(elm.firstChild.namespaceURI, 'http://www.w3.org/2000/svg');
var SVGNamespace = 'http://www.w3.org/2000/svg';
var XHTMLNamespace = 'http://www.w3.org/1999/xhtml';
elm = patch(vnode0, h('div', [h('div', {ns: SVGNamespace})])).elm;
assert.equal(elm.firstChild.namespaceURI, SVGNamespace);
elm = patch(vnode0, h('svg', [
h('foreignObject', [
h('div', ['I am HTML embedded in SVG'])
])
])).elm;
assert.equal(elm.namespaceURI, SVGNamespace);
assert.equal(elm.firstChild.namespaceURI, SVGNamespace);
assert.equal(elm.firstChild.firstChild.namespaceURI, XHTMLNamespace);
});
it('is recieves classes in selector', function() {
elm = patch(vnode0, h('div', [h('i.am.a.class')])).elm;

Loading…
Cancel
Save