Skip to content

Instantly share code, notes, and snippets.

@anutron
Created January 26, 2010 07:28
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anutron/286636 to your computer and use it in GitHub Desktop.
Save anutron/286636 to your computer and use it in GitHub Desktop.
(function(){
var supported;
if (document.body.setAttribute) {
var el = document.createElement('div');
el.setAttribute('onhashchange','return;');
supported = typeof el.onhashchange == 'function';
} else {
supported = 'onhashchange' in document.documentElement;
}
if (!supported) {
Element.Events.hashchange = {
duration: 250,
onAdd: function(){
if (!Element.Events.hashchange.timer) {
Element.Events.hashchange.timer = (function(){
if (location.hash && location.hash != Element.Events.hashchange.state) {
Element.Events.hashchange.state = location.hash;
window.fireEvent('hashchange', new Event({
bubbles: false,
cancelable: false,
currentTarget: window,
eventPhase: 2,
explicitOriginalTarget: document.getElementsByTagName('html')[0],
originalTarget: window,
target: window,
timeStamp: $time(),
type: "hashchange"
}));
}
}).periodical(Element.Events.hashchange.duration)
}
}
}
}
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment