From 16faf2159dbc4dd6191e03595280e5e3575f48e1 Mon Sep 17 00:00:00 2001 From: Leo Horie Date: Sun, 21 Sep 2014 14:49:00 -0400 Subject: [PATCH] add docs in setAttributes --- mithril.js | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/mithril.js b/mithril.js index 202eee21..015d706f 100644 --- a/mithril.js +++ b/mithril.js @@ -275,13 +275,17 @@ Mithril = m = new function app(window, undefined) { for (var attrName in dataAttrs) { var dataAttr = dataAttrs[attrName] var cachedAttr = cachedAttrs[attrName] + //see #29 for the reason behind `activeElement` usage if (!(attrName in cachedAttrs) || (cachedAttr !== dataAttr) || node === window.document.activeElement) { cachedAttrs[attrName] = dataAttr try { + //`config` isn't a real attributes, so ignore it if (attrName === "config") continue + //hook event handlers to the auto-redrawing system else if (typeof dataAttr == "function" && attrName.indexOf("on") == 0) { node[attrName] = autoredraw(dataAttr, node) } + //handle `style: {...}` else if (attrName === "style" && typeof dataAttr == "object") { for (var rule in dataAttr) { if (cachedAttr == null || cachedAttr[rule] !== dataAttr[rule]) node.style[rule] = dataAttr[rule] @@ -290,14 +294,19 @@ Mithril = m = new function app(window, undefined) { if (!(rule in dataAttr)) node.style[rule] = "" } } + //handle SVG else if (namespace != null) { if (attrName === "href") node.setAttributeNS("http://www.w3.org/1999/xlink", "href", dataAttr) else if (attrName === "className") node.setAttribute("class", dataAttr) else node.setAttribute(attrName, dataAttr) } + //part of fix for #29 else if (attrName === "value" && tag === "input") { if (node.value !== dataAttr) node.value = dataAttr } + //handle cases that are properties (but ignore cases where we should use setAttribute instead) + //- list and form are typically used as strings, but are DOM element references in js + //- when using CSS selectors (e.g. `m("[style='']")`), style is used as a string, but it's an object in js else if (attrName in node && !(attrName == "list" || attrName == "style" || attrName == "form")) { node[attrName] = dataAttr }