mirror of
https://github.com/ionic-team/ionic-framework.git
synced 2026-03-13 10:22:08 +08:00
Fixed #219
This commit is contained in:
20
js/ext/angular/src/directive/ionicNavRouter.js
vendored
20
js/ext/angular/src/directive/ionicNavRouter.js
vendored
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user