Skip to content

Commit a379bfd

Browse files
committedJul 31, 2015
fix(menuClose): Prevent clicking on current page link in sidemenu from disorganizing page heigharchy. Fixes #4132
1 parent bab6cad commit a379bfd

File tree

2 files changed

+37
-1
lines changed

2 files changed

+37
-1
lines changed
 

‎js/angular/directive/menuClose.js

+21-1
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,20 @@
2121
* ```html
2222
* <a menu-close href="#/home" class="item">Home</a>
2323
* ```
24+
*
25+
* Note that if your destination state uses a resolve and that resolve asyncronously
26+
* takes longer than a standard transition (300ms), you'll need to set the
27+
* `nextViewOptions` manually as your resolve completes.
28+
*
29+
* ```JS
30+
* $ionicHistory.nextViewOptions({
31+
* historyRoot: true,
32+
* disableAnimate: true,
33+
* expire: 300
34+
* });
2435
*/
2536
IonicModule
26-
.directive('menuClose', ['$ionicHistory', function($ionicHistory) {
37+
.directive('menuClose', ['$ionicHistory', '$timeout', function($ionicHistory, $timeout) {
2738
return {
2839
restrict: 'AC',
2940
link: function($scope, $element) {
@@ -35,6 +46,15 @@ IonicModule
3546
disableAnimate: true,
3647
expire: 300
3748
});
49+
// if no transition in 300ms, reset nextViewOptions
50+
// the expire should take care of it, but will be cancelled in some
51+
// cases. This directive is an exception to the rules of history.js
52+
$timeout( function() {
53+
$ionicHistory.nextViewOptions({
54+
historyRoot: false,
55+
disableAnimate: false
56+
});
57+
}, 300);
3858
sideMenuCtrl.close();
3959
}
4060
});

‎test/unit/angular/directive/sideMenu.unit.js

+16
Original file line numberDiff line numberDiff line change
@@ -349,4 +349,20 @@ describe('menuClose directive', function() {
349349
el.triggerHandler('click');
350350
expect(closeSpy).toHaveBeenCalled();
351351
}));
352+
it('should set nextViewOptions',
353+
inject(function($compile, $rootScope, $ionicHistory, $timeout) {
354+
var el = angular.element('<div menu-close>');
355+
el.data('$ionSideMenusController', {
356+
close: function() { }
357+
});
358+
$compile(el)($rootScope.$new());
359+
$rootScope.$apply();
360+
expect($ionicHistory.nextViewOptions()).toBe(undefined)
361+
el.triggerHandler('click');
362+
expect($ionicHistory.nextViewOptions().historyRoot).toBe(true);
363+
expect($ionicHistory.nextViewOptions().disableAnimate).toBe(true);
364+
$timeout.flush();
365+
expect($ionicHistory.nextViewOptions().historyRoot).toBe(false);
366+
expect($ionicHistory.nextViewOptions().disableAnimate).toBe(false);
367+
}));
352368
});

0 commit comments

Comments
 (0)