Skip to content

Instantly share code, notes, and snippets.

@lamchau
Created April 2, 2015 20:27
Show Gist options
  • Select an option

  • Save lamchau/0111768220259868c622 to your computer and use it in GitHub Desktop.

Select an option

Save lamchau/0111768220259868c622 to your computer and use it in GitHub Desktop.
(function(History) {
if (!Ember.Object.detectInstance(History)) {
throw new Error("Native `Ember.History` is already defined.");
}
if (Ember.Evented.detect(History)) {
return;
} else {
History.reopen(Ember.Evented);
}
History.reopen({
back: function() {
window.history.go(-1);
},
forward: function() {
window.history.go(1);
},
go: function(count) {
// most likely an error, explicitly use reload when we mean it
if (count === 0) {
throw new Ember.Error("Use `window.location.reload()` instead");
}
Ember.assert("Count must be an integer", Math.round(count) === count);
window.history.go(count);
this.trigger("go", count);
},
pushState: function(state, title, url) {
window.history.pushState(state, title, url);
this.trigger("pushState", state, title, url);
},
replaceState: function(state, title, url) {
window.history.replaceState(state, title, url);
this.trigger("replaceState", state, title, url);
}
});
})(Ember.History || (Ember.History = Ember.Object.create()));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment