Skip to content

Instantly share code, notes, and snippets.

@andrewdeandrade
Created February 5, 2012 23:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save andrewdeandrade/1748421 to your computer and use it in GitHub Desktop.
Save andrewdeandrade/1748421 to your computer and use it in GitHub Desktop.
Backbone.History
Backbone.History.prototype.urlHistory = {
stack: [],
currentIndex: 0,
current: function() {
return this.stack[this.currentIndex];
},
previous: function() {
return this.stack[this.currentIndex - 1];
},
next: function() {
return this.stack[this.currentIndex + 1];
},
add: function(url) {
// TODO: make this compatible with the browser back button.
if (url === this.previous()) {
this.currentIndex = this.currentIndex - 1;
if (this.next()) { this.clearForward(); }
window.history.back();
} else {
this.stack.push(url);
this.currentIndex = this.stack.length - 1;
}
return true;
},
clearForward: function() {
this.stack = this.stack.slice(0, this.currentIndex + 1);
}
};
@kisin
Copy link

kisin commented Feb 26, 2012

can you post usage example?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment