Permalink
Browse files

hash:changed inspired by http://github.com/nakajima/nakatype/tree/mas…

  • Loading branch information...
1 parent 11e4a91 commit 8fd2f39af026d490cdd46f12e16df8dd8cbc2d5a kangax committed May 16, 2008
Showing with 13 additions and 0 deletions.
  1. +13 −0 hash_changed.js
View
@@ -0,0 +1,13 @@
+// inspired by nakajima's http://github.com/nakajima/nakatype/tree/master/src/event_hash_changed.js
+// Fires hash:changed event when document.location.hash changes
+// oldValue and newValue are passed as properties of event's memo
+
+(function(){
+ var loc = document.location, hash = loc.hash;
+ this.setInterval(function(){
+ if (loc.hash != current) {
+ document.fire('hash:changed', { oldValue: current, newValue: loc.hash })
@nakajima
nakajima May 16, 2008

Nice touch to include the oldValue. I like it.

+ current = loc.hash;
+ }
+ }, 200)
+})().call(null)
@nakajima
nakajima May 16, 2008

Hey, if you don’t mind me asking, what does the “.call(null)” do here?

1 comment on commit 8fd2f39

@kangax
Owner
kangax commented on 8fd2f39 May 16, 2008

It invokes anonymous function within a global context – usually “window” object in browsers (but works safely when it’s not available).

Please sign in to comment.