Override namespace with xmlns attribute (#1825)
Fixes issue #1819 foreignObject inside SVG
This commit is contained in:
parent
2db6081601
commit
de4433cd31
2 changed files with 20 additions and 10 deletions
|
|
@ -6,9 +6,18 @@ module.exports = function($window) {
|
||||||
var $doc = $window.document
|
var $doc = $window.document
|
||||||
var $emptyFragment = $doc.createDocumentFragment()
|
var $emptyFragment = $doc.createDocumentFragment()
|
||||||
|
|
||||||
|
var nameSpace = {
|
||||||
|
svg: "http://www.w3.org/2000/svg",
|
||||||
|
math: "http://www.w3.org/1998/Math/MathML"
|
||||||
|
}
|
||||||
|
|
||||||
var onevent
|
var onevent
|
||||||
function setEventCallback(callback) {return onevent = callback}
|
function setEventCallback(callback) {return onevent = callback}
|
||||||
|
|
||||||
|
function getNameSpace(vnode) {
|
||||||
|
return vnode.attrs && vnode.attrs.xmlns || nameSpace[vnode.tag]
|
||||||
|
}
|
||||||
|
|
||||||
//create
|
//create
|
||||||
function createNodes(parent, vnodes, start, end, hooks, nextSibling, ns) {
|
function createNodes(parent, vnodes, start, end, hooks, nextSibling, ns) {
|
||||||
for (var i = start; i < end; i++) {
|
for (var i = start; i < end; i++) {
|
||||||
|
|
@ -66,14 +75,11 @@ module.exports = function($window) {
|
||||||
}
|
}
|
||||||
function createElement(parent, vnode, hooks, ns, nextSibling) {
|
function createElement(parent, vnode, hooks, ns, nextSibling) {
|
||||||
var tag = vnode.tag
|
var tag = vnode.tag
|
||||||
switch (vnode.tag) {
|
|
||||||
case "svg": ns = "http://www.w3.org/2000/svg"; break
|
|
||||||
case "math": ns = "http://www.w3.org/1998/Math/MathML"; break
|
|
||||||
}
|
|
||||||
|
|
||||||
var attrs = vnode.attrs
|
var attrs = vnode.attrs
|
||||||
var is = attrs && attrs.is
|
var is = attrs && attrs.is
|
||||||
|
|
||||||
|
ns = getNameSpace(vnode) || ns
|
||||||
|
|
||||||
var element = ns ?
|
var element = ns ?
|
||||||
is ? $doc.createElementNS(ns, tag, {is: is}) : $doc.createElementNS(ns, tag) :
|
is ? $doc.createElementNS(ns, tag, {is: is}) : $doc.createElementNS(ns, tag) :
|
||||||
is ? $doc.createElement(tag, {is: is}) : $doc.createElement(tag)
|
is ? $doc.createElement(tag, {is: is}) : $doc.createElement(tag)
|
||||||
|
|
@ -289,10 +295,8 @@ module.exports = function($window) {
|
||||||
}
|
}
|
||||||
function updateElement(old, vnode, recycling, hooks, ns) {
|
function updateElement(old, vnode, recycling, hooks, ns) {
|
||||||
var element = vnode.dom = old.dom
|
var element = vnode.dom = old.dom
|
||||||
switch (vnode.tag) {
|
ns = getNameSpace(vnode) || ns
|
||||||
case "svg": ns = "http://www.w3.org/2000/svg"; break
|
|
||||||
case "math": ns = "http://www.w3.org/1998/Math/MathML"; break
|
|
||||||
}
|
|
||||||
if (vnode.tag === "textarea") {
|
if (vnode.tag === "textarea") {
|
||||||
if (vnode.attrs == null) vnode.attrs = {}
|
if (vnode.attrs == null) vnode.attrs = {}
|
||||||
if (vnode.text != null) {
|
if (vnode.text != null) {
|
||||||
|
|
|
||||||
|
|
@ -55,7 +55,10 @@ o.spec("createElement", function() {
|
||||||
o(vnode.dom.childNodes[1].nodeName).equals("B")
|
o(vnode.dom.childNodes[1].nodeName).equals("B")
|
||||||
})
|
})
|
||||||
o("creates svg", function() {
|
o("creates svg", function() {
|
||||||
var vnode = {tag: "svg", ns: "http://www.w3.org/2000/svg", children: [{tag: "a", ns: "http://www.w3.org/2000/svg", attrs: {"xlink:href": "javascript:;"}}]}
|
var vnode = {tag: "svg", ns: "http://www.w3.org/2000/svg", children: [
|
||||||
|
{tag: "a", ns: "http://www.w3.org/2000/svg", attrs: {"xlink:href": "javascript:;"}},
|
||||||
|
{tag: "foreignObject", children: [{tag: "body", attrs: {xmlns: "http://www.w3.org/1999/xhtml"}}]}
|
||||||
|
]}
|
||||||
render(root, [vnode])
|
render(root, [vnode])
|
||||||
|
|
||||||
o(vnode.dom.nodeName).equals("svg")
|
o(vnode.dom.nodeName).equals("svg")
|
||||||
|
|
@ -64,6 +67,9 @@ o.spec("createElement", function() {
|
||||||
o(vnode.dom.firstChild.namespaceURI).equals("http://www.w3.org/2000/svg")
|
o(vnode.dom.firstChild.namespaceURI).equals("http://www.w3.org/2000/svg")
|
||||||
o(vnode.dom.firstChild.attributes["href"].nodeValue).equals("javascript:;")
|
o(vnode.dom.firstChild.attributes["href"].nodeValue).equals("javascript:;")
|
||||||
o(vnode.dom.firstChild.attributes["href"].namespaceURI).equals("http://www.w3.org/1999/xlink")
|
o(vnode.dom.firstChild.attributes["href"].namespaceURI).equals("http://www.w3.org/1999/xlink")
|
||||||
|
o(vnode.dom.childNodes[1].nodeName).equals("foreignObject")
|
||||||
|
o(vnode.dom.childNodes[1].firstChild.nodeName).equals("body")
|
||||||
|
o(vnode.dom.childNodes[1].firstChild.namespaceURI).equals("http://www.w3.org/1999/xhtml")
|
||||||
})
|
})
|
||||||
o("sets attributes correctly for svg", function() {
|
o("sets attributes correctly for svg", function() {
|
||||||
var vnode = {tag: "svg", ns: "http://www.w3.org/2000/svg", attrs: {viewBox: "0 0 100 100"}}
|
var vnode = {tag: "svg", ns: "http://www.w3.org/2000/svg", attrs: {viewBox: "0 0 100 100"}}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue