@@ -13,6 +13,8 @@ var ipcRenderer = require('ipc-renderer'),
1313
1414module . 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
0 commit comments