Skip to content
This repository was archived by the owner on May 16, 2019. It is now read-only.

Commit a2ae1b8

Browse files
committed
Merge pull request #1425 from programmerpeter/fix4
Implemented some @rmisio suggestions from #1419
2 parents 4ac89a6 + bcc4e8e commit a2ae1b8

File tree

2 files changed

+30
-15
lines changed

2 files changed

+30
-15
lines changed

js/router.js

Lines changed: 30 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ var ipcRenderer = require('ipc-renderer'),
1313

1414
module.exports = Backbone.Router.extend({
1515
initialize: function(options){
16+
var self = this;
17+
1618
var routes;
1719

1820
this.options = options || {};
@@ -48,9 +50,22 @@ module.exports = Backbone.Router.extend({
4850
this.navigate(translatedRoute, { trigger: true });
4951
});
5052
});
51-
history.size = -1;
52-
history.position = -1;
53-
history.action = 'default';
53+
54+
var originalHistoryBack = history.back;
55+
history.back = function() {
56+
self.historyAction = 'back';
57+
return originalHistoryBack(arguments);
58+
}
59+
60+
var originalHistoryForward = history.forward;
61+
history.forward = function() {
62+
self.historyAction = 'forward';
63+
return originalHistoryForward(arguments);
64+
}
65+
66+
this.historySize = -1;
67+
this.historyPosition = -1;
68+
this.historyAction = 'default';
5469
},
5570

5671
translateRoute: function(route) {
@@ -108,28 +123,30 @@ module.exports = Backbone.Router.extend({
108123
},
109124

110125
execute: function(callback, args, name) {
111-
if (history.action == 'default') {
112-
history.position += 1;
113-
history.size = history.position;
114-
} else if (history.action == 'back') {
115-
history.position -= 1;
116-
} else if(history.action == 'forward' && this.previousName != name && name != "index") {
126+
if (this.historyAction == 'default') {
127+
this.historyPosition += 1;
128+
this.historySize = this.historyPosition;
129+
} else if (this.historyAction == 'back') {
130+
this.historyPosition -= 1;
131+
} else if(this.historyAction == 'forward' && this.previousName != name && name != "index") {
117132
//don't increment if the same state is navigated to twice
118133
//don't increment on index since that isn't a real state
119-
history.position += 1;
134+
this.historyPosition += 1;
120135
}
121-
history.action = 'default';
136+
this.historyAction = 'default';
122137

123-
if (history.position == history.size)
138+
if (this.historyPosition == this.historySize)
124139
$('.js-navFwd').addClass('disabled');
125140
else
126141
$('.js-navFwd').removeClass('disabled');
127142

128-
if (history.position == 1)
143+
if (this.historyPosition == 1)
129144
$('.js-navBack').addClass('disabled');
130145
else
131146
$('.js-navBack').removeClass('disabled');
132147

148+
console.log('position: ' + this.historyPosition + '; size: ' + this.historySize);
149+
133150
if (callback) callback.apply(this, args);
134151
},
135152

js/views/pageNavVw.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -501,12 +501,10 @@ module.exports = baseVw.extend({
501501
},
502502

503503
navBackClick: function(){
504-
history.action = 'back';
505504
history.back();
506505
},
507506

508507
navFwdClick: function(){
509-
history.action = 'forward';
510508
history.forward();
511509
},
512510

0 commit comments

Comments
 (0)