boa-handler-history
Version:
A b-o-a handler for History API
33 lines (32 loc) • 1 kB
JavaScript
;
var History = (function () {
function History(callback) {
this.callback = callback;
this.window = Function('return this')();
this.history = this.window.history;
}
History.prototype.back = function () {
if (this.history) {
this.history.back();
}
};
History.prototype.go = function (path, replace) {
if (replace === void 0) { replace = false; }
if (this.history) {
var f = replace ? history.replaceState : history.pushState;
f.apply(history, [null, null, path]); // TODO: state
}
this.callback(path);
};
History.prototype.start = function () {
var _this = this;
if (this.history) {
this.window.addEventListener('popstate', function () {
var path = _this.window.location.pathname;
_this.callback(path);
}, false);
}
};
return History;
}());
exports.History = History;