Skip to content

Commit

Permalink
First version complete.
Browse files Browse the repository at this point in the history
  • Loading branch information
balupton committed Jan 22, 2011
1 parent aadfa61 commit f2ac286
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 13 deletions.
56 changes: 52 additions & 4 deletions README.md
Expand Up @@ -4,10 +4,9 @@ Welcome to History.js
This project is the successor of jQuery History, it aims to:

- Support HTML5's State Management
- Provide a backwards compatible experience for Browsers which do not support HTML5's State Management
- Provide a backwards compatible experience for Browsers which do not support HTML4's OnHashChange
- Provide a backwards compatible experience for Browsers which do not support HTML5's State Management *- including continued support replaceState, and data storage*
- Provide a backwards compatible experience for Browsers which do not support HTML4's OnHashChange *- including continued support for traditional anchors*
- Follow the original API's as much as possible
- Support for traditional anchors *- yet to complete*
- Support as many javascript frameworks as possible via adapters.

Licensed under the New BSD License, Copyright 2011 Benjamin Arthur Lupton <contact@balupton.com>
Expand Down Expand Up @@ -36,6 +35,42 @@ Licensed under the New BSD License, Copyright 2011 Benjamin Arthur Lupton <conta

})(window);

## Installation

1. Download History.js and upload it to your webserver. Download links: [tar.gz](https://github.com/balupton/History.js/tarball/master) or [zip](https://github.com/balupton/History.js/zipball/master)

2. Include [JSON2](http://www.json.org/js.html) for HTML4 Browsers Only *(replace www.yourwebsite.com)*

<script type="text/javascript">
if ( typeof JSON === 'undefined' ) {
var
url = 'http://www.yourwebsite.com/history.js/scripts/compressed/json2.min.js',
scriptEl = document.createElement('script');
scriptEl.type = 'text/javascript';
scriptEl.src = url;
document.body.appendChild(scriptEl);
}
</script>

3. Include the Adapter for your Framework:

- jQuery

<script type="text/javascript" src="http://www.yourwebsite.com/history.js/scripts/compressed/history.adapter.jquery.min.js"></script>

- Mootools

<script type="text/javascript" src="http://www.yourwebsite.com/history.js/scripts/compressed/history.adapter.mootools.min.js"></script>

- Prototype

<script type="text/javascript" src="http://www.yourwebsite.com/history.js/scripts/compressed/history.adapter.prototype.min.js"></script>

4. Include History.js

<script type="text/javascript" src="http://www.yourwebsite.com/history.js/scripts/compressed/history.min.js"></script>


## Explanation

We create the new namespace `window.History` instead of extending the exiting namespace `window.history` (capitalisation), as each framework handles the events a little bit so we cannot guarantee full compatibility with the original spec. This is shown in the above code by using `History.getState().data` instead of `event.state`, which is actually more powerful as we have access to that state's title and url as well. As such, extending the inbuilt `window.history` would cause discrepancies.
Expand All @@ -53,14 +88,27 @@ We create the new namespace `window.History` instead of extending the exiting na
- Prototype
- MooTools

> If your favourite framework is not included? Then just write an adapter for it, and send it to us :-) Easy peasy.
## Browsers

### Tested In
### Tested and Working In:

- Chrome 8
- Opera 10,11
- Safari 5
- Firefox 4 Beta 9
- Firefox 3
- IE 6,7,8


## Todo

- Support traditional anchors
- Degradation of the HTML5 States perhaps could be more graceful. Will need to:
- Evaluate the behaviour of the `data` stored in states with HTML5. Discover if it persists once the page is closed then re-opened.
- If it persists: use cookies
- If it doesn't then we don't need to do url serialisation (current solutions).
- Alternatively, we could support url serialisation for both HTML5 and HTML4 browsers to ensure the state of the page always persists in it's full entirety.
- HTML5 could have `data` and `title` passed as querystring.
- Will need to decide on best way forward, feedback welcome! contact@balupton.com
4 changes: 2 additions & 2 deletions demo/index.php
Expand Up @@ -25,9 +25,9 @@
</head>
<body>
<script type="text/javascript">
if ( typeof JSON === "undefined" ) {
if ( typeof JSON === 'undefined' ) {
var
url = './scripts/json2.min.js',
url = '../scripts/uncompressed/json2.js',
scriptEl = document.createElement('script');
scriptEl.type = 'text/javascript';
scriptEl.src = url;
Expand Down
7 changes: 0 additions & 7 deletions demo/scripts/json2.min.js

This file was deleted.

0 comments on commit f2ac286

Please sign in to comment.