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

Commit dc904b7

Browse files
committed
Use local variables.
1 parent 03e9359 commit dc904b7

File tree

1 file changed

+19
-15
lines changed

1 file changed

+19
-15
lines changed

js/router.js

Lines changed: 19 additions & 15 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 || {};
@@ -51,19 +53,19 @@ module.exports = Backbone.Router.extend({
5153

5254
var originalHistoryBack = history.back;
5355
history.back = function() {
54-
historyAction = 'back';
56+
self.historyAction = 'back';
5557
originalHistoryBack();
5658
}
5759

5860
var originalHistoryForward = history.forward;
5961
history.forward = function() {
60-
historyAction = 'forward';
62+
self.historyAction = 'forward';
6163
originalHistoryForward();
6264
}
6365

64-
window.historySize = -1;
65-
window.historyPosition = -1;
66-
window.historyAction = 'default';
66+
this.historySize = -1;
67+
this.historyPosition = -1;
68+
this.historyAction = 'default';
6769
},
6870

6971
translateRoute: function(route) {
@@ -121,28 +123,30 @@ module.exports = Backbone.Router.extend({
121123
},
122124

123125
execute: function(callback, args, name) {
124-
if (historyAction == 'default') {
125-
historyPosition += 1;
126-
historySize = historyPosition;
127-
} else if (historyAction == 'back') {
128-
historyPosition -= 1;
129-
} else if(historyAction == '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") {
130132
//don't increment if the same state is navigated to twice
131133
//don't increment on index since that isn't a real state
132-
historyPosition += 1;
134+
this.historyPosition += 1;
133135
}
134-
historyAction = 'default';
136+
this.historyAction = 'default';
135137

136-
if (historyPosition == historySize)
138+
if (this.historyPosition == this.historySize)
137139
$('.js-navFwd').addClass('disabled');
138140
else
139141
$('.js-navFwd').removeClass('disabled');
140142

141-
if (historyPosition == 1)
143+
if (this.historyPosition == 1)
142144
$('.js-navBack').addClass('disabled');
143145
else
144146
$('.js-navBack').removeClass('disabled');
145147

148+
console.log('position: ' + this.historyPosition + '; size: ' + this.historySize);
149+
146150
if (callback) callback.apply(this, args);
147151
},
148152

0 commit comments

Comments
 (0)