|
@@ -10,18 +10,19 @@ const isBooleanAttr = makeMap(
|
|
|
'truespeed,typemustmatch,visible'
|
|
'truespeed,typemustmatch,visible'
|
|
|
)
|
|
)
|
|
|
|
|
|
|
|
|
|
+const xlinkNS = 'http://www.w3.org/1999/xlink'
|
|
|
|
|
+const isXlink = name => name.slice(0, 6) === 'xlink:'
|
|
|
|
|
+
|
|
|
function updateAttrs (oldVnode, vnode) {
|
|
function updateAttrs (oldVnode, vnode) {
|
|
|
let key, cur, old
|
|
let key, cur, old
|
|
|
const elm = vnode.elm
|
|
const elm = vnode.elm
|
|
|
const oldAttrs = oldVnode.data.attrs || {}
|
|
const oldAttrs = oldVnode.data.attrs || {}
|
|
|
const attrs = vnode.data.attrs || {}
|
|
const attrs = vnode.data.attrs || {}
|
|
|
|
|
|
|
|
- // update modified attributes, add new attributes
|
|
|
|
|
for (key in attrs) {
|
|
for (key in attrs) {
|
|
|
cur = attrs[key]
|
|
cur = attrs[key]
|
|
|
old = oldAttrs[key]
|
|
old = oldAttrs[key]
|
|
|
if (old !== cur) {
|
|
if (old !== cur) {
|
|
|
- // TODO: add support to namespaced attributes (setAttributeNS)
|
|
|
|
|
if (isBooleanAttr(key)) {
|
|
if (isBooleanAttr(key)) {
|
|
|
if (cur == null) {
|
|
if (cur == null) {
|
|
|
elm.removeAttribute(key)
|
|
elm.removeAttribute(key)
|
|
@@ -30,17 +31,20 @@ function updateAttrs (oldVnode, vnode) {
|
|
|
}
|
|
}
|
|
|
} else if (isEnumeratedAttr(key)) {
|
|
} else if (isEnumeratedAttr(key)) {
|
|
|
elm.setAttribute(key, cur == null ? 'false' : 'true')
|
|
elm.setAttribute(key, cur == null ? 'false' : 'true')
|
|
|
|
|
+ } else if (isXlink(key)) {
|
|
|
|
|
+ elm.setAttributeNS(xlinkNS, key, cur)
|
|
|
} else {
|
|
} else {
|
|
|
elm.setAttribute(key, cur)
|
|
elm.setAttribute(key, cur)
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
- // remove removed attributes
|
|
|
|
|
- // use `in` operator since the previous `for` iteration uses it (.i.e. add even attributes with undefined value)
|
|
|
|
|
- // the other option is to remove all attributes with value == undefined
|
|
|
|
|
for (key in oldAttrs) {
|
|
for (key in oldAttrs) {
|
|
|
if (attrs[key] == null) {
|
|
if (attrs[key] == null) {
|
|
|
- elm.removeAttribute(key)
|
|
|
|
|
|
|
+ if (isXlink(key)) {
|
|
|
|
|
+ elm.removeAttributeNS(xlinkNS, key)
|
|
|
|
|
+ } else {
|
|
|
|
|
+ elm.removeAttribute(key)
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|