Last active
June 23, 2018 19:54
-
-
Save caiw/1e582077dab2de4286e890517b71054e to your computer and use it in GitHub Desktop.
Link to a specific scene in a Tumult Hype document
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function check_for_deeplinks(hypeDocument, element, event) { | |
/* | |
Allows "deep" linking from an external page into a specific scene in a Tumult Hype document. | |
To use, put this on the first frame of the first scene in the Hype document. | |
Then, set the link url to `my-hype-document.html#my-scene-name`, to go to the scene named | |
"my-scene-name". | |
*/ | |
// Look for a hash in the url | |
var hash = window.location.hash.substring(1); | |
// Once the hash is found, remove it from the url so you can return to the first scene again | |
// in future without redirecting again. | |
history.pushState("", document.title, window.location.pathname); | |
// Go through each scene to find the one whose name matches the hash | |
for(var i = 0; i < hypeDocument.sceneNames().length; i++) { | |
if(hypeDocument.sceneNames()[i] == hash) { | |
// Go to the scene once you've found it | |
hypeDocument.showSceneNamed(hash); | |
break; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment