scroll to top on route
This commit is contained in:
parent
4aad8619c5
commit
81f3367be9
2 changed files with 5 additions and 3 deletions
|
|
@ -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 = []
|
||||
|
|
|
|||
|
|
@ -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}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue