Runtime-deprecate ospec, change change-log to changelog, fix a few assorted bugs (#2578)
This commit is contained in:
parent
1630b06106
commit
9f0dc2ab46
76 changed files with 484 additions and 410 deletions
|
|
@ -726,12 +726,18 @@ module.exports = function($window) {
|
|||
|
||||
//attrs
|
||||
function setAttrs(vnode, attrs, ns) {
|
||||
// If you assign an input type that is not supported by IE 11 with an assignment expression, an error will occur.
|
||||
//
|
||||
// Also, the DOM does things to inputs based on the value, so it needs set first.
|
||||
// See: https://github.com/MithrilJS/mithril.js/issues/2622
|
||||
if (vnode.tag === "input" && attrs.type != null) vnode.dom.setAttribute("type", attrs.type)
|
||||
var isFileInput = attrs != null && vnode.tag === "input" && attrs.type === "file"
|
||||
for (var key in attrs) {
|
||||
setAttr(vnode, key, null, attrs[key], ns)
|
||||
setAttr(vnode, key, null, attrs[key], ns, isFileInput)
|
||||
}
|
||||
}
|
||||
function setAttr(vnode, key, old, value, ns) {
|
||||
if (key === "key" || key === "is" || value == null || isLifecycleMethod(key) || (old === value && !isFormAttribute(vnode, key)) && typeof value !== "object") return
|
||||
function setAttr(vnode, key, old, value, ns, isFileInput) {
|
||||
if (key === "key" || key === "is" || value == null || isLifecycleMethod(key) || (old === value && !isFormAttribute(vnode, key)) && typeof value !== "object" || key === "type" && vnode.tag === "input") return
|
||||
if (key[0] === "o" && key[1] === "n") return updateEvent(vnode, key, value)
|
||||
if (key.slice(0, 6) === "xlink:") vnode.dom.setAttributeNS("http://www.w3.org/1999/xlink", key.slice(6), value)
|
||||
else if (key === "style") updateStyle(vnode.dom, old, value)
|
||||
|
|
@ -740,16 +746,18 @@ module.exports = function($window) {
|
|||
// Only do the coercion if we're actually going to check the value.
|
||||
/* eslint-disable no-implicit-coercion */
|
||||
//setting input[value] to same value by typing on focused element moves cursor to end in Chrome
|
||||
if ((vnode.tag === "input" || vnode.tag === "textarea") && vnode.dom.value === "" + value && vnode.dom === activeElement()) return
|
||||
//setting input[type=file][value] to same value causes an error to be generated if it's non-empty
|
||||
if ((vnode.tag === "input" || vnode.tag === "textarea") && vnode.dom.value === "" + value && (isFileInput || vnode.dom === activeElement())) return
|
||||
//setting select[value] to same value while having select open blinks select dropdown in Chrome
|
||||
if (vnode.tag === "select" && old !== null && vnode.dom.value === "" + value) return
|
||||
//setting option[value] to same value while having select open blinks select dropdown in Chrome
|
||||
if (vnode.tag === "option" && old !== null && vnode.dom.value === "" + value) return
|
||||
//setting input[type=file][value] to different value is an error if it's non-empty
|
||||
// Not ideal, but it at least works around the most common source of uncaught exceptions for now.
|
||||
if (isFileInput && "" + value !== "") { console.error("`value` is read-only on file inputs!"); return }
|
||||
/* eslint-enable no-implicit-coercion */
|
||||
}
|
||||
// If you assign an input type that is not supported by IE 11 with an assignment expression, an error will occur.
|
||||
if (vnode.tag === "input" && key === "type") vnode.dom.setAttribute(key, value)
|
||||
else vnode.dom[key] = value
|
||||
vnode.dom[key] = value
|
||||
} else {
|
||||
if (typeof value === "boolean") {
|
||||
if (value) vnode.dom.setAttribute(key, "")
|
||||
|
|
@ -793,8 +801,14 @@ module.exports = function($window) {
|
|||
}
|
||||
function updateAttrs(vnode, old, attrs, ns) {
|
||||
if (attrs != null) {
|
||||
// If you assign an input type that is not supported by IE 11 with an assignment expression, an error will occur.
|
||||
//
|
||||
// Also, the DOM does things to inputs based on the value, so it needs set first.
|
||||
// See: https://github.com/MithrilJS/mithril.js/issues/2622
|
||||
if (vnode.tag === "input" && attrs.type != null) vnode.dom.setAttribute("type", attrs.type)
|
||||
var isFileInput = vnode.tag === "input" && attrs.type === "file"
|
||||
for (var key in attrs) {
|
||||
setAttr(vnode, key, old && old[key], attrs[key], ns)
|
||||
setAttr(vnode, key, old && old[key], attrs[key], ns, isFileInput)
|
||||
}
|
||||
}
|
||||
var val
|
||||
|
|
@ -897,6 +911,7 @@ module.exports = function($window) {
|
|||
//event
|
||||
function updateEvent(vnode, key, value) {
|
||||
if (vnode.events != null) {
|
||||
vnode.events._ = currentRedraw
|
||||
if (vnode.events[key] === value) return
|
||||
if (value != null && (typeof value === "function" || typeof value === "object")) {
|
||||
if (vnode.events[key] == null) vnode.dom.addEventListener(key.slice(2), vnode.events, false)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue