mimic html fallback-to-doing-nothing-on-invalid-attributes behavior in IE8, instead of throwing non-helpful "Invalid argument." error

This commit is contained in:
Leo Horie 2014-09-04 22:10:14 -04:00
parent 8285b903d6
commit 0ee2d7f200

View file

@ -277,6 +277,7 @@ Mithril = m = new function app(window, undefined) {
var cachedAttr = cachedAttrs[attrName] var cachedAttr = cachedAttrs[attrName]
if (!(attrName in cachedAttrs) || (cachedAttr !== dataAttr) || node === window.document.activeElement) { if (!(attrName in cachedAttrs) || (cachedAttr !== dataAttr) || node === window.document.activeElement) {
cachedAttrs[attrName] = dataAttr cachedAttrs[attrName] = dataAttr
try {
if (attrName === "config") continue if (attrName === "config") continue
else if (typeof dataAttr == "function" && attrName.indexOf("on") == 0) { else if (typeof dataAttr == "function" && attrName.indexOf("on") == 0) {
node[attrName] = autoredraw(dataAttr, node) node[attrName] = autoredraw(dataAttr, node)
@ -302,6 +303,11 @@ Mithril = m = new function app(window, undefined) {
} }
else node.setAttribute(attrName, dataAttr) else node.setAttribute(attrName, dataAttr)
} }
catch (e) {
//swallow IE's invalid argument errors to mimic HTML's fallback-to-doing-nothing-on-invalid-attributes behavior
if (e.message.indexOf("Invalid argument") < 0) throw e
}
}
} }
return cachedAttrs return cachedAttrs
} }