Created
August 13, 2008 11:50
-
-
Save sunny/5231 to your computer and use it in GitHub Desktop.
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
/* | |
* hash_change_listener(hash_check_interval) | |
* | |
* Prototype method for launching a "hash:change" custom event when the | |
* page's #anchor changes. | |
* | |
* Examples: adding a class to the current page anchor. | |
* | |
* document.observe('hash:change', function(event) { | |
* var div = $(window.location.hash.replace(/^#/, '')) | |
* if (div) { | |
* $$('.current_anchor').invoke('removeClassName', 'current_anchor') | |
* div.addClassName('current_anchor') | |
* } | |
* }) | |
* | |
* hash_change_listener(300) | |
*/ | |
function hash_change_listener(hash_check_interval) { | |
var hash_current = null | |
var fire_on_change = function() { | |
if (window.location.hash != hash_current) { | |
document.fire('hash:change') | |
hash_current = window.location.hash | |
} | |
} | |
fire_on_change() | |
return setInterval(fire_on_change, hash_check_interval) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment