diff --git a/archive/v0.1.11/change-log.html b/archive/v0.1.11/change-log.html
index de6da58d..52998b58 100644
--- a/archive/v0.1.11/change-log.html
+++ b/archive/v0.1.11/change-log.html
@@ -68,6 +68,10 @@
Added m.route() overload to allow reading of current route #61
Added background option to m.request to allow requests that don't affect rendering #62
+Bug Fixes:
+
+- Links using
config: m.route can now be opened in new tab correctly #64
+
v0.1.10 - maintenance
News:
diff --git a/archive/v0.1.11/mithril-tests.js b/archive/v0.1.11/mithril-tests.js
index ba71f23e..8b40890c 100644
--- a/archive/v0.1.11/mithril-tests.js
+++ b/archive/v0.1.11/mithril-tests.js
@@ -211,7 +211,7 @@ Mithril = m = new function app(window) {
return value
}
- var roots = [], modules = [], controllers = [], now = 0, lastRedraw = 0, lastRedrawId = 0
+ var roots = [], modules = [], controllers = [], now = 0, lastRedraw = 0, lastRedrawId = 0, computePostRedrawHook = null
m.module = function(root, module) {
m.startComputation()
var index = roots.indexOf(root)
@@ -235,20 +235,18 @@ Mithril = m = new function app(window) {
for (var i = 0; i < roots.length; i++) {
m.render(roots[i], modules[i].view(controllers[i]))
}
+ if (computePostRedrawHook) {
+ computePostRedrawHook()
+ computePostRedrawHook = null
+ }
lastRedraw = now
}
- var pendingRequests = 0, computePostRedrawHook = null
+ var pendingRequests = 0
m.startComputation = function() {pendingRequests++}
m.endComputation = function() {
pendingRequests = Math.max(pendingRequests - 1, 0)
- if (pendingRequests == 0) {
- m.redraw()
- if (computePostRedrawHook) {
- computePostRedrawHook()
- computePostRedrawHook = null
- }
- }
+ if (pendingRequests == 0) m.redraw()
}
m.withAttr = function(prop, withAttrCallback) {
@@ -279,6 +277,7 @@ Mithril = m = new function app(window) {
else if (arguments[0].addEventListener) {
var element = arguments[0]
var isInitialized = arguments[1]
+ element.href = modes[m.route.mode] + element.pathname
if (!isInitialized) {
element.removeEventListener("click", routeUnobtrusive)
element.addEventListener("click", routeUnobtrusive)
@@ -316,8 +315,9 @@ Mithril = m = new function app(window) {
}
}
function routeUnobtrusive(e) {
+ if (e.ctrlKey || e.metaKey || e.which == 2) return
e.preventDefault()
- m.route(e.currentTarget.getAttribute("href"))
+ m.route(e.currentTarget[m.route.mode].slice(modes[m.route.mode].length))
}
function scrollToHash() {
if (m.route.mode != "hash" && window.location.hash) window.location.hash = window.location.hash
@@ -934,7 +934,7 @@ function testMithril(mock) {
//m.redraw
test(function() {
- mock.performance.$elapse(50)
+ mock.performance.$elapse(50) //setup
var controller
var root = mock.document.createElement("div")
m.module(root, {
@@ -946,11 +946,11 @@ function testMithril(mock) {
var lengthBefore = root.childNodes.length
mock.performance.$elapse(50)
m.redraw()
- mock.performance.$elapse(50)
+ mock.performance.$elapse(50) //teardown
return lengthBefore === 0 && root.childNodes[0].nodeValue === "foo"
})
test(function() {
- mock.performance.$elapse(50)
+ mock.performance.$elapse(50) //setup
var count = 0
var root = mock.document.createElement("div")
m.module(root, {
@@ -964,13 +964,13 @@ function testMithril(mock) {
m.redraw()
mock.performance.$elapse(50)
m.redraw()
- mock.performance.$elapse(50)
+ mock.performance.$elapse(50) //teardown
return count === 2
})
//m.route
test(function() {
- mock.performance.$elapse(50)
+ mock.performance.$elapse(50) //setup
mock.location.search = "?"
var root = mock.document.createElement("div")
@@ -978,10 +978,11 @@ function testMithril(mock) {
m.route(root, "/test1", {
"/test1": {controller: function() {}, view: function() {return "foo"}}
})
+ mock.performance.$elapse(50) //teardown
return mock.location.search == "?/test1" && root.childNodes[0].nodeValue === "foo"
})
test(function() {
- mock.performance.$elapse(50)
+ mock.performance.$elapse(50) //setup
mock.location.pathname = "/"
var root = mock.document.createElement("div")
@@ -989,10 +990,11 @@ function testMithril(mock) {
m.route(root, "/test2", {
"/test2": {controller: function() {}, view: function() {return "foo"}}
})
+ mock.performance.$elapse(50) //teardown
return mock.location.pathname == "/test2" && root.childNodes[0].nodeValue === "foo"
})
test(function() {
- mock.performance.$elapse(50)
+ mock.performance.$elapse(50) //setup
mock.location.hash = "#"
var root = mock.document.createElement("div")
@@ -1000,10 +1002,11 @@ function testMithril(mock) {
m.route(root, "/test3", {
"/test3": {controller: function() {}, view: function() {return "foo"}}
})
+ mock.performance.$elapse(50) //teardown
return mock.location.hash == "#/test3" && root.childNodes[0].nodeValue === "foo"
})
test(function() {
- mock.performance.$elapse(50)
+ mock.performance.$elapse(50) //setup
mock.location.search = "?"
var root = mock.document.createElement("div")
@@ -1011,10 +1014,11 @@ function testMithril(mock) {
m.route(root, "/test4/foo", {
"/test4/:test": {controller: function() {}, view: function() {return m.route.param("test")}}
})
+ mock.performance.$elapse(50) //teardown
return mock.location.search == "?/test4/foo" && root.childNodes[0].nodeValue === "foo"
})
test(function() {
- mock.performance.$elapse(50)
+ mock.performance.$elapse(50) //setup
mock.location.search = "?"
var module = {controller: function() {}, view: function() {return m.route.param("test")}}
@@ -1026,13 +1030,14 @@ function testMithril(mock) {
"/test5/:test": module
})
var paramValueBefore = m.route.param("test")
+ mock.performance.$elapse(50)
m.route("/")
var paramValueAfter = m.route.param("test")
-
+ mock.performance.$elapse(50) //teardown
return mock.location.search == "?/" && paramValueBefore === "foo" && paramValueAfter === undefined
})
test(function() {
- mock.performance.$elapse(50)
+ mock.performance.$elapse(50) //setup
mock.location.search = "?"
var module = {controller: function() {}, view: function() {return m.route.param("a1")}}
@@ -1044,13 +1049,15 @@ function testMithril(mock) {
"/test6/:a1": module
})
var paramValueBefore = m.route.param("a1")
+ mock.performance.$elapse(50)
m.route("/")
var paramValueAfter = m.route.param("a1")
+ mock.performance.$elapse(50) //teardown
return mock.location.search == "?/" && paramValueBefore === "foo" && paramValueAfter === undefined
})
test(function() {
//https://github.com/lhorie/mithril.js/issues/61
- mock.performance.$elapse(50)
+ mock.performance.$elapse(50) //setup
mock.location.search = "?"
var module = {controller: function() {}, view: function() {return m.route.param("a1")}}
@@ -1062,8 +1069,10 @@ function testMithril(mock) {
"/test7/:a1": module
})
var routeValueBefore = m.route()
+ mock.performance.$elapse(50)
m.route("/")
var routeValueAfter = m.route()
+ mock.performance.$elapse(50) //teardown
return routeValueBefore === "/test7/foo" && routeValueAfter === "/"
})
diff --git a/archive/v0.1.11/mithril.html b/archive/v0.1.11/mithril.html
index 1a406b69..c9e1957a 100644
--- a/archive/v0.1.11/mithril.html
+++ b/archive/v0.1.11/mithril.html
@@ -147,6 +147,8 @@ m("button", {onclick: alert}); //yields <button></button>,
You can set inline styles like this:
m("div", {style: {border: "1px solid red"}}); //yields <div style="border:1px solid red;"></div>
Note that in order to keep the framework lean, Mithril does not auto-append units like px or % to any values. Typically, you should not even be using inline styles to begin with (unless you are dynamically changing them).
+Mithril also does not auto-camel-case CSS properties on inline style attributes, so you should use the Javascript syntax when setting them:
+m("div", {style: {textAlign: "center"}}); //yields <div style="text-align:1px solid red;"></div>
You can define a non-HTML-standard attribute called config. This special parameter allows you to call methods on the DOM element after it gets created.
This is useful, for example, if you declare a canvas element and want to use the Javascript API to draw:
diff --git a/archive/v0.1.11/mithril.js b/archive/v0.1.11/mithril.js
index 06685a0f..f07d8197 100644
--- a/archive/v0.1.11/mithril.js
+++ b/archive/v0.1.11/mithril.js
@@ -211,7 +211,7 @@ Mithril = m = new function app(window) {
return value
}
- var roots = [], modules = [], controllers = [], now = 0, lastRedraw = 0, lastRedrawId = 0
+ var roots = [], modules = [], controllers = [], now = 0, lastRedraw = 0, lastRedrawId = 0, computePostRedrawHook = null
m.module = function(root, module) {
m.startComputation()
var index = roots.indexOf(root)
@@ -235,20 +235,18 @@ Mithril = m = new function app(window) {
for (var i = 0; i < roots.length; i++) {
m.render(roots[i], modules[i].view(controllers[i]))
}
+ if (computePostRedrawHook) {
+ computePostRedrawHook()
+ computePostRedrawHook = null
+ }
lastRedraw = now
}
- var pendingRequests = 0, computePostRedrawHook = null
+ var pendingRequests = 0
m.startComputation = function() {pendingRequests++}
m.endComputation = function() {
pendingRequests = Math.max(pendingRequests - 1, 0)
- if (pendingRequests == 0) {
- m.redraw()
- if (computePostRedrawHook) {
- computePostRedrawHook()
- computePostRedrawHook = null
- }
- }
+ if (pendingRequests == 0) m.redraw()
}
m.withAttr = function(prop, withAttrCallback) {
@@ -279,6 +277,7 @@ Mithril = m = new function app(window) {
else if (arguments[0].addEventListener) {
var element = arguments[0]
var isInitialized = arguments[1]
+ element.href = modes[m.route.mode] + element.pathname
if (!isInitialized) {
element.removeEventListener("click", routeUnobtrusive)
element.addEventListener("click", routeUnobtrusive)
@@ -316,8 +315,9 @@ Mithril = m = new function app(window) {
}
}
function routeUnobtrusive(e) {
+ if (e.ctrlKey || e.metaKey || e.which == 2) return
e.preventDefault()
- m.route(e.currentTarget.getAttribute("href"))
+ m.route(e.currentTarget[m.route.mode].slice(modes[m.route.mode].length))
}
function scrollToHash() {
if (m.route.mode != "hash" && window.location.hash) window.location.hash = window.location.hash
diff --git a/archive/v0.1.11/mithril.min.js b/archive/v0.1.11/mithril.min.js
index 133dc33f..d5b8b899 100644
--- a/archive/v0.1.11/mithril.min.js
+++ b/archive/v0.1.11/mithril.min.js
@@ -4,5 +4,5 @@ http://github.com/lhorie/mithril.js
(c) Leo Horie
License: MIT
*/
-Mithril=m=new function(a){function b(){var a=arguments,b="[object Object]"==u.call(a[1]),c=b?a[1]:{},d="class"in c?"class":"className",e=t[a[0]];if(void 0===e){t[a[0]]=e={tag:"div",attrs:{}};for(var f,h=[];f=v.exec(a[0]);)if(""==f[1])e.tag=f[2];else if("#"==f[1])e.attrs.id=f[2];else if("."==f[1])h.push(f[2]);else if("["==f[3][0]){var i=w.exec(f[3]);e.attrs[i[1]]=i[3]||!0}h.length>0&&(e.attrs[d]=h.join(" "))}e=g(e),e.attrs=g(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 c(b,g,h,i,j,k,l){if(null===h||void 0===h)return void(i&&e(i.nodes));if("retain"!==h.subtree){var m=u.call(i),n=u.call(h);if(m!=n&&(null!==i&&void 0!==i&&e(i.nodes),i=new h.constructor,i.nodes=[]),"[object Array]"==n){for(var o=[],p=i.length===h.length,q=0,r=0,s=0;r-1?new h.constructor(h):h,i.nodes=[v];else if(i.valueOf()!==h.valueOf()||j===!0){if(h.$trusted){var x=i.nodes[0],o=[x];if(x){for(;x=x.nextSibling;)o.push(x);e(o),v=f(b,k,h)}else b.innerHTML=h}else v=i.nodes[0],"textarea"===g?b.value=h:b.insertBefore(v,b.childNodes[k]||null),v.nodeValue=h;i=new h.constructor(h),i.nodes=[v]}else i.nodes.intact=!0}return i}}function d(b,c,d,e,f){for(var g in d){var i=d[g],j=e[g];if(!(g in e)||j!==i||b===a.document.activeElement){if(e[g]=i,"config"===g)continue;if("function"==typeof i&&0==g.indexOf("on"))b[g]=h(i,b);else if("style"===g)for(var k in i)(void 0===j||j[k]!==i[k])&&(b.style[k]=i[k]);else void 0!==f?"href"===g?b.setAttributeNS("http://www.w3.org/1999/xlink","href",i):"className"===g?b.setAttribute("class",i):b.setAttribute(g,i):"value"===g&&"input"===c?b.value!==i&&(b.value=i):g in b?b[g]=i:b.setAttribute(g,i)}}return e}function e(a){for(var b=0;b0&&("GET"==a.method?a.url=a.url+(a.url.indexOf("?")<0?"?":"&")+o(b):a.data=c(b)),a}function q(a,b){var c=a.match(/:[a-z]\w+/gi);if(c&&b)for(var d=0;de?y.push(b)-1:e,g=b==a.document||b==a.document.documentElement?x:b;z[f]=c(g,null,d,z[f],!1,0)},b.trust=function(a){return a=new String(a),a.$trusted=!0,a};var A=[],B=[],C=[],D=0,E=0,F=0;b.module=function(a,c){b.startComputation();var d=A.indexOf(a);0>d&&(d=A.length),A[d]=a,B[d]=c,C[d]=new c.controller,b.endComputation()},b.redraw=function(){if(D=a.performance&&a.performance.now?a.performance.now():(new a.Date).getTime(),D-E>16)i();else{var b=a.cancelAnimationFrame||a.clearTimeout,c=a.requestAnimationFrame||a.setTimeout;b(F),F=c(i,0)}};var G=0,H=null;b.startComputation=function(){G++},b.endComputation=function(){G=Math.max(G-1,0),0==G&&(b.redraw(),H&&(H(),H=null))},b.withAttr=function(a,b){return function(c){b(a in c.currentTarget?c.currentTarget[a]:c.currentTarget.getAttribute(a))}};var I,J={pathname:"",hash:"#",search:"?"},K=function(){},L={};return b.route=function(){if(0===arguments.length)return I;if(3===arguments.length){I=a.location[b.route.mode].slice(J[b.route.mode].length);var c=arguments[0],d=arguments[1],e=arguments[2];K=function(a){var f=a.slice(J[b.route.mode].length);j(c,e,f)||b.route(d,!0)};var f="hash"==b.route.mode?"onhashchange":"onpopstate";a[f]=function(){K(a.location[b.route.mode])},H=l,a[f]()}else if(arguments[0].addEventListener){var g=arguments[0],h=arguments[1];h||(g.removeEventListener("click",k),g.addEventListener("click",k))}else if("string"==typeof arguments[0]){I=arguments[0];var i=arguments[1]===!0;a.history.pushState?(H=function(){a.history[i?"replaceState":"pushState"](null,a.document.title,J[b.route.mode]+I),l()},K(J[b.route.mode]+I)):a.location[b.route.mode]=I}},b.route.param=function(a){return L[a]},b.route.mode="search",b.prop=function(a){var b=function(){return arguments.length&&(a=arguments[0]),a};return b.toJSON=function(){return a},b},b.deferred=function(){var a=[],c=[],d={resolve:function(b){for(var c=0;c0&&(e.attrs[d]=h.join(" "))}e=g(e),e.attrs=g(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 c(b,g,h,i,j,k,l){if(null===h||void 0===h)return void(i&&e(i.nodes));if("retain"!==h.subtree){var m=u.call(i),n=u.call(h);if(m!=n&&(null!==i&&void 0!==i&&e(i.nodes),i=new h.constructor,i.nodes=[]),"[object Array]"==n){for(var o=[],p=i.length===h.length,q=0,r=0,s=0;r-1?new h.constructor(h):h,i.nodes=[v];else if(i.valueOf()!==h.valueOf()||j===!0){if(h.$trusted){var x=i.nodes[0],o=[x];if(x){for(;x=x.nextSibling;)o.push(x);e(o),v=f(b,k,h)}else b.innerHTML=h}else v=i.nodes[0],"textarea"===g?b.value=h:b.insertBefore(v,b.childNodes[k]||null),v.nodeValue=h;i=new h.constructor(h),i.nodes=[v]}else i.nodes.intact=!0}return i}}function d(b,c,d,e,f){for(var g in d){var i=d[g],j=e[g];if(!(g in e)||j!==i||b===a.document.activeElement){if(e[g]=i,"config"===g)continue;if("function"==typeof i&&0==g.indexOf("on"))b[g]=h(i,b);else if("style"===g)for(var k in i)(void 0===j||j[k]!==i[k])&&(b.style[k]=i[k]);else void 0!==f?"href"===g?b.setAttributeNS("http://www.w3.org/1999/xlink","href",i):"className"===g?b.setAttribute("class",i):b.setAttribute(g,i):"value"===g&&"input"===c?b.value!==i&&(b.value=i):g in b?b[g]=i:b.setAttribute(g,i)}}return e}function e(a){for(var b=0;b0&&("GET"==a.method?a.url=a.url+(a.url.indexOf("?")<0?"?":"&")+o(b):a.data=c(b)),a}function q(a,b){var c=a.match(/:[a-z]\w+/gi);if(c&&b)for(var d=0;de?y.push(b)-1:e,g=b==a.document||b==a.document.documentElement?x:b;z[f]=c(g,null,d,z[f],!1,0)},b.trust=function(a){return a=new String(a),a.$trusted=!0,a};var A=[],B=[],C=[],D=0,E=0,F=0,G=null;b.module=function(a,c){b.startComputation();var d=A.indexOf(a);0>d&&(d=A.length),A[d]=a,B[d]=c,C[d]=new c.controller,b.endComputation()},b.redraw=function(){if(D=a.performance&&a.performance.now?a.performance.now():(new a.Date).getTime(),D-E>16)i();else{var b=a.cancelAnimationFrame||a.clearTimeout,c=a.requestAnimationFrame||a.setTimeout;b(F),F=c(i,0)}};var H=0;b.startComputation=function(){H++},b.endComputation=function(){H=Math.max(H-1,0),0==H&&b.redraw()},b.withAttr=function(a,b){return function(c){b(a in c.currentTarget?c.currentTarget[a]:c.currentTarget.getAttribute(a))}};var I,J={pathname:"",hash:"#",search:"?"},K=function(){},L={};return b.route=function(){if(0===arguments.length)return I;if(3===arguments.length){I=a.location[b.route.mode].slice(J[b.route.mode].length);var c=arguments[0],d=arguments[1],e=arguments[2];K=function(a){var f=a.slice(J[b.route.mode].length);j(c,e,f)||b.route(d,!0)};var f="hash"==b.route.mode?"onhashchange":"onpopstate";a[f]=function(){K(a.location[b.route.mode])},G=l,a[f]()}else if(arguments[0].addEventListener){var g=arguments[0],h=arguments[1];g.href=J[b.route.mode]+g.pathname,h||(g.removeEventListener("click",k),g.addEventListener("click",k))}else if("string"==typeof arguments[0]){I=arguments[0];var i=arguments[1]===!0;a.history.pushState?(G=function(){a.history[i?"replaceState":"pushState"](null,a.document.title,J[b.route.mode]+I),l()},K(J[b.route.mode]+I)):a.location[b.route.mode]=I}},b.route.param=function(a){return L[a]},b.route.mode="search",b.prop=function(a){var b=function(){return arguments.length&&(a=arguments[0]),a};return b.toJSON=function(){return a},b},b.deferred=function(){var a=[],c=[],d={resolve:function(b){for(var c=0;c
+```
+
---
You can define a non-HTML-standard attribute called `config`. This special parameter allows you to call methods on the DOM element after it gets created.
diff --git a/mithril.js b/mithril.js
index 06685a0f..f07d8197 100644
--- a/mithril.js
+++ b/mithril.js
@@ -211,7 +211,7 @@ Mithril = m = new function app(window) {
return value
}
- var roots = [], modules = [], controllers = [], now = 0, lastRedraw = 0, lastRedrawId = 0
+ var roots = [], modules = [], controllers = [], now = 0, lastRedraw = 0, lastRedrawId = 0, computePostRedrawHook = null
m.module = function(root, module) {
m.startComputation()
var index = roots.indexOf(root)
@@ -235,20 +235,18 @@ Mithril = m = new function app(window) {
for (var i = 0; i < roots.length; i++) {
m.render(roots[i], modules[i].view(controllers[i]))
}
+ if (computePostRedrawHook) {
+ computePostRedrawHook()
+ computePostRedrawHook = null
+ }
lastRedraw = now
}
- var pendingRequests = 0, computePostRedrawHook = null
+ var pendingRequests = 0
m.startComputation = function() {pendingRequests++}
m.endComputation = function() {
pendingRequests = Math.max(pendingRequests - 1, 0)
- if (pendingRequests == 0) {
- m.redraw()
- if (computePostRedrawHook) {
- computePostRedrawHook()
- computePostRedrawHook = null
- }
- }
+ if (pendingRequests == 0) m.redraw()
}
m.withAttr = function(prop, withAttrCallback) {
@@ -279,6 +277,7 @@ Mithril = m = new function app(window) {
else if (arguments[0].addEventListener) {
var element = arguments[0]
var isInitialized = arguments[1]
+ element.href = modes[m.route.mode] + element.pathname
if (!isInitialized) {
element.removeEventListener("click", routeUnobtrusive)
element.addEventListener("click", routeUnobtrusive)
@@ -316,8 +315,9 @@ Mithril = m = new function app(window) {
}
}
function routeUnobtrusive(e) {
+ if (e.ctrlKey || e.metaKey || e.which == 2) return
e.preventDefault()
- m.route(e.currentTarget.getAttribute("href"))
+ m.route(e.currentTarget[m.route.mode].slice(modes[m.route.mode].length))
}
function scrollToHash() {
if (m.route.mode != "hash" && window.location.hash) window.location.hash = window.location.hash
diff --git a/tests/mithril-tests.js b/tests/mithril-tests.js
index 7b95b041..345226d5 100644
--- a/tests/mithril-tests.js
+++ b/tests/mithril-tests.js
@@ -330,7 +330,7 @@ function testMithril(mock) {
//m.redraw
test(function() {
- mock.performance.$elapse(50)
+ mock.performance.$elapse(50) //setup
var controller
var root = mock.document.createElement("div")
m.module(root, {
@@ -342,11 +342,11 @@ function testMithril(mock) {
var lengthBefore = root.childNodes.length
mock.performance.$elapse(50)
m.redraw()
- mock.performance.$elapse(50)
+ mock.performance.$elapse(50) //teardown
return lengthBefore === 0 && root.childNodes[0].nodeValue === "foo"
})
test(function() {
- mock.performance.$elapse(50)
+ mock.performance.$elapse(50) //setup
var count = 0
var root = mock.document.createElement("div")
m.module(root, {
@@ -360,13 +360,13 @@ function testMithril(mock) {
m.redraw()
mock.performance.$elapse(50)
m.redraw()
- mock.performance.$elapse(50)
+ mock.performance.$elapse(50) //teardown
return count === 2
})
//m.route
test(function() {
- mock.performance.$elapse(50)
+ mock.performance.$elapse(50) //setup
mock.location.search = "?"
var root = mock.document.createElement("div")
@@ -374,10 +374,11 @@ function testMithril(mock) {
m.route(root, "/test1", {
"/test1": {controller: function() {}, view: function() {return "foo"}}
})
+ mock.performance.$elapse(50) //teardown
return mock.location.search == "?/test1" && root.childNodes[0].nodeValue === "foo"
})
test(function() {
- mock.performance.$elapse(50)
+ mock.performance.$elapse(50) //setup
mock.location.pathname = "/"
var root = mock.document.createElement("div")
@@ -385,10 +386,11 @@ function testMithril(mock) {
m.route(root, "/test2", {
"/test2": {controller: function() {}, view: function() {return "foo"}}
})
+ mock.performance.$elapse(50) //teardown
return mock.location.pathname == "/test2" && root.childNodes[0].nodeValue === "foo"
})
test(function() {
- mock.performance.$elapse(50)
+ mock.performance.$elapse(50) //setup
mock.location.hash = "#"
var root = mock.document.createElement("div")
@@ -396,10 +398,11 @@ function testMithril(mock) {
m.route(root, "/test3", {
"/test3": {controller: function() {}, view: function() {return "foo"}}
})
+ mock.performance.$elapse(50) //teardown
return mock.location.hash == "#/test3" && root.childNodes[0].nodeValue === "foo"
})
test(function() {
- mock.performance.$elapse(50)
+ mock.performance.$elapse(50) //setup
mock.location.search = "?"
var root = mock.document.createElement("div")
@@ -407,10 +410,11 @@ function testMithril(mock) {
m.route(root, "/test4/foo", {
"/test4/:test": {controller: function() {}, view: function() {return m.route.param("test")}}
})
+ mock.performance.$elapse(50) //teardown
return mock.location.search == "?/test4/foo" && root.childNodes[0].nodeValue === "foo"
})
test(function() {
- mock.performance.$elapse(50)
+ mock.performance.$elapse(50) //setup
mock.location.search = "?"
var module = {controller: function() {}, view: function() {return m.route.param("test")}}
@@ -422,13 +426,14 @@ function testMithril(mock) {
"/test5/:test": module
})
var paramValueBefore = m.route.param("test")
+ mock.performance.$elapse(50)
m.route("/")
var paramValueAfter = m.route.param("test")
-
+ mock.performance.$elapse(50) //teardown
return mock.location.search == "?/" && paramValueBefore === "foo" && paramValueAfter === undefined
})
test(function() {
- mock.performance.$elapse(50)
+ mock.performance.$elapse(50) //setup
mock.location.search = "?"
var module = {controller: function() {}, view: function() {return m.route.param("a1")}}
@@ -440,13 +445,15 @@ function testMithril(mock) {
"/test6/:a1": module
})
var paramValueBefore = m.route.param("a1")
+ mock.performance.$elapse(50)
m.route("/")
var paramValueAfter = m.route.param("a1")
+ mock.performance.$elapse(50) //teardown
return mock.location.search == "?/" && paramValueBefore === "foo" && paramValueAfter === undefined
})
test(function() {
//https://github.com/lhorie/mithril.js/issues/61
- mock.performance.$elapse(50)
+ mock.performance.$elapse(50) //setup
mock.location.search = "?"
var module = {controller: function() {}, view: function() {return m.route.param("a1")}}
@@ -458,8 +465,10 @@ function testMithril(mock) {
"/test7/:a1": module
})
var routeValueBefore = m.route()
+ mock.performance.$elapse(50)
m.route("/")
var routeValueAfter = m.route()
+ mock.performance.$elapse(50) //teardown
return routeValueBefore === "/test7/foo" && routeValueAfter === "/"
})