This commit is contained in:
Max Lynch
2013-11-25 21:26:09 -06:00
parent 8bc870e494
commit 91826e327e
4 changed files with 32 additions and 10 deletions

View File

@@ -34,6 +34,10 @@ angular.module('ionic.ui.navRouter', ['ionic.service.gesture'])
isVisible: true
};
$scope.navController = this;
this.goBack = function() {
$scope.direction = 'back';
}
}],
link: function($scope, $element, $attr) {
@@ -42,6 +46,9 @@ angular.module('ionic.ui.navRouter', ['ionic.service.gesture'])
$element.addClass('noop-animation');
var isFirst = true;
// Store whether we did an animation yet, to know if
// we should let the first state animate
var didAnimate = false;
var initTransition = function() {
//$element.addClass($scope.animation);
@@ -64,14 +71,15 @@ angular.module('ionic.ui.navRouter', ['ionic.service.gesture'])
$scope.$on('$routeChangeStart', function(e, next, current) {
var back, historyState = $window.history.state;
back = !!(historyState && historyState.position <= $rootScope.stackCursorPosition);
back = $scope.direction == 'back' || (!!(historyState && historyState.position <= $rootScope.stackCursorPosition));
if(isFirst || (next && next.$$route.originalPath === "")) {
// Don't animate
return;
}
if($rootScope.stackCursorPosition > 0) {
if(didAnimate || $rootScope.stackCursorPosition > 0) {
didAnimate = true;
if(back) {
reverseTransition();
} else {
@@ -93,7 +101,6 @@ angular.module('ionic.ui.navRouter', ['ionic.service.gesture'])
// going forwards or back
$scope.$watch(function () { return $location.path() }, function (newLocation, oldLocation) {
if($rootScope.actualLocation === newLocation) {
if(oldLocation == '' || newLocation == '/') {
// initial route, skip this
return;
@@ -101,7 +108,7 @@ angular.module('ionic.ui.navRouter', ['ionic.service.gesture'])
var back, historyState = $window.history.state;
back = !!(historyState && historyState.position <= $rootScope.stackCursorPosition);
back = $scope.direction == 'back' || (!!(historyState && historyState.position <= $rootScope.stackCursorPosition));
if (back) {
//back button
@@ -110,6 +117,8 @@ angular.module('ionic.ui.navRouter', ['ionic.service.gesture'])
//forward button
$rootScope.stackCursorPosition++;
}
$scope.direction = 'forwards';
} else {
var currentRouteBeforeChange = $route.current;
@@ -352,6 +361,9 @@ angular.module('ionic.ui.navRouter', ['ionic.service.gesture'])
// Only trigger back if the stack is greater than zero
if($rootScope.stackCursorPosition > 0) {
$window.history.back();
// Fallback for bad history supporting devices
navCtrl.goBack();
}
e.alreadyHandled = true;
return false;