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

@@ -1397,6 +1397,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) {
@@ -1405,6 +1409,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);
@@ -1427,14 +1434,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 {
@@ -1456,7 +1464,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;
@@ -1464,7 +1471,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
@@ -1473,6 +1480,8 @@ angular.module('ionic.ui.navRouter', ['ionic.service.gesture'])
//forward button
$rootScope.stackCursorPosition++;
}
$scope.direction = 'forwards';
} else {
var currentRouteBeforeChange = $route.current;
@@ -1715,6 +1724,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;

1
dist/js/ionic.js vendored
View File

@@ -1840,7 +1840,6 @@ window.ionic = {
return inputTapPolyfill(ele.control, e);
}
} else if( ele.tagName === "A" || ele.tagName === "BUTTON" ) {
var href = ele.getAttribute('href');
ionic.trigger('click', {
target: ele
});

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;

View File

@@ -69,7 +69,6 @@
return inputTapPolyfill(ele.control, e);
}
} else if( ele.tagName === "A" || ele.tagName === "BUTTON" ) {
var href = ele.getAttribute('href');
ionic.trigger('click', {
target: ele
});