Created
July 27, 2011 13:51
-
-
Save mtrpcic/1109398 to your computer and use it in GitHub Desktop.
HTML5 Fallback Ideas
This file contains hidden or 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
// PathJS supports both the Hashtag and HTML5 History API now. Some users would like it to automatically fall back to the Hashtag if | |
// the history API is not supported. Obviously, this can't be the default, as some users want the site to work in browsers with JavaScript | |
// turned off, and will only use the History API to add transitions and effects to their site. | |
// | |
// When using the Hashtag implementation, users must define their routes, and then make sure that they tell PathJS to listen for state changes | |
// by calling the appropriate method: | |
Path.listen(); | |
// The `Path.listen()` method is not required when doing HTML5 History API calls, as we have a wrapper method that wraps the native | |
// `window.history.pushState()` methods. This method wraps regular pushState calls, and invokes the PathJS router: | |
Path.history.pushState(state, title, new_path); | |
// There is only one method required to implement the HTML5 History implementation, and as seen above, it is namespaced to the `history` | |
// object. | |
// | |
// To support automatic fallback to the hash when HTML5 is not supported, three things need to happen: | |
// 1. All routes defined that do not use the hashtag need to be converted to use it. | |
// 2. An attribute needs to be set to inform `Path.history.pushState` methods that they should change the Hashtag in some situations | |
// 3. A Hash Change listener needs to be started to respond to these changing events | |
// | |
// Rather than making the user explicitly set an internal PathJS attribute, followed by calling the regular Hashtag listener, I would | |
// like to encapsulate that in one method. I'm unsure if I should just add this to the regular `Path.listen()` method: | |
Path.listen(true) // Pass `true` into the `listen` method to enable graceful fallback | |
// Or if it should be a new method that is namespaced to the `history` object, similar to the `pushState` method: | |
Path.history.listen() // Call the `Path.history.listen()` method to enable graceful fallback | |
// Or is there something else that should be done? | |
// Please leave comments. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment