From eb9720656e6037e8ef2dc0687ea5dc4e84021844 Mon Sep 17 00:00:00 2001 From: Leo Horie Date: Tue, 4 Nov 2014 21:41:39 -0500 Subject: [PATCH] #319 fix dynamic link w/ config:m.route --- mithril.js | 12 ++++++------ tests/mithril-tests.js | 1 - 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/mithril.js b/mithril.js index f08f8b52..96dc3db9 100644 --- a/mithril.js +++ b/mithril.js @@ -539,6 +539,7 @@ Mithril = m = new function app(window, undefined) { var modes = {pathname: "", hash: "#", search: "?"} var redirect = function() {}, routeParams = {}, currentRoute m.route = function() { + //m.route() if (arguments.length === 0) return currentRoute else if (arguments.length === 3 && isStr(arguments[1])) { var root = arguments[0], defaultRoute = arguments[1], router = arguments[2] @@ -557,17 +558,16 @@ Mithril = m = new function app(window, undefined) { computePostRedrawHook = setScroll window[listener]() } + //config: m.route else if (arguments[0].addEventListener) { var element = arguments[0] var isInitialized = arguments[1] var context = arguments[2] - if (!isInitialized) { - context.href = element.getAttribute("href") - element.href = (m.route.mode !== 'pathname' ? window.location.pathname : '') + modes[m.route.mode] + context.href - element.removeEventListener("click", routeUnobtrusive) - element.addEventListener("click", routeUnobtrusive) - } + element.href = (m.route.mode !== 'pathname' ? window.location.pathname : '') + modes[m.route.mode] + this.attrs.href + element.removeEventListener("click", routeUnobtrusive) + element.addEventListener("click", routeUnobtrusive) } + //m.route(route) else if (isStr(arguments[0])) { currentRoute = arguments[0] var querystring = isObj(arguments[1]) ? buildQueryString(arguments[1]) : null diff --git a/tests/mithril-tests.js b/tests/mithril-tests.js index 0c48f068..56c73b52 100644 --- a/tests/mithril-tests.js +++ b/tests/mithril-tests.js @@ -1642,7 +1642,6 @@ function testMithril(mock) { test(function() { var prop = m.request({method: "GET", url: "test"}) mock.XMLHttpRequest.$instances.pop().onreadystatechange() - console.log(prop()) return prop().method === "GET" && prop().url === "test" }) test(function() {