Created
April 26, 2010 17:53
-
-
Save apeckham/379647 to your computer and use it in GitHub Desktop.
location.hash history for prototype
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
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