@@ -7,6 +7,7 @@ angular.module('ionic.service.view', ['ui.router', 'ionic.service.platform'])
7
7
// init the variables that keep track of the view history
8
8
$rootScope . $viewHistory = {
9
9
histories : { root : { historyId : 'root' , parentHistoryId : null , stack : [ ] , cursor : - 1 } } ,
10
+ views : { } ,
10
11
backView : null ,
11
12
forwardView : null ,
12
13
currentView : null ,
@@ -199,7 +200,7 @@ angular.module('ionic.service.view', ['ui.router', 'ionic.service.platform'])
199
200
if ( forwardView && currentView . stateId !== forwardView . stateId ) {
200
201
// they navigated to a new view but the stack already has a forward view
201
202
// since its a new view remove any forwards that existed
202
- var forwardsHistory = this . _getView ( forwardView . historyId ) ;
203
+ var forwardsHistory = this . _getHistoryById ( forwardView . historyId ) ;
203
204
if ( forwardsHistory ) {
204
205
// the forward has a history
205
206
for ( var x = forwardsHistory . stack . length - 1 ; x >= forwardView . index ; x -- ) {
@@ -215,8 +216,8 @@ angular.module('ionic.service.view', ['ui.router', 'ionic.service.platform'])
215
216
rsp . navAction = 'initialView' ;
216
217
}
217
218
218
- // add the new view to the stack
219
- viewHistory . histories [ rsp . viewId ] = this . createView ( {
219
+ // add the new view
220
+ viewHistory . views [ rsp . viewId ] = this . createView ( {
220
221
viewId : rsp . viewId ,
221
222
index : hist . stack . length ,
222
223
historyId : hist . historyId ,
@@ -230,7 +231,7 @@ angular.module('ionic.service.view', ['ui.router', 'ionic.service.platform'])
230
231
} ) ;
231
232
232
233
// add the new view to this history's stack
233
- hist . stack . push ( viewHistory . histories [ rsp . viewId ] ) ;
234
+ hist . stack . push ( viewHistory . views [ rsp . viewId ] ) ;
234
235
}
235
236
236
237
this . setNavViews ( rsp . viewId ) ;
@@ -243,7 +244,7 @@ angular.module('ionic.service.view', ['ui.router', 'ionic.service.platform'])
243
244
setNavViews : function ( viewId ) {
244
245
var viewHistory = $rootScope . $viewHistory ;
245
246
246
- viewHistory . currentView = this . _getView ( viewId ) ;
247
+ viewHistory . currentView = this . _getViewById ( viewId ) ;
247
248
viewHistory . backView = this . _getBackView ( viewHistory . currentView ) ;
248
249
viewHistory . forwardView = this . _getForwardView ( viewHistory . currentView ) ;
249
250
@@ -335,16 +336,20 @@ angular.module('ionic.service.view', ['ui.router', 'ionic.service.platform'])
335
336
}
336
337
} ,
337
338
338
- _getView : function ( viewId ) {
339
- return ( viewId ? $rootScope . $viewHistory . histories [ viewId ] : null ) ;
339
+ _getViewById : function ( viewId ) {
340
+ return ( viewId ? $rootScope . $viewHistory . views [ viewId ] : null ) ;
340
341
} ,
341
342
342
343
_getBackView : function ( view ) {
343
- return ( view ? this . _getView ( view . backViewId ) : null ) ;
344
+ return ( view ? this . _getViewById ( view . backViewId ) : null ) ;
344
345
} ,
345
346
346
347
_getForwardView : function ( view ) {
347
- return ( view ? this . _getView ( view . forwardViewId ) : null ) ;
348
+ return ( view ? this . _getViewById ( view . forwardViewId ) : null ) ;
349
+ } ,
350
+
351
+ _getHistoryById : function ( historyId ) {
352
+ return ( historyId ? $rootScope . $viewHistory . histories [ historyId ] : null ) ;
348
353
} ,
349
354
350
355
_getHistory : function ( scope ) {
@@ -493,11 +498,11 @@ angular.module('ionic.service.view', ['ui.router', 'ionic.service.platform'])
493
498
} ,
494
499
495
500
clearHistory : function ( ) {
496
- var historyId , x , view ,
501
+ var
497
502
histories = $rootScope . $viewHistory . histories ,
498
503
currentView = $rootScope . $viewHistory . currentView ;
499
504
500
- for ( historyId in histories ) {
505
+ for ( var historyId in histories ) {
501
506
502
507
if ( histories [ historyId ] . stack ) {
503
508
histories [ historyId ] . stack = [ ] ;
@@ -514,6 +519,12 @@ angular.module('ionic.service.view', ['ui.router', 'ionic.service.platform'])
514
519
515
520
}
516
521
522
+ for ( var viewId in $rootScope . $viewHistory . views ) {
523
+ if ( viewId !== currentView . viewId ) {
524
+ delete $rootScope . $viewHistory . views [ viewId ] ;
525
+ }
526
+ }
527
+
517
528
this . setNavViews ( currentView . viewId ) ;
518
529
}
519
530
0 commit comments