fix input cursor bug in chrome
This commit is contained in:
parent
ed66e5d67a
commit
22deb93d04
65 changed files with 7237 additions and 26 deletions
39
mithril.js
39
mithril.js
|
|
@ -32,7 +32,7 @@ Mithril = m = new function app(window) {
|
|||
}
|
||||
return cell
|
||||
}
|
||||
function build(parent, data, cached, shouldReattach, index, namespace) {
|
||||
function build(parentElement, parentTag, data, cached, shouldReattach, index, namespace) {
|
||||
if (data === null || data === undefined) {
|
||||
if (cached) clear(cached.nodes)
|
||||
return
|
||||
|
|
@ -49,7 +49,7 @@ Mithril = m = new function app(window) {
|
|||
if (dataType == "[object Array]") {
|
||||
var nodes = [], intact = cached.length === data.length, subArrayCount = 0
|
||||
for (var i = 0, cacheCount = 0; i < data.length; i++) {
|
||||
var item = build(parent, data[i], cached[cacheCount], shouldReattach, index + subArrayCount || subArrayCount, namespace)
|
||||
var item = build(parentElement, null, data[i], cached[cacheCount], shouldReattach, index + subArrayCount || subArrayCount, namespace)
|
||||
if (item === undefined) continue
|
||||
if (!item.nodes.intact) intact = false
|
||||
subArrayCount += item instanceof Array ? item.length : 1
|
||||
|
|
@ -58,7 +58,7 @@ Mithril = m = new function app(window) {
|
|||
if (!intact) {
|
||||
for (var i = 0; i < data.length; i++) if (cached[i] !== undefined) nodes = nodes.concat(cached[i].nodes)
|
||||
for (var i = nodes.length, node; node = cached.nodes[i]; i++) if (node.parentNode !== null) node.parentNode.removeChild(node)
|
||||
for (var i = cached.nodes.length, node; node = nodes[i]; i++) if (node.parentNode === null) parent.appendChild(node)
|
||||
for (var i = cached.nodes.length, node; node = nodes[i]; i++) if (node.parentNode === null) parentElement.appendChild(node)
|
||||
if (data.length < cached.length) cached.length = data.length
|
||||
cached.nodes = nodes
|
||||
}
|
||||
|
|
@ -74,17 +74,17 @@ Mithril = m = new function app(window) {
|
|||
cached = {
|
||||
tag: data.tag,
|
||||
attrs: setAttributes(node, data.tag, data.attrs, {}, namespace),
|
||||
children: build(node, data.children, cached.children, true, 0, namespace),
|
||||
children: build(node, data.tag, data.children, cached.children, true, 0, namespace),
|
||||
nodes: [node]
|
||||
}
|
||||
parent.insertBefore(node, parent.childNodes[index] || null)
|
||||
parentElement.insertBefore(node, parentElement.childNodes[index] || null)
|
||||
}
|
||||
else {
|
||||
node = cached.nodes[0]
|
||||
setAttributes(node, data.tag, data.attrs, cached.attrs, namespace)
|
||||
cached.children = build(node, data.children, cached.children, false, 0, namespace)
|
||||
cached.children = build(node, data.tag, data.children, cached.children, false, 0, namespace)
|
||||
cached.nodes.intact = true
|
||||
if (shouldReattach === true) parent.insertBefore(node, parent.childNodes[index] || null)
|
||||
if (shouldReattach === true) parentElement.insertBefore(node, parentElement.childNodes[index] || null)
|
||||
}
|
||||
if (type.call(data.attrs["config"]) == "[object Function]") data.attrs["config"](node, !isNew)
|
||||
}
|
||||
|
|
@ -92,11 +92,11 @@ Mithril = m = new function app(window) {
|
|||
var node
|
||||
if (cached.nodes.length === 0) {
|
||||
if (data.$trusted) {
|
||||
node = injectHTML(parent, index, data)
|
||||
node = injectHTML(parentElement, index, data)
|
||||
}
|
||||
else {
|
||||
node = window.document.createTextNode(data)
|
||||
parent.insertBefore(node, parent.childNodes[index] || null)
|
||||
parentElement.insertBefore(node, parentElement.childNodes[index] || null)
|
||||
}
|
||||
cached = "string number boolean".indexOf(typeof data) > -1 ? new data.constructor(data) : data
|
||||
cached.nodes = [node]
|
||||
|
|
@ -107,13 +107,14 @@ Mithril = m = new function app(window) {
|
|||
if (current) {
|
||||
while (current = current.nextSibling) nodes.push(current)
|
||||
clear(nodes)
|
||||
node = injectHTML(parent, index, data)
|
||||
node = injectHTML(parentElement, index, data)
|
||||
}
|
||||
else parent.innerHTML = data
|
||||
else parentElement.innerHTML = data
|
||||
}
|
||||
else {
|
||||
node = cached.nodes[0]
|
||||
parent.insertBefore(node, parent.childNodes[index] || null)
|
||||
if (parentTag === "textarea") parentElement.value = data
|
||||
else parentElement.insertBefore(node, parentElement.childNodes[index] || null)
|
||||
node.nodeValue = data
|
||||
}
|
||||
cached = new data.constructor(data)
|
||||
|
|
@ -145,9 +146,7 @@ Mithril = m = new function app(window) {
|
|||
else node.setAttribute(attrName, dataAttr)
|
||||
}
|
||||
else if (attrName === "value" && tag === "input") {
|
||||
if (node[attrName] !== dataAttr) {
|
||||
node.setAttribute(attrName, dataAttr)
|
||||
}
|
||||
if (node.value !== dataAttr) node.value = dataAttr
|
||||
}
|
||||
else if (attrName in node) node[attrName] = dataAttr
|
||||
else node.setAttribute(attrName, dataAttr)
|
||||
|
|
@ -159,11 +158,11 @@ Mithril = m = new function app(window) {
|
|||
for (var i = 0; i < nodes.length; i++) nodes[i].parentNode.removeChild(nodes[i])
|
||||
nodes.length = 0
|
||||
}
|
||||
function injectHTML(parent, index, data) {
|
||||
var nextSibling = parent.childNodes[index]
|
||||
function injectHTML(parentElement, index, data) {
|
||||
var nextSibling = parentElement.childNodes[index]
|
||||
if (nextSibling) nextSibling.insertAdjacentHTML("beforebegin", data)
|
||||
else parent.insertAdjacentHTML("beforeend", data)
|
||||
return nextSibling ? nextSibling.previousSibling : parent.firstChild
|
||||
else parentElement.insertAdjacentHTML("beforeend", data)
|
||||
return nextSibling ? nextSibling.previousSibling : parentElement.firstChild
|
||||
}
|
||||
function clone(object) {
|
||||
var result = {}
|
||||
|
|
@ -203,7 +202,7 @@ Mithril = m = new function app(window) {
|
|||
var index = nodeCache.indexOf(root)
|
||||
var id = index < 0 ? nodeCache.push(root) - 1 : index
|
||||
var node = root == window.document || root == window.document.documentElement ? documentNode : root
|
||||
cellCache[id] = build(node, cell, cellCache[id], false, 0)
|
||||
cellCache[id] = build(node, null, cell, cellCache[id], false, 0)
|
||||
}
|
||||
|
||||
m.trust = function(value) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue