Rewrite most of the last commit of #887 (without the m.request bug)
This commit is contained in:
parent
c6fc86f728
commit
1b4737b0c6
3 changed files with 14 additions and 15 deletions
25
mithril.js
25
mithril.js
|
|
@ -1145,7 +1145,7 @@
|
||||||
// used as a string, but it's an object in js
|
// used as a string, but it's an object in js
|
||||||
//
|
//
|
||||||
// #348
|
// #348
|
||||||
// don't set the value if not needed otherwise cursor placement
|
// don't set the value if not needed, otherwise cursor placement
|
||||||
// breaks in Chrome
|
// breaks in Chrome
|
||||||
if (tag !== "input" || node[attr] !== dataAttr) {
|
if (tag !== "input" || node[attr] !== dataAttr) {
|
||||||
node[attr] = dataAttr
|
node[attr] = dataAttr
|
||||||
|
|
@ -1161,7 +1161,7 @@
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
// swallow IE's invalid argument errors to mimic HTML's
|
// swallow IE's invalid argument errors to mimic HTML's
|
||||||
// fallback-to-doing-nothing-on-invalid-attributes behavior
|
// fallback-to-doing-nothing-on-invalid-attributes behavior
|
||||||
if (e.message.indexOf("Invalid argument") < 0) throw e
|
if (/\bInvalid argument\b/.test(e.message)) throw e
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1173,7 +1173,7 @@
|
||||||
trySetSingle(attr, dataAttr, cachedAttr, node, namespace, tag)
|
trySetSingle(attr, dataAttr, cachedAttr, node, namespace, tag)
|
||||||
} else if (attr === "value" && tag === "input" &&
|
} else if (attr === "value" && tag === "input" &&
|
||||||
// #348: dataAttr may not be a string, so use loose
|
// #348: dataAttr may not be a string, so use loose
|
||||||
// comparison
|
// comparison (i.e. identity not required).
|
||||||
node.value != dataAttr) { // eslint-disable-line eqeqeq
|
node.value != dataAttr) { // eslint-disable-line eqeqeq
|
||||||
node.value = dataAttr
|
node.value = dataAttr
|
||||||
}
|
}
|
||||||
|
|
@ -1454,7 +1454,7 @@
|
||||||
var lastRedrawCallTime = 0
|
var lastRedrawCallTime = 0
|
||||||
|
|
||||||
function actuallyPerformRedraw() {
|
function actuallyPerformRedraw() {
|
||||||
if (lastRedrawId > 0) $cancelAnimationFrame(lastRedrawId)
|
if (lastRedrawId !== 0) $cancelAnimationFrame(lastRedrawId)
|
||||||
lastRedrawId = $requestAnimationFrame(redraw, FRAME_BUDGET)
|
lastRedrawId = $requestAnimationFrame(redraw, FRAME_BUDGET)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1816,7 +1816,7 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
function parseQueryString(str) {
|
function parseQueryString(str) {
|
||||||
if (str === "" || str == null) return {}
|
if (!str) return {}
|
||||||
if (str[0] === "?") str = str.slice(1)
|
if (str[0] === "?") str = str.slice(1)
|
||||||
|
|
||||||
var pairs = str.split("&")
|
var pairs = str.split("&")
|
||||||
|
|
@ -2122,7 +2122,7 @@
|
||||||
|
|
||||||
script.src = options.url +
|
script.src = options.url +
|
||||||
(options.url.indexOf("?") > 0 ? "&" : "?") +
|
(options.url.indexOf("?") > 0 ? "&" : "?") +
|
||||||
(options.callbackKey ? options.callbackKey : "callback") +
|
(options.callbackKey || "callback") +
|
||||||
"=" + callbackKey +
|
"=" + callbackKey +
|
||||||
"&" + buildQueryString(options.data || {})
|
"&" + buildQueryString(options.data || {})
|
||||||
|
|
||||||
|
|
@ -2169,7 +2169,7 @@
|
||||||
data = options.data
|
data = options.data
|
||||||
}
|
}
|
||||||
|
|
||||||
if (data && !isString(data) && data.constructor !== window.FormData) {
|
if (data && !isString(data) && !(data instanceof window.FormData)) {
|
||||||
throw new Error("Request data should be either be a string or " +
|
throw new Error("Request data should be either be a string or " +
|
||||||
"FormData. Check the `serialize` option in `m.request`")
|
"FormData. Check the `serialize` option in `m.request`")
|
||||||
}
|
}
|
||||||
|
|
@ -2179,7 +2179,7 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
function ajax(options) {
|
function ajax(options) {
|
||||||
if (options.dataType && options.dataType.toLowerCase() === "jsonp") {
|
if (options.dataType && options.dataType.toUpperCase() === "JSONP") {
|
||||||
return getJsonp(options)
|
return getJsonp(options)
|
||||||
} else {
|
} else {
|
||||||
return runXhr(options)
|
return runXhr(options)
|
||||||
|
|
@ -2221,15 +2221,14 @@
|
||||||
return jsonp.responseText
|
return jsonp.responseText
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!options.dataType || options.dataType.toLowerCase() !== "jsonp") {
|
if (!options.dataType || options.dataType.toUpperCase() !== "JSONP") {
|
||||||
serialize = options.serialize || JSON.stringify
|
serialize = options.serialize || JSON.stringify
|
||||||
deserialize = options.deserialize || JSON.parse
|
deserialize = options.deserialize || JSON.parse
|
||||||
extract = options.extract || function (xhr) {
|
extract = options.extract || function (xhr) {
|
||||||
if (xhr.responseText.length === 0 &&
|
if (xhr.responseText.length || deserialize !== JSON.parse) {
|
||||||
deserialize === JSON.parse) {
|
|
||||||
return null
|
|
||||||
} else {
|
|
||||||
return xhr.responseText
|
return xhr.responseText
|
||||||
|
} else {
|
||||||
|
return null
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
2
mithril.min.js
vendored
2
mithril.min.js
vendored
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
Loading…
Add table
Add a link
Reference in a new issue