Permalink
Browse files

Add attach/detach methods.

  • Loading branch information...
1 parent 9503f18 commit c140c848c9a8d53858dc4d317e93abdd2aa9ffdf @cpojer committed Oct 17, 2012
Showing with 14 additions and 6 deletions.
  1. +14 −6 Source/History.js
View
@@ -32,23 +32,31 @@ var events = Element.NativeEvents,
hasPushState = ('pushState' in history),
event = hasPushState ? 'popstate' : 'hashchange';
+events[event] = hasPushState ? 2 : 1;
+
var History = module.exports = new new Class({
Implements: [Class.Binds, Events],
- initialize: hasPushState ? function(){
- events[event] = 2;
- window.addEvent(event, this.bound('pop'));
- } : function(){
- events[event] = 1;
- window.addEvent(event, this.bound('pop'));
+ initialize: function(){
+ this.attach();
+
+ if (hasPushState) return;
this.hash = location.hash;
var hashchange = ('onhashchange' in window);
if (!(hashchange && (document.documentMode === undefined || document.documentMode > 7)))
this.timer = this.check.periodical(200, this);
},
+ attach: function() {
+ window.addEvent(event, this.bound('pop'));
+ },
+
+ detach: function() {
+ window.removeEvent(event, this.bound('pop'));
+ },
+
cleanURL: cleanURL,
push: hasPushState ? function(url, title, state){

0 comments on commit c140c84

Please sign in to comment.