Permalink
Browse files

Add back button support, disabled until we get forward button support

  • Loading branch information...
1 parent f137e26 commit 88d50b96afd335e9800be6a2e28f73572f2ce9cc @bgirard committed May 30, 2012
Showing with 22 additions and 0 deletions.
  1. +22 −0 js/ui.js
View
@@ -515,6 +515,18 @@ RangeSelector.prototype = {
},
};
+window.onpopstate = function(ev) {
+ console.log("pop: " + JSON.stringify(ev.state));
+ gBreadcrumbTrail.pop();
+ if (ev.state) {
+ console.log("state");
+ if (ev.state.action === "popbreadcrumb") {
+ console.log("bread");
+ //gBreadcrumbTrail.pop();
+ }
+ }
+}
+
function BreadcrumbTrail() {
this._breadcrumbs = [];
this._selectedBreadcrumbIndex = -1;
@@ -574,20 +586,30 @@ BreadcrumbTrail.prototype = {
var removalHandle = this.add(breadcrumb);
this._enter(this._breadcrumbs.length - 1);
},
+ pop : function BreadcrumbTrail_pop() {
+ if (this._breadcrumbs.length-2 >= 0)
+ this._enter(this._breadcrumbs.length-2);
+ },
_enter: function BreadcrumbTrail__select(index) {
if (index == this._selectedBreadcrumbIndex)
return;
var prevSelected = this._breadcrumbs[this._selectedBreadcrumbIndex];
if (prevSelected)
prevSelected.classList.remove("selected");
var li = this._breadcrumbs[index];
+ if (this === gBreadcrumbTrail && index != 0) {
+ // Support for back button, disabled until the forward button is implemented.
+ //var state = {action: "popbreadcrumb",};
+ //window.history.pushState(state, "Cleopatra");
+ }
if (!li)
console.log("li at index " + index + " is null!");
delete li.breadcrumbIsTransient;
li.classList.add("selected");
this._deleteBeyond(index);
this._selectedBreadcrumbIndex = index;
li.breadcrumbEnterCallback();
+ // Add history state
},
_deleteBeyond: function BreadcrumbTrail__deleteBeyond(index) {
while (this._breadcrumbs.length > index + 1) {

0 comments on commit 88d50b9

Please sign in to comment.