From 9da113fd15d9b00386c35958bfab4d354bbd9618 Mon Sep 17 00:00:00 2001 From: Ash Connell Date: Fri, 22 May 2015 19:02:01 +1000 Subject: [PATCH 1/2] [ionicHistory] add method to remove the back view --- js/angular/service/history.js | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/js/angular/service/history.js b/js/angular/service/history.js index 8e453aa0230..60dc67a00e2 100644 --- a/js/angular/service/history.js +++ b/js/angular/service/history.js @@ -599,6 +599,37 @@ function($rootScope, $state, $location, $window, $timeout, $ionicViewSwitcher, $ viewHistory.backView && viewHistory.backView.go(); }, + /** + * @ngdoc method + * @name $ionicHistory#removeBackView + * @description Remove the previous view from the history completely, including the + * cached element and scope (if they exist). + */ + removeBackView: function () { + var self = this; + var currentHistory = viewHistory.histories[this.currentHistoryId()]; + var currentCursor = currentHistory.cursor; + + var currentView = currentHistory.stack[currentCursor]; + var backView = currentHistory.stack[currentCursor - 1]; + var replacementView = currentHistory.stack[currentCursor - 2]; + + // fail if we dont have enough views in the history + if (!backView || !replacementView) { + return; + } + + // remove the old backView and the cached element/scope + currentHistory.stack.splice(currentCursor - 1, 1); + self.clearCache([backView.viewId]); + // make the replacementView and currentView point to each other (bypass the old backView) + currentView.backViewId = replacementView.viewId; + currentView.index = currentView.index - 1; + replacementView.forwardViewId = currentView.viewId; + // update the cursor and set new backView + viewHistory.backView = replacementView; + currentHistory.currentCursor += -1; + }, enabledBack: function(view) { var backView = getBackView(view); From e3c1147e5f60dafe4b7a091bf79efad350a1474c Mon Sep 17 00:00:00 2001 From: Ash Connell Date: Sat, 23 May 2015 19:16:05 +1000 Subject: [PATCH 2/2] [fix] trailing whitespace --- js/angular/service/history.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/js/angular/service/history.js b/js/angular/service/history.js index 60dc67a00e2..0c84b7b323e 100644 --- a/js/angular/service/history.js +++ b/js/angular/service/history.js @@ -602,7 +602,7 @@ function($rootScope, $state, $location, $window, $timeout, $ionicViewSwitcher, $ /** * @ngdoc method * @name $ionicHistory#removeBackView - * @description Remove the previous view from the history completely, including the + * @description Remove the previous view from the history completely, including the * cached element and scope (if they exist). */ removeBackView: function () {