Comparing version 0.1.13 to 0.1.16
348
mithril.js
@@ -5,6 +5,6 @@ Mithril = m = new function app(window) { | ||
var parser = /(?:(^|#|\.)([^#\.\[\]]+))|(\[.+?\])/g, attrParser = /\[(.+?)(?:=("|'|)(.+?)\2)?\]/ | ||
function m() { | ||
var args = arguments | ||
var hasAttrs = type.call(args[1]) == "[object Object]" | ||
var hasAttrs = type.call(args[1]) == "[object Object]" && !("tag" in args[1]) && !("subtree" in args[1]) | ||
var attrs = hasAttrs ? args[1] : {} | ||
@@ -36,17 +36,68 @@ var classAttrName = "class" in attrs ? "class" : "className" | ||
} | ||
function build(parentElement, parentTag, data, cached, shouldReattach, index, editable, namespace) { | ||
function build(parentElement, parentTag, parentCache, parentIndex, data, cached, shouldReattach, index, editable, namespace, configs) { | ||
if (data === null || data === undefined) data = "" | ||
if (data.subtree === "retain") return | ||
var cachedType = type.call(cached), dataType = type.call(data) | ||
if (cachedType != dataType) { | ||
if (cached !== null && cached !== undefined) clear(cached.nodes) | ||
if (cached !== null && cached !== undefined) { | ||
if (parentCache && parentCache.nodes) { | ||
var offset = index - parentIndex | ||
clear(parentCache.nodes.slice(offset, offset + (dataType == "[object Array]" ? data : cached.nodes).length)) | ||
} | ||
else clear(cached.nodes) | ||
} | ||
cached = new data.constructor | ||
cached.nodes = [] | ||
} | ||
if (dataType == "[object Array]") { | ||
var nodes = [], intact = cached.length === data.length, subArrayCount = 0 | ||
var DELETION = 1, INSERTION = 2 , MOVE = 3 | ||
var existing = {}, shouldMaintainIdentities = false | ||
for (var i = 0; i < cached.length; i++) { | ||
if (cached[i] && cached[i].attrs && cached[i].attrs.key !== undefined) { | ||
shouldMaintainIdentities = true | ||
existing[cached[i].attrs.key] = {action: DELETION, index: i} | ||
} | ||
} | ||
if (shouldMaintainIdentities) { | ||
for (var i = 0; i < data.length; i++) { | ||
if (data[i] && data[i].attrs && data[i].attrs.key !== undefined) { | ||
var key = data[i].attrs.key | ||
if (!existing[key]) existing[key] = {action: INSERTION, index: i} | ||
else existing[key] = {action: MOVE, index: i, from: existing[key].index, element: parentElement.childNodes[existing[key].index]} | ||
} | ||
} | ||
var actions = Object.keys(existing).map(function(key) {return existing[key]}) | ||
var changes = actions.sort(function(a, b) {return a.action - b.action || b.index - a.index}) | ||
var newCached = new Array(cached.length) | ||
for (var i = 0, change; change = changes[i]; i++) { | ||
if (change.action == DELETION) { | ||
clear(cached[change.index].nodes) | ||
newCached.splice(change.index, 1) | ||
} | ||
if (change.action == INSERTION) { | ||
var dummy = window.document.createElement("div") | ||
dummy.key = data[change.index].attrs.key.toString() | ||
parentElement.insertBefore(dummy, parentElement.childNodes[change.index]) | ||
newCached.splice(change.index, 0, {attrs: {key: data[change.index].attrs.key}, nodes: [dummy]}) | ||
} | ||
if (change.action == MOVE) { | ||
if (parentElement.childNodes[change.index] !== change.element) { | ||
parentElement.insertBefore(change.element, parentElement.childNodes[change.index]) | ||
} | ||
newCached[change.index] = cached[change.from] | ||
} | ||
} | ||
cached = newCached | ||
cached.nodes = [] | ||
for (var i = 0, child; child = parentElement.childNodes[i]; i++) cached.nodes.push(child) | ||
} | ||
for (var i = 0, cacheCount = 0; i < data.length; i++) { | ||
var item = build(parentElement, null, data[i], cached[cacheCount], shouldReattach, index + subArrayCount || subArrayCount, editable, namespace) | ||
var item = build(parentElement, parentTag, cached, index, data[i], cached[cacheCount], shouldReattach, index + subArrayCount || subArrayCount, editable, namespace, configs) | ||
if (item === undefined) continue | ||
@@ -58,8 +109,15 @@ if (!item.nodes.intact) intact = false | ||
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) parentElement.appendChild(node) | ||
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.childNodes.length != nodes.length) node.parentNode.removeChild(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 | ||
} | ||
} | ||
@@ -69,5 +127,6 @@ else if (dataType == "[object Object]") { | ||
if (typeof data.tag != "string") return | ||
var node, isNew = cached.nodes.length === 0 | ||
if (data.tag === "svg") namespace = "http://www.w3.org/2000/svg" | ||
if (data.attrs.xmlns) namespace = data.attrs.xmlns | ||
else if (data.tag === "svg") namespace = "http://www.w3.org/2000/svg" | ||
if (isNew) { | ||
@@ -78,3 +137,3 @@ node = namespace === undefined ? window.document.createElement(data.tag) : window.document.createElementNS(namespace, data.tag) | ||
attrs: setAttributes(node, data.tag, data.attrs, {}, namespace), | ||
children: build(node, data.tag, data.children, cached.children, true, 0, data.attrs.contenteditable ? node : editable, namespace), | ||
children: data.children !== undefined ? build(node, data.tag, undefined, undefined, data.children, cached.children, true, 0, data.attrs.contenteditable ? node : editable, namespace, configs) : undefined, | ||
nodes: [node] | ||
@@ -87,39 +146,40 @@ } | ||
setAttributes(node, data.tag, data.attrs, cached.attrs, namespace) | ||
cached.children = build(node, data.tag, data.children, cached.children, false, 0, data.attrs.contenteditable ? node : editable, namespace) | ||
cached.children = build(node, data.tag, undefined, undefined, data.children, cached.children, false, 0, data.attrs.contenteditable ? node : editable, namespace, configs) | ||
cached.nodes.intact = true | ||
if (shouldReattach === true) parentElement.insertBefore(node, parentElement.childNodes[index] || null) | ||
} | ||
if (type.call(data.attrs["config"]) == "[object Function]") data.attrs["config"](node, !isNew) | ||
if (type.call(data.attrs["config"]) == "[object Function]") { | ||
configs.push(data.attrs["config"].bind(window, node, !isNew, cached.configContext = cached.configContext || {})) | ||
} | ||
} | ||
else { | ||
var node | ||
var nodes | ||
if (cached.nodes.length === 0) { | ||
if (data.$trusted) { | ||
node = injectHTML(parentElement, index, data) | ||
nodes = injectHTML(parentElement, index, data) | ||
} | ||
else { | ||
node = window.document.createTextNode(data) | ||
parentElement.insertBefore(node, parentElement.childNodes[index] || null) | ||
nodes = [window.document.createTextNode(data)] | ||
parentElement.insertBefore(nodes[0], parentElement.childNodes[index] || null) | ||
} | ||
cached = "string number boolean".indexOf(typeof data) > -1 ? new data.constructor(data) : data | ||
cached.nodes = [node] | ||
cached.nodes = nodes | ||
} | ||
else if (cached.valueOf() !== data.valueOf() || shouldReattach === true) { | ||
nodes = cached.nodes | ||
if (!editable || editable !== window.document.activeElement) { | ||
if (data.$trusted) { | ||
var current = cached.nodes[0], nodes = [current] | ||
if (current) { | ||
while (current = current.nextSibling) nodes.push(current) | ||
clear(nodes) | ||
node = injectHTML(parentElement, index, data) | ||
} | ||
else parentElement.innerHTML = data | ||
clear(nodes) | ||
nodes = injectHTML(parentElement, index, data) | ||
} | ||
else { | ||
node = cached.nodes[0] | ||
if (parentTag === "textarea") parentElement.value = data | ||
else if (editable) editable.innerHTML = data | ||
else { | ||
parentElement.insertBefore(node, parentElement.childNodes[index] || null) | ||
node.nodeValue = data | ||
if (nodes[0].nodeType == 1 || nodes.length > 1) { //was a trusted string | ||
clear(cached.nodes) | ||
nodes = [window.document.createTextNode(data)] | ||
} | ||
parentElement.insertBefore(nodes[0], parentElement.childNodes[index] || null) | ||
nodes[0].nodeValue = data | ||
} | ||
@@ -129,7 +189,7 @@ } | ||
cached = new data.constructor(data) | ||
cached.nodes = [node] | ||
cached.nodes = nodes | ||
} | ||
else cached.nodes.intact = true | ||
} | ||
return cached | ||
@@ -163,3 +223,5 @@ } | ||
} | ||
else if (attrName in node && !(attrName == "list" || attrName == "style")) node[attrName] = dataAttr | ||
else if (attrName in node && !(attrName == "list" || attrName == "style")) { | ||
node[attrName] = dataAttr | ||
} | ||
else node.setAttribute(attrName, dataAttr) | ||
@@ -171,3 +233,3 @@ } | ||
function clear(nodes) { | ||
for (var i = nodes.length - 1; i > -1; i--) nodes[i].parentNode.removeChild(nodes[i]) | ||
for (var i = nodes.length - 1; i > -1; i--) if (nodes[i] && nodes[i].parentNode) nodes[i].parentNode.removeChild(nodes[i]) | ||
nodes.length = 0 | ||
@@ -177,5 +239,19 @@ } | ||
var nextSibling = parentElement.childNodes[index] | ||
if (nextSibling) nextSibling.insertAdjacentHTML("beforebegin", data) | ||
if (nextSibling) { | ||
var isElement = nextSibling.nodeType != 1 | ||
var placeholder = window.document.createElement("span") | ||
if (isElement) { | ||
parentElement.insertBefore(placeholder, nextSibling) | ||
placeholder.insertAdjacentHTML("beforebegin", data) | ||
parentElement.removeChild(placeholder) | ||
} | ||
else nextSibling.insertAdjacentHTML("beforebegin", data) | ||
} | ||
else parentElement.insertAdjacentHTML("beforeend", data) | ||
return nextSibling ? nextSibling.previousSibling : parentElement.firstChild | ||
var nodes = [] | ||
while (parentElement.childNodes[index] !== nextSibling) { | ||
nodes.push(parentElement.childNodes[index]) | ||
index++ | ||
} | ||
return nodes | ||
} | ||
@@ -189,2 +265,3 @@ function clone(object) { | ||
return function(e) { | ||
e = e || event | ||
m.startComputation() | ||
@@ -195,3 +272,3 @@ try {return callback.call(object, e)} | ||
} | ||
var html | ||
@@ -218,8 +295,11 @@ var documentNode = { | ||
m.render = function(root, cell) { | ||
var configs = [] | ||
if (!root) throw new Error("Please ensure the DOM element exists before rendering a template into it.") | ||
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, null, cell, cellCache[id], false, 0, null, undefined) | ||
cellCache[id] = build(node, null, undefined, undefined, cell, cellCache[id], false, 0, null, undefined, configs) | ||
for (var i = 0; i < configs.length; i++) configs[i]() | ||
} | ||
m.trust = function(value) { | ||
@@ -230,13 +310,21 @@ value = new String(value) | ||
} | ||
var roots = [], modules = [], controllers = [], now = 0, lastRedraw = 0, lastRedrawId = 0, computePostRedrawHook = null | ||
m.module = function(root, module) { | ||
m.startComputation() | ||
var index = roots.indexOf(root) | ||
if (index < 0) index = roots.length | ||
roots[index] = root | ||
modules[index] = module | ||
if (controllers[index] && typeof controllers[index].onunload == "function") controllers[index].onunload() | ||
controllers[index] = new module.controller | ||
m.endComputation() | ||
var isPrevented = false | ||
if (controllers[index] && typeof controllers[index].onunload == "function") { | ||
var event = { | ||
preventDefault: function() {isPrevented = true} | ||
} | ||
controllers[index].onunload(event) | ||
} | ||
if (!isPrevented) { | ||
m.startComputation() | ||
roots[index] = root | ||
modules[index] = module | ||
controllers[index] = new module.controller | ||
m.endComputation() | ||
} | ||
} | ||
@@ -255,3 +343,3 @@ m.redraw = function() { | ||
for (var i = 0; i < roots.length; i++) { | ||
m.render(roots[i], modules[i].view(controllers[i])) | ||
if (controllers[i]) m.render(roots[i], modules[i].view(controllers[i])) | ||
} | ||
@@ -264,3 +352,3 @@ if (computePostRedrawHook) { | ||
} | ||
var pendingRequests = 0 | ||
@@ -272,7 +360,10 @@ m.startComputation = function() {pendingRequests++} | ||
} | ||
m.withAttr = function(prop, withAttrCallback) { | ||
return function(e) {withAttrCallback(prop in e.currentTarget ? e.currentTarget[prop] : e.currentTarget.getAttribute(prop))} | ||
return function(e) { | ||
e = e || event | ||
withAttrCallback(prop in e.currentTarget ? e.currentTarget[prop] : e.currentTarget.getAttribute(prop)) | ||
} | ||
} | ||
//routing | ||
@@ -283,7 +374,6 @@ var modes = {pathname: "", hash: "#", search: "?"} | ||
if (arguments.length === 0) return currentRoute | ||
else if (arguments.length === 3) { | ||
currentRoute = window.location[m.route.mode].slice(modes[m.route.mode].length) | ||
else if (arguments.length === 3 && typeof arguments[1] == "string") { | ||
var root = arguments[0], defaultRoute = arguments[1], router = arguments[2] | ||
redirect = function(source) { | ||
var path = source.slice(modes[m.route.mode].length) | ||
var path = currentRoute = normalizeRoute(source) | ||
if (!routeByValue(root, router, path)) { | ||
@@ -295,6 +385,9 @@ m.route(defaultRoute, true) | ||
window[listener] = function() { | ||
redirect(window.location[m.route.mode]) | ||
if (currentRoute != normalizeRoute(window.location[m.route.mode])) { | ||
redirect(window.location[m.route.mode]) | ||
} | ||
} | ||
computePostRedrawHook = scrollToHash | ||
computePostRedrawHook = setScroll | ||
window[listener]() | ||
currentRoute = normalizeRoute(window.location[m.route.mode]) | ||
} | ||
@@ -305,3 +398,3 @@ else if (arguments[0].addEventListener) { | ||
if (element.href.indexOf(modes[m.route.mode]) < 0) { | ||
element.href = location.pathname + modes[m.route.mode] + element.pathname | ||
element.href = window.location.pathname + modes[m.route.mode] + element.pathname | ||
} | ||
@@ -315,7 +408,11 @@ if (!isInitialized) { | ||
currentRoute = arguments[0] | ||
var shouldReplaceHistoryEntry = arguments[1] === true | ||
var querystring = typeof arguments[1] == "object" ? buildQueryString(arguments[1]) : null | ||
if (querystring) currentRoute += (currentRoute.indexOf("?") === -1 ? "?" : "&") + querystring | ||
var shouldReplaceHistoryEntry = (arguments.length == 3 ? arguments[2] : arguments[1]) === true | ||
if (window.history.pushState) { | ||
computePostRedrawHook = function() { | ||
window.history[shouldReplaceHistoryEntry ? "replaceState" : "pushState"](null, window.document.title, modes[m.route.mode] + currentRoute) | ||
scrollToHash() | ||
setScroll() | ||
} | ||
@@ -329,14 +426,22 @@ redirect(modes[m.route.mode] + currentRoute) | ||
m.route.mode = "search" | ||
function normalizeRoute(route) {return route.slice(modes[m.route.mode].length)} | ||
function routeByValue(root, router, path) { | ||
routeParams = {} | ||
var queryStart = path.indexOf("?") | ||
if (queryStart !== -1) { | ||
routeParams = parseQueryString(path.substr(queryStart + 1, path.length)) | ||
path = path.substr(0, queryStart) | ||
} | ||
for (var route in router) { | ||
if (route == path) return !void m.module(root, router[route]) | ||
var matcher = new RegExp("^" + route.replace(/:[^\/]+?\.{3}/g, "(.*?)").replace(/:[^\/]+/g, "([^\\/]+)") + "$") | ||
var matcher = new RegExp("^" + route.replace(/:[^\/]+?\.{3}/g, "(.*?)").replace(/:[^\/]+/g, "([^\\/]+)") + "\/?$") | ||
if (matcher.test(path)) { | ||
return !void path.replace(matcher, function() { | ||
var keys = route.match(/:[^\/]+/g) | ||
var keys = route.match(/:[^\/]+/g) || [] | ||
var values = [].slice.call(arguments, 1, -2) | ||
for (var i = 0; i < keys.length; i++) routeParams[keys[i].replace(/:|\./g, "")] = decodeURIComponent(values[i]) | ||
for (var i = 0; i < keys.length; i++) routeParams[keys[i].replace(/:|\./g, "")] = decodeSpace(values[i]) | ||
m.module(root, router[route]) | ||
@@ -348,2 +453,3 @@ }) | ||
function routeUnobtrusive(e) { | ||
e = e || event | ||
if (e.ctrlKey || e.metaKey || e.which == 2) return | ||
@@ -353,6 +459,26 @@ e.preventDefault() | ||
} | ||
function scrollToHash() { | ||
function setScroll() { | ||
if (m.route.mode != "hash" && window.location.hash) window.location.hash = window.location.hash | ||
else window.scrollTo(0, 0) | ||
} | ||
function buildQueryString(object, prefix) { | ||
var str = [] | ||
for(var prop in object) { | ||
var key = prefix ? prefix + "[" + prop + "]" : prop, value = object[prop] | ||
str.push(typeof value == "object" ? buildQueryString(value, key) : encodeURIComponent(key) + "=" + encodeURIComponent(value)) | ||
} | ||
return str.join("&") | ||
} | ||
function parseQueryString(str) { | ||
var pairs = str.split("&"), params = {} | ||
for (var i = 0; i < pairs.length; i++) { | ||
var pair = pairs[i].split("=") | ||
params[decodeSpace(pair[0])] = pair[1] ? decodeSpace(pair[1]) : (pair.length === 1 ? true : "") | ||
} | ||
return params | ||
} | ||
function decodeSpace(string) { | ||
return decodeURIComponent(string.replace(/\+/g, " ")) | ||
} | ||
//model | ||
@@ -370,7 +496,8 @@ m.prop = function(store) { | ||
var none = {} | ||
m.deferred = function() { | ||
var resolvers = [], rejecters = [], resolved, rejected | ||
var resolvers = [], rejecters = [], resolved = none, rejected = none, promise = m.prop() | ||
var object = { | ||
resolve: function(value) { | ||
if (resolved === undefined) resolved = value | ||
if (resolved === none) promise(resolved = value) | ||
for (var i = 0; i < resolvers.length; i++) resolvers[i](value) | ||
@@ -380,7 +507,7 @@ resolvers.length = rejecters.length = 0 | ||
reject: function(value) { | ||
if (rejected === undefined) rejected = value | ||
if (rejected === none) rejected = value | ||
for (var i = 0; i < rejecters.length; i++) rejecters[i](value) | ||
resolvers.length = rejecters.length = 0 | ||
}, | ||
promise: m.prop() | ||
promise: promise | ||
} | ||
@@ -405,4 +532,4 @@ object.promise.resolvers = resolvers | ||
} | ||
if (resolved !== undefined) callback("resolve", success)(resolved) | ||
else if (rejected !== undefined) callback("reject", error)(rejected) | ||
if (resolved !== none) callback("resolve", success)(resolved) | ||
else if (rejected !== none) callback("reject", error)(rejected) | ||
else { | ||
@@ -418,7 +545,7 @@ resolvers.push(callback("resolve", success)) | ||
var method = "resolve" | ||
function synchronizer(resolved) { | ||
function synchronizer(pos, resolved) { | ||
return function(value) { | ||
results.push(value) | ||
results[pos] = value | ||
if (!resolved) method = "reject" | ||
if (results.length == args.length) { | ||
if (--outstanding == 0) { | ||
deferred.promise(results) | ||
@@ -430,7 +557,8 @@ deferred[method](results) | ||
} | ||
var deferred = m.deferred() | ||
var results = [] | ||
var outstanding = args.length | ||
var results = new Array(outstanding) | ||
for (var i = 0; i < args.length; i++) { | ||
args[i].then(synchronizer(true), synchronizer(false)) | ||
args[i].then(synchronizer(i, true), synchronizer(i, false)) | ||
} | ||
@@ -442,27 +570,21 @@ return deferred.promise | ||
function ajax(options) { | ||
var xhr = window.XDomainRequest ? new window.XDomainRequest : new window.XMLHttpRequest | ||
var xhr = new window.XMLHttpRequest | ||
xhr.open(options.method, options.url, true, options.user, options.password) | ||
xhr.onload = typeof options.onload == "function" ? options.onload : function() {} | ||
xhr.onerror = typeof options.onerror == "function" ? options.onerror : function() {} | ||
xhr.onreadystatechange = function() { | ||
if (xhr.readyState === 4 && xhr.status === 0) { | ||
xhr.onerror({type: "error", target: xhr}) | ||
if (xhr.readyState === 4) { | ||
if (xhr.status >= 200 && xhr.status < 300) options.onload({type: "load", target: xhr}) | ||
else options.onerror({type: "error", target: xhr}) | ||
} | ||
} | ||
if (typeof options.config == "function") options.config(xhr, options) | ||
if (typeof options.config == "function") { | ||
var maybeXhr = options.config(xhr, options) | ||
if (maybeXhr !== undefined) xhr = maybeXhr | ||
} | ||
xhr.send(options.data) | ||
return xhr | ||
} | ||
function querystring(object, prefix) { | ||
var str = [] | ||
for(var prop in object) { | ||
var key = prefix ? prefix + "[" + prop + "]" : prop, value = object[prop] | ||
str.push(typeof value == "object" ? querystring(value, key) : encodeURIComponent(key) + "=" + encodeURIComponent(value)) | ||
} | ||
return str.join("&") | ||
} | ||
function bindData(xhrOptions, data, serialize) { | ||
if (data && Object.keys(data).length > 0) { | ||
if (xhrOptions.method == "GET") { | ||
xhrOptions.url = xhrOptions.url + (xhrOptions.url.indexOf("?") < 0 ? "?" : "&") + querystring(data) | ||
xhrOptions.url = xhrOptions.url + (xhrOptions.url.indexOf("?") < 0 ? "?" : "&") + buildQueryString(data) | ||
} | ||
@@ -496,25 +618,25 @@ else xhrOptions.data = serialize(data) | ||
xhrOptions.onload = xhrOptions.onerror = function(e) { | ||
var unwrap = (e.type == "load" ? xhrOptions.unwrapSuccess : xhrOptions.unwrapError) || identity | ||
var response = unwrap(deserialize(extract(e.target, xhrOptions))) | ||
if (response instanceof Array && xhrOptions.type) { | ||
for (var i = 0; i < response.length; i++) response[i] = new xhrOptions.type(response[i]) | ||
try { | ||
e = e || event | ||
var unwrap = (e.type == "load" ? xhrOptions.unwrapSuccess : xhrOptions.unwrapError) || identity | ||
var response = unwrap(deserialize(extract(e.target, xhrOptions))) | ||
if (e.type == "load") { | ||
if (response instanceof Array && xhrOptions.type) { | ||
for (var i = 0; i < response.length; i++) response[i] = new xhrOptions.type(response[i]) | ||
} | ||
else if (xhrOptions.type) response = new xhrOptions.type(response) | ||
} | ||
deferred[e.type == "load" ? "resolve" : "reject"](response) | ||
} | ||
else if (xhrOptions.type) response = new xhrOptions.type(response) | ||
deferred.promise(response) | ||
deferred[e.type == "load" ? "resolve" : "reject"](response) | ||
catch (e) { | ||
if (e instanceof SyntaxError) throw new SyntaxError("Could not parse HTTP response. See http://lhorie.github.io/mithril/mithril.request.html#using-variable-data-formats") | ||
else if (e instanceof Error && e.constructor !== Error) throw e | ||
else deferred.reject(e) | ||
} | ||
if (xhrOptions.background !== true) m.endComputation() | ||
} | ||
ajax(xhrOptions) | ||
deferred.promise.then = propBinder(deferred.promise) | ||
return deferred.promise | ||
} | ||
function propBinder(promise) { | ||
var bind = promise.then | ||
return function(success, error) { | ||
var next = bind(function(value) {return next(success(value))}, function(value) {return next(error(value))}) | ||
next.then = propBinder(next) | ||
return next | ||
} | ||
} | ||
//testing API | ||
@@ -524,7 +646,9 @@ m.deps = function(mock) {return window = mock} | ||
m.deps.factory = app | ||
return m | ||
}(this) | ||
}(typeof window != "undefined" ? window : {}) | ||
if (typeof module != "undefined" && module !== null) module.exports = m | ||
if (typeof define == "function" && define.amd) define(function() {return m}) | ||
;;; |
/* | ||
Mithril v0.1.13 | ||
Mithril v0.1.16 | ||
http://github.com/lhorie/mithril.js | ||
@@ -7,3 +7,3 @@ (c) Leo Horie | ||
*/ | ||
Mithril=m=new function a(b){function c(){var a=arguments,b="[object Object]"==v.call(a[1]),c=b?a[1]:{},d="class"in c?"class":"className",e=u[a[0]];if(void 0===e){u[a[0]]=e={tag:"div",attrs:{}};for(var f,g=[];f=w.exec(a[0]);)if(""==f[1])e.tag=f[2];else if("#"==f[1])e.attrs.id=f[2];else if("."==f[1])g.push(f[2]);else if("["==f[3][0]){var i=x.exec(f[3]);e.attrs[i[1]]=i[3]||!0}g.length>0&&(e.attrs[d]=g.join(" "))}e=h(e),e.attrs=h(e.attrs),e.children=b?a[2]:a[1];for(var j in c)e.attrs[j]=j==d?(e.attrs[j]||"")+" "+c[j]:c[j];return e}function d(a,c,h,i,j,k,l,m){if((null===h||void 0===h)&&(h=""),"retain"!==h.subtree){var n=v.call(i),o=v.call(h);if(n!=o&&(null!==i&&void 0!==i&&f(i.nodes),i=new h.constructor,i.nodes=[]),"[object Array]"==o){for(var p=[],q=i.length===h.length,r=0,s=0,t=0;s<h.length;s++){var u=d(a,null,h[s],i[t],j,k+r||r,l,m);void 0!==u&&(u.nodes.intact||(q=!1),r+=u instanceof Array?u.length:1,i[t++]=u)}if(!q){for(var s=0;s<h.length;s++)void 0!==i[s]&&(p=p.concat(i[s].nodes));for(var w,s=p.length;w=i.nodes[s];s++)null!==w.parentNode&&w.parentNode.removeChild(w);for(var w,s=i.nodes.length;w=p[s];s++)null===w.parentNode&&a.appendChild(w);h.length<i.length&&(i.length=h.length),i.nodes=p}}else if("[object Object]"==o){if((h.tag!=i.tag||Object.keys(h.attrs).join()!=Object.keys(i.attrs).join()||h.attrs.id!=i.attrs.id)&&f(i.nodes),"string"!=typeof h.tag)return;var w,x=0===i.nodes.length;"svg"===h.tag&&(m="http://www.w3.org/2000/svg"),x?(w=void 0===m?b.document.createElement(h.tag):b.document.createElementNS(m,h.tag),i={tag:h.tag,attrs:e(w,h.tag,h.attrs,{},m),children:d(w,h.tag,h.children,i.children,!0,0,h.attrs.contenteditable?w:l,m),nodes:[w]},a.insertBefore(w,a.childNodes[k]||null)):(w=i.nodes[0],e(w,h.tag,h.attrs,i.attrs,m),i.children=d(w,h.tag,h.children,i.children,!1,0,h.attrs.contenteditable?w:l,m),i.nodes.intact=!0,j===!0&&a.insertBefore(w,a.childNodes[k]||null)),"[object Function]"==v.call(h.attrs.config)&&h.attrs.config(w,!x)}else{var w;if(0===i.nodes.length)h.$trusted?w=g(a,k,h):(w=b.document.createTextNode(h),a.insertBefore(w,a.childNodes[k]||null)),i="string number boolean".indexOf(typeof h)>-1?new h.constructor(h):h,i.nodes=[w];else if(i.valueOf()!==h.valueOf()||j===!0){if(!l||l!==b.document.activeElement)if(h.$trusted){var y=i.nodes[0],p=[y];if(y){for(;y=y.nextSibling;)p.push(y);f(p),w=g(a,k,h)}else a.innerHTML=h}else w=i.nodes[0],"textarea"===c?a.value=h:l?l.innerHTML=h:(a.insertBefore(w,a.childNodes[k]||null),w.nodeValue=h);i=new h.constructor(h),i.nodes=[w]}else i.nodes.intact=!0}return i}}function e(a,c,d,e,f){for(var g in d){var h=d[g],j=e[g];if(!(g in e)||j!==h||a===b.document.activeElement){if(e[g]=h,"config"===g)continue;if("function"==typeof h&&0==g.indexOf("on"))a[g]=i(h,a);else if("style"===g&&"object"==typeof h){for(var k in h)(void 0===j||j[k]!==h[k])&&(a.style[k]=h[k]);for(var k in j)k in h||(a.style[k]="")}else void 0!==f?"href"===g?a.setAttributeNS("http://www.w3.org/1999/xlink","href",h):"className"===g?a.setAttribute("class",h):a.setAttribute(g,h):"value"===g&&"input"===c?a.value!==h&&(a.value=h):g in a&&"list"!=g&&"style"!=g?a[g]=h:a.setAttribute(g,h)}}return e}function f(a){for(var b=a.length-1;b>-1;b--)a[b].parentNode.removeChild(a[b]);a.length=0}function g(a,b,c){var d=a.childNodes[b];return d?d.insertAdjacentHTML("beforebegin",c):a.insertAdjacentHTML("beforeend",c),d?d.previousSibling:a.firstChild}function h(a){var b={};for(var c in a)b[c]=a[c];return b}function i(a,b){return function(d){c.startComputation();try{return a.call(b,d)}finally{c.endComputation()}}}function j(){for(var a=0;a<B.length;a++)c.render(B[a],C[a].view(D[a]));H&&(H(),H=null),F=E}function k(a,b,d){M={};for(var e in b){if(e==d)return!void c.module(a,b[e]);var f=new RegExp("^"+e.replace(/:[^\/]+?\.{3}/g,"(.*?)").replace(/:[^\/]+/g,"([^\\/]+)")+"$");if(f.test(d))return!void d.replace(f,function(){for(var d=e.match(/:[^\/]+/g),f=[].slice.call(arguments,1,-2),g=0;g<d.length;g++)M[d[g].replace(/:|\./g,"")]=decodeURIComponent(f[g]);c.module(a,b[e])})}}function l(a){a.ctrlKey||a.metaKey||2==a.which||(a.preventDefault(),c.route(a.currentTarget[c.route.mode].slice(K[c.route.mode].length)))}function m(){"hash"!=c.route.mode&&b.location.hash&&(b.location.hash=b.location.hash)}function n(a){return a}function o(a){var c=b.XDomainRequest?new b.XDomainRequest:new b.XMLHttpRequest;return c.open(a.method,a.url,!0,a.user,a.password),c.onload="function"==typeof a.onload?a.onload:function(){},c.onerror="function"==typeof a.onerror?a.onerror:function(){},c.onreadystatechange=function(){4===c.readyState&&0===c.status&&c.onerror({type:"error",target:c})},"function"==typeof a.config&&a.config(c,a),c.send(a.data),c}function p(a,b){var c=[];for(var d in a){var e=b?b+"["+d+"]":d,f=a[d];c.push("object"==typeof f?p(f,e):encodeURIComponent(e)+"="+encodeURIComponent(f))}return c.join("&")}function q(a,b,c){return b&&Object.keys(b).length>0&&("GET"==a.method?a.url=a.url+(a.url.indexOf("?")<0?"?":"&")+p(b):a.data=c(b)),a}function r(a,b){var c=a.match(/:[a-z]\w+/gi);if(c&&b)for(var d=0;d<c.length;d++){var e=c[d].slice(1);a=a.replace(c[d],b[e]),delete b[e]}return a}function s(a){var b=a.then;return function(a,c){var d=b(function(b){return d(a(b))},function(a){return d(c(a))});return d.then=s(d),d}}var t,u={},v={}.toString,w=/(?:(^|#|\.)([^#\.\[\]]+))|(\[.+?\])/g,x=/\[(.+?)(?:=("|'|)(.+?)\2)?\]/,y={insertAdjacentHTML:function(a,c){b.document.write(c),b.document.close()},appendChild:function(a){void 0===t&&(t=b.document.createElement("html")),"HTML"==a.nodeName?t=a:t.appendChild(a),b.document.documentElement!==t&&b.document.replaceChild(t,b.document.documentElement)},insertBefore:function(a){this.appendChild(a)},childNodes:[]},z=[],A={};c.render=function(a,c){var e=z.indexOf(a),f=0>e?z.push(a)-1:e,g=a==b.document||a==b.document.documentElement?y:a;A[f]=d(g,null,c,A[f],!1,0,null,void 0)},c.trust=function(a){return a=new String(a),a.$trusted=!0,a};var B=[],C=[],D=[],E=0,F=0,G=0,H=null;c.module=function(a,b){c.startComputation();var d=B.indexOf(a);0>d&&(d=B.length),B[d]=a,C[d]=b,D[d]&&"function"==typeof D[d].onunload&&D[d].onunload(),D[d]=new b.controller,c.endComputation()},c.redraw=function(){if(E=b.performance&&b.performance.now?b.performance.now():(new b.Date).getTime(),E-F>16)j();else{var a=b.cancelAnimationFrame||b.clearTimeout,c=b.requestAnimationFrame||b.setTimeout;a(G),G=c(j,0)}};var I=0;c.startComputation=function(){I++},c.endComputation=function(){I=Math.max(I-1,0),0==I&&c.redraw()},c.withAttr=function(a,b){return function(c){b(a in c.currentTarget?c.currentTarget[a]:c.currentTarget.getAttribute(a))}};var J,K={pathname:"",hash:"#",search:"?"},L=function(){},M={};return c.route=function(){if(0===arguments.length)return J;if(3===arguments.length){J=b.location[c.route.mode].slice(K[c.route.mode].length);var a=arguments[0],d=arguments[1],e=arguments[2];L=function(b){var f=b.slice(K[c.route.mode].length);k(a,e,f)||c.route(d,!0)};var f="hash"==c.route.mode?"onhashchange":"onpopstate";b[f]=function(){L(b.location[c.route.mode])},H=m,b[f]()}else if(arguments[0].addEventListener){var g=arguments[0],h=arguments[1];g.href.indexOf(K[c.route.mode])<0&&(g.href=location.pathname+K[c.route.mode]+g.pathname),h||(g.removeEventListener("click",l),g.addEventListener("click",l))}else if("string"==typeof arguments[0]){J=arguments[0];var i=arguments[1]===!0;b.history.pushState?(H=function(){b.history[i?"replaceState":"pushState"](null,b.document.title,K[c.route.mode]+J),m()},L(K[c.route.mode]+J)):b.location[c.route.mode]=J}},c.route.param=function(a){return M[a]},c.route.mode="search",c.prop=function(a){var b=function(){return arguments.length&&(a=arguments[0]),a};return b.toJSON=function(){return a},b},c.deferred=function(){var a,b,d=[],e=[],f={resolve:function(b){void 0===a&&(a=b);for(var c=0;c<d.length;c++)d[c](b);d.length=e.length=0},reject:function(a){void 0===b&&(b=a);for(var c=0;c<e.length;c++)e[c](a);d.length=e.length=0},promise:c.prop()};return f.promise.resolvers=d,f.promise.then=function(f,g){function h(a,b){return function(c){try{var d=b(c);d&&"function"==typeof d.then?d.then(i[a],g):i[a](void 0!==d?d:c)}catch(e){if(e instanceof Error&&e.constructor!==Error)throw e;i.reject(e)}}}var i=c.deferred();return f||(f=n),g||(g=n),void 0!==a?h("resolve",f)(a):void 0!==b?h("reject",g)(b):(d.push(h("resolve",f)),e.push(h("reject",g))),i.promise},f},c.sync=function(a){function b(b){return function(c){return f.push(c),b||(d="reject"),f.length==a.length&&(e.promise(f),e[d](f)),c}}for(var d="resolve",e=c.deferred(),f=[],g=0;g<a.length;g++)a[g].then(b(!0),b(!1));return e.promise},c.request=function(a){a.background!==!0&&c.startComputation();var b=c.deferred(),d=a.serialize||JSON.stringify,e=a.deserialize||JSON.parse,f=a.extract||function(a){return 0===a.responseText.length&&e===JSON.parse?null:a.responseText};return a.url=r(a.url,a.data),a=q(a,a.data,d),a.onload=a.onerror=function(d){var g=("load"==d.type?a.unwrapSuccess:a.unwrapError)||n,h=g(e(f(d.target,a)));if(h instanceof Array&&a.type)for(var i=0;i<h.length;i++)h[i]=new a.type(h[i]);else a.type&&(h=new a.type(h));b.promise(h),b["load"==d.type?"resolve":"reject"](h),a.background!==!0&&c.endComputation()},o(a),b.promise.then=s(b.promise),b.promise},c.deps=function(a){return b=a},c.deps.factory=a,c}(this),"undefined"!=typeof module&&null!==module&&(module.exports=m),"function"==typeof define&&define.amd&&define(function(){return m}); | ||
Mithril=m=new function a(b){function c(){var a=arguments,b=!("[object Object]"!=x.call(a[1])||"tag"in a[1]||"subtree"in a[1]),c=b?a[1]:{},d="class"in c?"class":"className",e=w[a[0]];if(void 0===e){w[a[0]]=e={tag:"div",attrs:{}};for(var f,g=[];f=y.exec(a[0]);)if(""==f[1])e.tag=f[2];else if("#"==f[1])e.attrs.id=f[2];else if("."==f[1])g.push(f[2]);else if("["==f[3][0]){var i=z.exec(f[3]);e.attrs[i[1]]=i[3]||!0}g.length>0&&(e.attrs[d]=g.join(" "))}e=h(e),e.attrs=h(e.attrs),e.children=b?a[2]:a[1];for(var j in c)e.attrs[j]=j==d?(e.attrs[j]||"")+" "+c[j]:c[j];return e}function d(a,c,h,i,j,k,l,m,n,o,p){if((null===j||void 0===j)&&(j=""),"retain"!==j.subtree){var q=x.call(k),r=x.call(j);if(q!=r){if(null!==k&&void 0!==k)if(h&&h.nodes){var s=m-i;f(h.nodes.slice(s,s+("[object Array]"==r?j:k.nodes).length))}else f(k.nodes);k=new j.constructor,k.nodes=[]}if("[object Array]"==r){for(var t=[],u=k.length===j.length,v=0,w=1,y=2,z=3,A={},B=!1,C=0;C<k.length;C++)k[C]&&k[C].attrs&&void 0!==k[C].attrs.key&&(B=!0,A[k[C].attrs.key]={action:w,index:C});if(B){for(var C=0;C<j.length;C++)if(j[C]&&j[C].attrs&&void 0!==j[C].attrs.key){var D=j[C].attrs.key;A[D]=A[D]?{action:z,index:C,from:A[D].index,element:a.childNodes[A[D].index]}:{action:y,index:C}}for(var E,F=Object.keys(A).map(function(a){return A[a]}),G=F.sort(function(a,b){return a.action-b.action||b.index-a.index}),H=new Array(k.length),C=0;E=G[C];C++){if(E.action==w&&(f(k[E.index].nodes),H.splice(E.index,1)),E.action==y){var I=b.document.createElement("div");I.key=j[E.index].attrs.key.toString(),a.insertBefore(I,a.childNodes[E.index]),H.splice(E.index,0,{attrs:{key:j[E.index].attrs.key},nodes:[I]})}E.action==z&&(a.childNodes[E.index]!==E.element&&a.insertBefore(E.element,a.childNodes[E.index]),H[E.index]=k[E.from])}k=H,k.nodes=[];for(var J,C=0;J=a.childNodes[C];C++)k.nodes.push(J)}for(var C=0,K=0;C<j.length;C++){var L=d(a,c,k,m,j[C],k[K],l,m+v||v,n,o,p);void 0!==L&&(L.nodes.intact||(u=!1),v+=L instanceof Array?L.length:1,k[K++]=L)}if(!u){for(var C=0;C<j.length;C++)void 0!==k[C]&&(t=t.concat(k[C].nodes));for(var M,C=t.length;M=k.nodes[C];C++)null!==M.parentNode&&M.parentNode.childNodes.length!=t.length&&M.parentNode.removeChild(M);for(var M,C=k.nodes.length;M=t[C];C++)null===M.parentNode&&a.appendChild(M);j.length<k.length&&(k.length=j.length),k.nodes=t}}else if("[object Object]"==r){if((j.tag!=k.tag||Object.keys(j.attrs).join()!=Object.keys(k.attrs).join()||j.attrs.id!=k.attrs.id)&&f(k.nodes),"string"!=typeof j.tag)return;var M,N=0===k.nodes.length;j.attrs.xmlns?o=j.attrs.xmlns:"svg"===j.tag&&(o="http://www.w3.org/2000/svg"),N?(M=void 0===o?b.document.createElement(j.tag):b.document.createElementNS(o,j.tag),k={tag:j.tag,attrs:e(M,j.tag,j.attrs,{},o),children:void 0!==j.children?d(M,j.tag,void 0,void 0,j.children,k.children,!0,0,j.attrs.contenteditable?M:n,o,p):void 0,nodes:[M]},a.insertBefore(M,a.childNodes[m]||null)):(M=k.nodes[0],e(M,j.tag,j.attrs,k.attrs,o),k.children=d(M,j.tag,void 0,void 0,j.children,k.children,!1,0,j.attrs.contenteditable?M:n,o,p),k.nodes.intact=!0,l===!0&&a.insertBefore(M,a.childNodes[m]||null)),"[object Function]"==x.call(j.attrs.config)&&p.push(j.attrs.config.bind(b,M,!N,k.configContext=k.configContext||{}))}else{var t;0===k.nodes.length?(j.$trusted?t=g(a,m,j):(t=[b.document.createTextNode(j)],a.insertBefore(t[0],a.childNodes[m]||null)),k="string number boolean".indexOf(typeof j)>-1?new j.constructor(j):j,k.nodes=t):k.valueOf()!==j.valueOf()||l===!0?(t=k.nodes,n&&n===b.document.activeElement||(j.$trusted?(f(t),t=g(a,m,j)):"textarea"===c?a.value=j:n?n.innerHTML=j:((1==t[0].nodeType||t.length>1)&&(f(k.nodes),t=[b.document.createTextNode(j)]),a.insertBefore(t[0],a.childNodes[m]||null),t[0].nodeValue=j)),k=new j.constructor(j),k.nodes=t):k.nodes.intact=!0}return k}}function e(a,c,d,e,f){for(var g in d){var h=d[g],j=e[g];if(!(g in e)||j!==h||a===b.document.activeElement){if(e[g]=h,"config"===g)continue;if("function"==typeof h&&0==g.indexOf("on"))a[g]=i(h,a);else if("style"===g&&"object"==typeof h){for(var k in h)(void 0===j||j[k]!==h[k])&&(a.style[k]=h[k]);for(var k in j)k in h||(a.style[k]="")}else void 0!==f?"href"===g?a.setAttributeNS("http://www.w3.org/1999/xlink","href",h):"className"===g?a.setAttribute("class",h):a.setAttribute(g,h):"value"===g&&"input"===c?a.value!==h&&(a.value=h):g in a&&"list"!=g&&"style"!=g?a[g]=h:a.setAttribute(g,h)}}return e}function f(a){for(var b=a.length-1;b>-1;b--)a[b]&&a[b].parentNode&&a[b].parentNode.removeChild(a[b]);a.length=0}function g(a,c,d){var e=a.childNodes[c];if(e){var f=1!=e.nodeType,g=b.document.createElement("span");f?(a.insertBefore(g,e),g.insertAdjacentHTML("beforebegin",d),a.removeChild(g)):e.insertAdjacentHTML("beforebegin",d)}else a.insertAdjacentHTML("beforeend",d);for(var h=[];a.childNodes[c]!==e;)h.push(a.childNodes[c]),c++;return h}function h(a){var b={};for(var c in a)b[c]=a[c];return b}function i(a,b){return function(d){d=d||event,c.startComputation();try{return a.call(b,d)}finally{c.endComputation()}}}function j(){for(var a=0;a<D.length;a++)F[a]&&c.render(D[a],E[a].view(F[a]));J&&(J(),J=null),H=G}function k(a){return a.slice(M[c.route.mode].length)}function l(a,b,d){O={};var e=d.indexOf("?");-1!==e&&(O=p(d.substr(e+1,d.length)),d=d.substr(0,e));for(var f in b){if(f==d)return!void c.module(a,b[f]);var g=new RegExp("^"+f.replace(/:[^\/]+?\.{3}/g,"(.*?)").replace(/:[^\/]+/g,"([^\\/]+)")+"/?$");if(g.test(d))return!void d.replace(g,function(){for(var d=f.match(/:[^\/]+/g)||[],e=[].slice.call(arguments,1,-2),g=0;g<d.length;g++)O[d[g].replace(/:|\./g,"")]=q(e[g]);c.module(a,b[f])})}}function m(a){a=a||event,a.ctrlKey||a.metaKey||2==a.which||(a.preventDefault(),c.route(a.currentTarget[c.route.mode].slice(M[c.route.mode].length)))}function n(){"hash"!=c.route.mode&&b.location.hash?b.location.hash=b.location.hash:b.scrollTo(0,0)}function o(a,b){var c=[];for(var d in a){var e=b?b+"["+d+"]":d,f=a[d];c.push("object"==typeof f?o(f,e):encodeURIComponent(e)+"="+encodeURIComponent(f))}return c.join("&")}function p(a){for(var b=a.split("&"),c={},d=0;d<b.length;d++){var e=b[d].split("=");c[q(e[0])]=e[1]?q(e[1]):1===e.length?!0:""}return c}function q(a){return decodeURIComponent(a.replace(/\+/g," "))}function r(a){return a}function s(a){var c=new b.XMLHttpRequest;if(c.open(a.method,a.url,!0,a.user,a.password),c.onreadystatechange=function(){4===c.readyState&&(c.status>=200&&c.status<300?a.onload({type:"load",target:c}):a.onerror({type:"error",target:c}))},"function"==typeof a.config){var d=a.config(c,a);void 0!==d&&(c=d)}return c.send(a.data),c}function t(a,b,c){return b&&Object.keys(b).length>0&&("GET"==a.method?a.url=a.url+(a.url.indexOf("?")<0?"?":"&")+o(b):a.data=c(b)),a}function u(a,b){var c=a.match(/:[a-z]\w+/gi);if(c&&b)for(var d=0;d<c.length;d++){var e=c[d].slice(1);a=a.replace(c[d],b[e]),delete b[e]}return a}var v,w={},x={}.toString,y=/(?:(^|#|\.)([^#\.\[\]]+))|(\[.+?\])/g,z=/\[(.+?)(?:=("|'|)(.+?)\2)?\]/,A={insertAdjacentHTML:function(a,c){b.document.write(c),b.document.close()},appendChild:function(a){void 0===v&&(v=b.document.createElement("html")),"HTML"==a.nodeName?v=a:v.appendChild(a),b.document.documentElement!==v&&b.document.replaceChild(v,b.document.documentElement)},insertBefore:function(a){this.appendChild(a)},childNodes:[]},B=[],C={};c.render=function(a,c){var e=[];if(!a)throw new Error("Please ensure the DOM element exists before rendering a template into it.");var f=B.indexOf(a),g=0>f?B.push(a)-1:f,h=a==b.document||a==b.document.documentElement?A:a;C[g]=d(h,null,void 0,void 0,c,C[g],!1,0,null,void 0,e);for(var i=0;i<e.length;i++)e[i]()},c.trust=function(a){return a=new String(a),a.$trusted=!0,a};var D=[],E=[],F=[],G=0,H=0,I=0,J=null;c.module=function(a,b){var d=D.indexOf(a);0>d&&(d=D.length);var e=!1;if(F[d]&&"function"==typeof F[d].onunload){var f={preventDefault:function(){e=!0}};F[d].onunload(f)}e||(c.startComputation(),D[d]=a,E[d]=b,F[d]=new b.controller,c.endComputation())},c.redraw=function(){if(G=b.performance&&b.performance.now?b.performance.now():(new b.Date).getTime(),G-H>16)j();else{var a=b.cancelAnimationFrame||b.clearTimeout,c=b.requestAnimationFrame||b.setTimeout;a(I),I=c(j,0)}};var K=0;c.startComputation=function(){K++},c.endComputation=function(){K=Math.max(K-1,0),0==K&&c.redraw()},c.withAttr=function(a,b){return function(c){c=c||event,b(a in c.currentTarget?c.currentTarget[a]:c.currentTarget.getAttribute(a))}};var L,M={pathname:"",hash:"#",search:"?"},N=function(){},O={};c.route=function(){if(0===arguments.length)return L;if(3===arguments.length&&"string"==typeof arguments[1]){var a=arguments[0],d=arguments[1],e=arguments[2];N=function(b){var f=L=k(b);l(a,e,f)||c.route(d,!0)};var f="hash"==c.route.mode?"onhashchange":"onpopstate";b[f]=function(){L!=k(b.location[c.route.mode])&&N(b.location[c.route.mode])},J=n,b[f](),L=k(b.location[c.route.mode])}else if(arguments[0].addEventListener){var g=arguments[0],h=arguments[1];g.href.indexOf(M[c.route.mode])<0&&(g.href=b.location.pathname+M[c.route.mode]+g.pathname),h||(g.removeEventListener("click",m),g.addEventListener("click",m))}else if("string"==typeof arguments[0]){L=arguments[0];var i="object"==typeof arguments[1]?o(arguments[1]):null;i&&(L+=(-1===L.indexOf("?")?"?":"&")+i);var j=(3==arguments.length?arguments[2]:arguments[1])===!0;b.history.pushState?(J=function(){b.history[j?"replaceState":"pushState"](null,b.document.title,M[c.route.mode]+L),n()},N(M[c.route.mode]+L)):b.location[c.route.mode]=L}},c.route.param=function(a){return O[a]},c.route.mode="search",c.prop=function(a){var b=function(){return arguments.length&&(a=arguments[0]),a};return b.toJSON=function(){return a},b};var P={};return c.deferred=function(){var a=[],b=[],d=P,e=P,f=c.prop(),g={resolve:function(c){d===P&&f(d=c);for(var e=0;e<a.length;e++)a[e](c);a.length=b.length=0},reject:function(c){e===P&&(e=c);for(var d=0;d<b.length;d++)b[d](c);a.length=b.length=0},promise:f};return g.promise.resolvers=a,g.promise.then=function(f,g){function h(a,b){return function(c){try{var d=b(c);d&&"function"==typeof d.then?d.then(i[a],g):i[a](void 0!==d?d:c)}catch(e){if(e instanceof Error&&e.constructor!==Error)throw e;i.reject(e)}}}var i=c.deferred();return f||(f=r),g||(g=r),d!==P?h("resolve",f)(d):e!==P?h("reject",g)(e):(a.push(h("resolve",f)),b.push(h("reject",g))),i.promise},g},c.sync=function(a){function b(a,b){return function(c){return g[a]=c,b||(d="reject"),0==--f&&(e.promise(g),e[d](g)),c}}for(var d="resolve",e=c.deferred(),f=a.length,g=new Array(f),h=0;h<a.length;h++)a[h].then(b(h,!0),b(h,!1));return e.promise},c.request=function(a){a.background!==!0&&c.startComputation();var b=c.deferred(),d=a.serialize||JSON.stringify,e=a.deserialize||JSON.parse,f=a.extract||function(a){return 0===a.responseText.length&&e===JSON.parse?null:a.responseText};return a.url=u(a.url,a.data),a=t(a,a.data,d),a.onload=a.onerror=function(d){try{d=d||event;var g=("load"==d.type?a.unwrapSuccess:a.unwrapError)||r,h=g(e(f(d.target,a)));if("load"==d.type)if(h instanceof Array&&a.type)for(var i=0;i<h.length;i++)h[i]=new a.type(h[i]);else a.type&&(h=new a.type(h));b["load"==d.type?"resolve":"reject"](h)}catch(d){if(d instanceof SyntaxError)throw new SyntaxError("Could not parse HTTP response. See http://lhorie.github.io/mithril/mithril.request.html#using-variable-data-formats");if(d instanceof Error&&d.constructor!==Error)throw d;b.reject(d)}a.background!==!0&&c.endComputation()},s(a),b.promise},c.deps=function(a){return b=a},c.deps.factory=a,c}("undefined"!=typeof window?window:{}),"undefined"!=typeof module&&null!==module&&(module.exports=m),"function"==typeof define&&define.amd&&define(function(){return m}); | ||
//# sourceMappingURL=mithril.min.map |
@@ -5,3 +5,3 @@ { | ||
"keywords": ["mvc", "framework"], | ||
"version": "0.1.13", | ||
"version": "0.1.16", | ||
"author": "Leo Horie <leohorie@hotmail.com>", | ||
@@ -8,0 +8,0 @@ "repository": {"type": "git", "url": "https://github.com/lhorie/mithril"}, |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
54166
642