Skip to content

Instantly share code, notes, and snippets.

@pauginer
Last active August 29, 2015 14:04
Show Gist options
  • Save pauginer/076a6d314dc76dedc893 to your computer and use it in GitHub Desktop.
Save pauginer/076a6d314dc76dedc893 to your computer and use it in GitHub Desktop.
Scene transitions where updateState is called can be navigated back using the browser "back" button.
var hash = window.location.hash;
if(hash.length != 0){
window.location.hash="";
}
jQuery(document).ready(function($) {
if (window.history && window.history.pushState) {
$(window).on('popstate', function() {
var hash = window.location.hash;
var sceneName=hash.replace('#','');
var hypeDocument = HYPE.documents['index']
if(hash.length == 0){sceneName = hypeDocument.sceneNames()[0]; }
hypeDocument.showSceneNamed(sceneName, hypeDocument.kSceneTransitionInstant);
});
}
});
function updateState(){ //Should be called AFTER jumping to the scene.
var hypeDocument = HYPE.documents['index']
var sceneName = hypeDocument.currentSceneName();
window.history.pushState('forward', null, '#'+sceneName);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment