Improved url / hash change handling

This commit is contained in:
David Baker 2015-10-05 15:32:34 +01:00
parent 61f951a33e
commit 490e56bfbb
1 changed files with 12 additions and 4 deletions

View File

@ -53,15 +53,19 @@ function onHashChange(ev) {
} }
var loaded = false; var loaded = false;
var lastLoadedScreen = null;
// This will be called whenever the SDK changes screens, // This will be called whenever the SDK changes screens,
// so a web page can update the URL bar appropriately. // so a web page can update the URL bar appropriately.
var onNewScreen = function(screen) { var onNewScreen = function(screen) {
if (!loaded) return; if (!loaded) {
lastLoadedScreen = screen;
} else {
var hash = '#/' + screen; var hash = '#/' + screen;
lastLocationHashSet = hash; lastLocationHashSet = hash;
window.location.hash = hash; window.location.hash = hash;
} }
}
// We use this to work out what URL the SDK should // We use this to work out what URL the SDK should
// pass through when registering to allow the user to // pass through when registering to allow the user to
@ -85,5 +89,9 @@ window.addEventListener('hashchange', onHashChange);
window.onload = function() { window.onload = function() {
routeUrl(window.location); routeUrl(window.location);
loaded = true; loaded = true;
if (lastLoadedScreen) {
onNewScreen(lastLoadedScreen);
lastLoadedScreen = null;
}
} }