diff --git a/mithril.js b/mithril.js index 8d6268d7..6f87333b 100644 --- a/mithril.js +++ b/mithril.js @@ -360,7 +360,7 @@ Mithril = m = new function app(window) { redirect(window.location[m.route.mode]) } } - computePostRedrawHook = scrollToHash + computePostRedrawHook = setScroll window[listener]() currentRoute = normalizeRoute(window.location[m.route.mode]) } @@ -385,7 +385,7 @@ Mithril = m = new function app(window) { if (window.history.pushState) { computePostRedrawHook = function() { window.history[shouldReplaceHistoryEntry ? "replaceState" : "pushState"](null, window.document.title, modes[m.route.mode] + currentRoute) - scrollToHash() + setScroll() } redirect(modes[m.route.mode] + currentRoute) } @@ -425,8 +425,9 @@ Mithril = m = new function app(window) { e.preventDefault() m.route(e.currentTarget[m.route.mode].slice(modes[m.route.mode].length)) } - 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 = [] diff --git a/tests/mock.js b/tests/mock.js index 808f1da7..f39b3d6d 100644 --- a/tests/mock.js +++ b/tests/mock.js @@ -70,6 +70,7 @@ mock.window = new function() { this.childNodes.splice(index, 1) child.parentNode = null } + window.scrollTo = function() {} window.performance = new function () { var timestamp = 50 this.$elapse = function(amount) {timestamp += amount}