File: //usr/share/nodejs/turbolinks/src/turbolinks/history.js
// Generated by CoffeeScript 1.12.8
(function() {
var bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; };
Turbolinks.History = (function() {
function History(delegate) {
this.delegate = delegate;
this.onPageLoad = bind(this.onPageLoad, this);
this.onPopState = bind(this.onPopState, this);
}
History.prototype.start = function() {
if (!this.started) {
addEventListener("popstate", this.onPopState, false);
addEventListener("load", this.onPageLoad, false);
return this.started = true;
}
};
History.prototype.stop = function() {
if (this.started) {
removeEventListener("popstate", this.onPopState, false);
removeEventListener("load", this.onPageLoad, false);
return this.started = false;
}
};
History.prototype.push = function(location, restorationIdentifier) {
location = Turbolinks.Location.wrap(location);
return this.update("push", location, restorationIdentifier);
};
History.prototype.replace = function(location, restorationIdentifier) {
location = Turbolinks.Location.wrap(location);
return this.update("replace", location, restorationIdentifier);
};
History.prototype.onPopState = function(event) {
var location, ref, restorationIdentifier, turbolinks;
if (this.shouldHandlePopState()) {
if (turbolinks = (ref = event.state) != null ? ref.turbolinks : void 0) {
location = Turbolinks.Location.wrap(window.location);
restorationIdentifier = turbolinks.restorationIdentifier;
return this.delegate.historyPoppedToLocationWithRestorationIdentifier(location, restorationIdentifier);
}
}
};
History.prototype.onPageLoad = function(event) {
return Turbolinks.defer((function(_this) {
return function() {
return _this.pageLoaded = true;
};
})(this));
};
History.prototype.shouldHandlePopState = function() {
return this.pageIsLoaded();
};
History.prototype.pageIsLoaded = function() {
return this.pageLoaded || document.readyState === "complete";
};
History.prototype.update = function(method, location, restorationIdentifier) {
var state;
state = {
turbolinks: {
restorationIdentifier: restorationIdentifier
}
};
return history[method + "State"](state, null, location);
};
return History;
})();
}).call(this);