From 91826e327e6759f049ff2e66e48e5db0e7cf7700 Mon Sep 17 00:00:00 2001 From: Max Lynch Date: Mon, 25 Nov 2013 21:26:09 -0600 Subject: [PATCH] Fixed #219 --- dist/js/ionic-angular.js | 20 +++++++++++++++---- dist/js/ionic.js | 1 - .../angular/src/directive/ionicNavRouter.js | 20 +++++++++++++++---- js/utils/poly.js | 1 - 4 files changed, 32 insertions(+), 10 deletions(-) diff --git a/dist/js/ionic-angular.js b/dist/js/ionic-angular.js index cd683cdec7..498743fa31 100644 --- a/dist/js/ionic-angular.js +++ b/dist/js/ionic-angular.js @@ -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; diff --git a/dist/js/ionic.js b/dist/js/ionic.js index 720b3b9429..31f208aaed 100644 --- a/dist/js/ionic.js +++ b/dist/js/ionic.js @@ -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 }); diff --git a/js/ext/angular/src/directive/ionicNavRouter.js b/js/ext/angular/src/directive/ionicNavRouter.js index 6db1db4fa6..167d404005 100644 --- a/js/ext/angular/src/directive/ionicNavRouter.js +++ b/js/ext/angular/src/directive/ionicNavRouter.js @@ -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; diff --git a/js/utils/poly.js b/js/utils/poly.js index a79f37dab4..38929c76c7 100644 --- a/js/utils/poly.js +++ b/js/utils/poly.js @@ -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 });