fix class/className concat bug when they're defined in both selector and attrs
This commit is contained in:
parent
4163b11fde
commit
dd9d9c1da8
1 changed files with 11 additions and 16 deletions
27
mithril.js
27
mithril.js
|
|
@ -1,5 +1,4 @@
|
||||||
Mithril = m = new function app(window) {
|
Mithril = m = new function app(window) {
|
||||||
var selectorCache = {}
|
|
||||||
var type = {}.toString
|
var type = {}.toString
|
||||||
var parser = /(?:(^|#|\.)([^#\.\[\]]+))|(\[.+?\])/g, attrParser = /\[(.+?)(?:=("|'|)(.*?)\2)?\]/
|
var parser = /(?:(^|#|\.)([^#\.\[\]]+))|(\[.+?\])/g, attrParser = /\[(.+?)(?:=("|'|)(.*?)\2)?\]/
|
||||||
|
|
||||||
|
|
@ -8,23 +7,19 @@ Mithril = m = new function app(window) {
|
||||||
var hasAttrs = type.call(args[1]) == "[object Object]" && !("tag" in args[1]) && !("subtree" in args[1])
|
var hasAttrs = type.call(args[1]) == "[object Object]" && !("tag" in args[1]) && !("subtree" in args[1])
|
||||||
var attrs = hasAttrs ? args[1] : {}
|
var attrs = hasAttrs ? args[1] : {}
|
||||||
var classAttrName = "class" in attrs ? "class" : "className"
|
var classAttrName = "class" in attrs ? "class" : "className"
|
||||||
var cell = selectorCache[args[0]]
|
var cell = {tag: "div", attrs: {}}
|
||||||
if (cell === undefined) {
|
var match, classes = []
|
||||||
selectorCache[args[0]] = cell = {tag: "div", attrs: {}}
|
while (match = parser.exec(args[0])) {
|
||||||
var match, classes = []
|
if (match[1] == "") cell.tag = match[2]
|
||||||
while (match = parser.exec(args[0])) {
|
else if (match[1] == "#") cell.attrs.id = match[2]
|
||||||
if (match[1] == "") cell.tag = match[2]
|
else if (match[1] == ".") classes.push(match[2])
|
||||||
else if (match[1] == "#") cell.attrs.id = match[2]
|
else if (match[3][0] == "[") {
|
||||||
else if (match[1] == ".") classes.push(match[2])
|
var pair = attrParser.exec(match[3])
|
||||||
else if (match[3][0] == "[") {
|
cell.attrs[pair[1]] = pair[3] || (pair[2] ? "" :true)
|
||||||
var pair = attrParser.exec(match[3])
|
|
||||||
cell.attrs[pair[1]] = pair[3] || (pair[2] ? "" :true)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if (classes.length > 0) cell.attrs[classAttrName] = classes.join(" ")
|
|
||||||
}
|
}
|
||||||
cell = clone(cell)
|
if (classes.length > 0) cell.attrs[classAttrName] = classes.join(" ")
|
||||||
cell.attrs = clone(cell.attrs)
|
|
||||||
cell.children = hasAttrs ? args[2] : args[1]
|
cell.children = hasAttrs ? args[2] : args[1]
|
||||||
for (var attrName in attrs) {
|
for (var attrName in attrs) {
|
||||||
if (attrName == classAttrName) cell.attrs[attrName] = (cell.attrs[attrName] || "") + " " + attrs[attrName]
|
if (attrName == classAttrName) cell.attrs[attrName] = (cell.attrs[attrName] || "") + " " + attrs[attrName]
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue