add docs in setAttributes
This commit is contained in:
parent
57e9e1557e
commit
16faf2159d
1 changed files with 9 additions and 0 deletions
|
|
@ -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
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue