From 12bd7dd7703d173682634cdb65eba7c468c02e73 Mon Sep 17 00:00:00 2001 From: Matt Kaemmerer Date: Mon, 17 Oct 2016 13:09:59 -0500 Subject: [PATCH] Call setAttributeNS instead of setAttribute for keys with a known namespace --- modules/attributes.js | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/modules/attributes.js b/modules/attributes.js index 9a50259..7456277 100644 --- a/modules/attributes.js +++ b/modules/attributes.js @@ -1,3 +1,7 @@ +var NamespaceURIs = { + "xlink": "http://www.w3.org/1999/xlink" +}; + var booleanAttrs = ["allowfullscreen", "async", "autofocus", "autoplay", "checked", "compact", "controls", "declare", "default", "defaultchecked", "defaultmuted", "defaultselected", "defer", "disabled", "draggable", "enabled", "formnovalidate", "hidden", "indeterminate", "inert", "ismap", "itemscope", "loop", "multiple", @@ -12,7 +16,7 @@ for(var i=0, len = booleanAttrs.length; i < len; i++) { function updateAttrs(oldVnode, vnode) { var key, cur, old, elm = vnode.elm, - oldAttrs = oldVnode.data.attrs, attrs = vnode.data.attrs; + oldAttrs = oldVnode.data.attrs, attrs = vnode.data.attrs, namespace; if (!oldAttrs && !attrs) return; oldAttrs = oldAttrs || {}; @@ -22,10 +26,12 @@ function updateAttrs(oldVnode, vnode) { for (key in attrs) { cur = attrs[key]; old = oldAttrs[key]; + namespace = key.split(":")[0]; if (old !== cur) { - // TODO: add support to namespaced attributes (setAttributeNS) if(!cur && booleanAttrsDict[key]) elm.removeAttribute(key); + else if(key.match(/:/) && NamespaceURIs.hasOwnProperty(namespace)) + elm.setAttributeNS(NamespaceURIs[namespace], key, cur); else elm.setAttribute(key, cur); }