Deeplink Easy-peasy deeplinking manager
Deeplink is a small utility for working with deeplinks.
Implementation
<script src="js/jquery-1.7.1.min.js"></script>
<script src="js/deeplink-0.1.22-min.js"></script>
Documentation is available here.
Usage
Each new Deeplink instance is a new object monitoring the window.onhashchange event (or a custom monitoring function for older browsers). This is the simplest way to call the constructor:
var d = new Deeplink();
You may also specify strings for the hash equality and separator values:
var d = new Deeplink(":", ",");
.hashchange
Every "hashchange" event triggers a "deeplink" event on the Deeplink instance. Any functions that need information from this event should be bound to the instance. These functions receive two arguments: a jQuery Event, and a data object with the data.hash string and a data.map key-value object:
var d = new Deeplink();
var goto = function (e, data) {
var hash = data.hash;
var map = data.map;
};
$(d).bind("deeplink", goto);
.hashupdate
One other method to note is "hashupdate". If your code updates the state of the page in a way that needs to be referenced by a deeplink, you may pass a key-value object into this method to update the page URL. This method has three parameters:
- map: The key-value object that updates the hash parameters
- replace: A boolean that specifies whether the entire hash should be replaced
- fire: A boolean that specifies whether this update should trigger a deeplink event on this instance
Sample usage:
var d = new Deeplink();
var changePanel = function (id) {
// do stuff to change the panel
d.hashupdate({"panel", id});
};
changePanel(4);
Deeplink.setDelay
A final method to review is Deeplink.setDelay, which allows you to modify the timeout length between hash checks in browsers that don't support the window.onhashchange event:
Deeplink.setDelay(500); // in milliseconds
Dependencies
jQuery 1.7+
Contributing
- Fork the project.
- Read through the outstanding issues or report new ones.
- Write some tests to make sure we don't accidentally break each other's code.
- Send a pull request.
License
Download
The latest release, 0.1.22 is available here.
You can download this project in either zip or tar formats.
You can also clone the project with Git by running:
$ git clone git://github.com/draeton/deeplink