Reset our scroll position if we change our hash to "#".

Changing the hash to "#" causes Chrome to jump to the top of the page
on Mac OS X. This commit doesn't actually fix any bug, but it
is necessary for my *next* commit, where otherwise you'd have to
ensure that the scroll code came *after* the hashchange code.

(imported from commit 925b44d770c96dafaabebc9e0114f9a3b8f53c4d)
This commit is contained in:
Waseem Daher 2013-01-10 11:21:19 -05:00
parent 1141bfa888
commit a9112155da
1 changed files with 4 additions and 3 deletions

View File

@ -6,16 +6,17 @@ var expected_hash = false;
exports.changehash = function (newhash) {
expected_hash = newhash;
// Some browsers reset scrollTop when changing the hash to "",
// Some browsers reset scrollTop when changing the hash
// to "" or "#" (Mac Chrome, for example)
// so we save and restore it.
// http://stackoverflow.com/questions/4715073/window-location-hash-prevent-scrolling-to-the-top
var scrolltop;
if (newhash === "") {
if (newhash === "" || newhash === "#") {
scrolltop = viewport.scrollTop();
}
window.location.hash = newhash;
util.reset_favicon();
if (newhash === "") {
if (newhash === "" || newhash === "#") {
viewport.scrollTop(scrolltop);
}
};