Skip to content

Instantly share code, notes, and snippets.

@apeckham
Created April 26, 2010 17:53
Show Gist options
  • Save apeckham/379647 to your computer and use it in GitHub Desktop.
Save apeckham/379647 to your computer and use it in GitHub Desktop.
location.hash history for prototype
var LocationHash = Class.create({
currentHash: "",
initialize: function(proxy) {
this.proxy = proxy || {
get: function() {
return location.hash;
},
set: function(value) {
location.hash = value;
}
};
},
watch: function(callback) {
setInterval(function() {
var pageHash = this.get();
if (pageHash != this.currentHash) {
this.currentHash = pageHash;
callback(pageHash);
}
}.bind(this), 100);
},
set: function(value) {
this.currentHash = value;
this.proxy.set("#" + value);
},
get: function() {
return this.proxy.get().substring(1);
},
empty: function() {
return this.get() == "";
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment