Skip to content

Instantly share code, notes, and snippets.

@xergio
Created December 5, 2011 15:37
Show Gist options
  • Save xergio/1433987 to your computer and use it in GitHub Desktop.
Save xergio/1433987 to your computer and use it in GitHub Desktop.
Mootools event hashchange
/*
Original: https://github.com/greggoryhz/MooTools-onHashChange-Event
Example:
window.addEvent('hashchange', function(hash) { console.log(hash); });
*/
Element.Events.hashchange = {
onAdd: function(fn) {
var hash = location.hash;
var hashchange = function () {
if (hash == location.hash) return;
hash = location.hash;
var hash_real = (hash.indexOf('#') == 0 ? hash.substr(1): hash);
fn.call(this, hash_real);
};
if ("onhashchange" in window)
window.onhashchange = hashchange;
else
hashchange.periodical(50);
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment