using history.pushState instead of location change in courtesy of @medikoo

This commit is contained in:
Bartek Szopka
2012-03-06 21:11:08 +01:00
parent 3fceded114
commit 45fcf19c4d

View File

@@ -97,7 +97,7 @@
var getElementFromUrl = function () { var getElementFromUrl = function () {
// get id from url # by removing `#` or `#/` from the beginning, // get id from url # by removing `#` or `#/` from the beginning,
// so both "fallback" `#slide-id` and "enhanced" `#/slide-id` will work // so both `#slide-id` and "legacy" `#/slide-id` will work
return byId( window.location.hash.replace(/^#\/?/,"") ); return byId( window.location.hash.replace(/^#\/?/,"") );
}; };
@@ -252,15 +252,13 @@
root.className = "step-" + el.id; root.className = "step-" + el.id;
// `#/step-id` is used instead of `#step-id` to prevent default browser // Setting fragment URL with `history.pushState`
// scrolling to element in hash // and it has to be set after animation finishes, because in Chrome it
//
// and it has to be set after animation finishes, because in chrome it
// causes transtion being laggy // causes transtion being laggy
// BUG: http://code.google.com/p/chromium/issues/detail?id=62820 // BUG: http://code.google.com/p/chromium/issues/detail?id=62820
window.clearTimeout( hashTimeout ); window.clearTimeout( hashTimeout );
hashTimeout = window.setTimeout(function () { hashTimeout = window.setTimeout(function () {
window.location.hash = "#/" + el.id; history.pushState({}, '', '#' + el.id);
}, 1000); }, 1000);
var target = { var target = {