Skip to content

Commit 91826e3

Browse files
committed
Fixed #219
1 parent 8bc870e commit 91826e3

File tree

4 files changed

+32
-10
lines changed

4 files changed

+32
-10
lines changed

dist/js/ionic-angular.js

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1397,6 +1397,10 @@ angular.module('ionic.ui.navRouter', ['ionic.service.gesture'])
13971397
isVisible: true
13981398
};
13991399
$scope.navController = this;
1400+
1401+
this.goBack = function() {
1402+
$scope.direction = 'back';
1403+
}
14001404
}],
14011405

14021406
link: function($scope, $element, $attr) {
@@ -1405,6 +1409,9 @@ angular.module('ionic.ui.navRouter', ['ionic.service.gesture'])
14051409
$element.addClass('noop-animation');
14061410

14071411
var isFirst = true;
1412+
// Store whether we did an animation yet, to know if
1413+
// we should let the first state animate
1414+
var didAnimate = false;
14081415

14091416
var initTransition = function() {
14101417
//$element.addClass($scope.animation);
@@ -1427,14 +1434,15 @@ angular.module('ionic.ui.navRouter', ['ionic.service.gesture'])
14271434
$scope.$on('$routeChangeStart', function(e, next, current) {
14281435
var back, historyState = $window.history.state;
14291436

1430-
back = !!(historyState && historyState.position <= $rootScope.stackCursorPosition);
1437+
back = $scope.direction == 'back' || (!!(historyState && historyState.position <= $rootScope.stackCursorPosition));
14311438

14321439
if(isFirst || (next && next.$$route.originalPath === "")) {
14331440
// Don't animate
14341441
return;
14351442
}
14361443

1437-
if($rootScope.stackCursorPosition > 0) {
1444+
if(didAnimate || $rootScope.stackCursorPosition > 0) {
1445+
didAnimate = true;
14381446
if(back) {
14391447
reverseTransition();
14401448
} else {
@@ -1456,15 +1464,14 @@ angular.module('ionic.ui.navRouter', ['ionic.service.gesture'])
14561464
// going forwards or back
14571465
$scope.$watch(function () { return $location.path() }, function (newLocation, oldLocation) {
14581466
if($rootScope.actualLocation === newLocation) {
1459-
14601467
if(oldLocation == '' || newLocation == '/') {
14611468
// initial route, skip this
14621469
return;
14631470
}
14641471

14651472
var back, historyState = $window.history.state;
14661473

1467-
back = !!(historyState && historyState.position <= $rootScope.stackCursorPosition);
1474+
back = $scope.direction == 'back' || (!!(historyState && historyState.position <= $rootScope.stackCursorPosition));
14681475

14691476
if (back) {
14701477
//back button
@@ -1473,6 +1480,8 @@ angular.module('ionic.ui.navRouter', ['ionic.service.gesture'])
14731480
//forward button
14741481
$rootScope.stackCursorPosition++;
14751482
}
1483+
1484+
$scope.direction = 'forwards';
14761485

14771486
} else {
14781487
var currentRouteBeforeChange = $route.current;
@@ -1715,6 +1724,9 @@ angular.module('ionic.ui.navRouter', ['ionic.service.gesture'])
17151724
// Only trigger back if the stack is greater than zero
17161725
if($rootScope.stackCursorPosition > 0) {
17171726
$window.history.back();
1727+
1728+
// Fallback for bad history supporting devices
1729+
navCtrl.goBack();
17181730
}
17191731
e.alreadyHandled = true;
17201732
return false;

dist/js/ionic.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1840,7 +1840,6 @@ window.ionic = {
18401840
return inputTapPolyfill(ele.control, e);
18411841
}
18421842
} else if( ele.tagName === "A" || ele.tagName === "BUTTON" ) {
1843-
var href = ele.getAttribute('href');
18441843
ionic.trigger('click', {
18451844
target: ele
18461845
});

js/ext/angular/src/directive/ionicNavRouter.js

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,10 @@ angular.module('ionic.ui.navRouter', ['ionic.service.gesture'])
3434
isVisible: true
3535
};
3636
$scope.navController = this;
37+
38+
this.goBack = function() {
39+
$scope.direction = 'back';
40+
}
3741
}],
3842

3943
link: function($scope, $element, $attr) {
@@ -42,6 +46,9 @@ angular.module('ionic.ui.navRouter', ['ionic.service.gesture'])
4246
$element.addClass('noop-animation');
4347

4448
var isFirst = true;
49+
// Store whether we did an animation yet, to know if
50+
// we should let the first state animate
51+
var didAnimate = false;
4552

4653
var initTransition = function() {
4754
//$element.addClass($scope.animation);
@@ -64,14 +71,15 @@ angular.module('ionic.ui.navRouter', ['ionic.service.gesture'])
6471
$scope.$on('$routeChangeStart', function(e, next, current) {
6572
var back, historyState = $window.history.state;
6673

67-
back = !!(historyState && historyState.position <= $rootScope.stackCursorPosition);
74+
back = $scope.direction == 'back' || (!!(historyState && historyState.position <= $rootScope.stackCursorPosition));
6875

6976
if(isFirst || (next && next.$$route.originalPath === "")) {
7077
// Don't animate
7178
return;
7279
}
7380

74-
if($rootScope.stackCursorPosition > 0) {
81+
if(didAnimate || $rootScope.stackCursorPosition > 0) {
82+
didAnimate = true;
7583
if(back) {
7684
reverseTransition();
7785
} else {
@@ -93,15 +101,14 @@ angular.module('ionic.ui.navRouter', ['ionic.service.gesture'])
93101
// going forwards or back
94102
$scope.$watch(function () { return $location.path() }, function (newLocation, oldLocation) {
95103
if($rootScope.actualLocation === newLocation) {
96-
97104
if(oldLocation == '' || newLocation == '/') {
98105
// initial route, skip this
99106
return;
100107
}
101108

102109
var back, historyState = $window.history.state;
103110

104-
back = !!(historyState && historyState.position <= $rootScope.stackCursorPosition);
111+
back = $scope.direction == 'back' || (!!(historyState && historyState.position <= $rootScope.stackCursorPosition));
105112

106113
if (back) {
107114
//back button
@@ -110,6 +117,8 @@ angular.module('ionic.ui.navRouter', ['ionic.service.gesture'])
110117
//forward button
111118
$rootScope.stackCursorPosition++;
112119
}
120+
121+
$scope.direction = 'forwards';
113122

114123
} else {
115124
var currentRouteBeforeChange = $route.current;
@@ -352,6 +361,9 @@ angular.module('ionic.ui.navRouter', ['ionic.service.gesture'])
352361
// Only trigger back if the stack is greater than zero
353362
if($rootScope.stackCursorPosition > 0) {
354363
$window.history.back();
364+
365+
// Fallback for bad history supporting devices
366+
navCtrl.goBack();
355367
}
356368
e.alreadyHandled = true;
357369
return false;

js/utils/poly.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,6 @@
6969
return inputTapPolyfill(ele.control, e);
7070
}
7171
} else if( ele.tagName === "A" || ele.tagName === "BUTTON" ) {
72-
var href = ele.getAttribute('href');
7372
ionic.trigger('click', {
7473
target: ele
7574
});

0 commit comments

Comments
 (0)