Skip to content

Commit

Permalink
fix(menuClose): Prevent clicking on current page link in sidemenu fro…
Browse files Browse the repository at this point in the history
…m disorganizing page heigharchy. Fixes #4132
  • Loading branch information
perrygovier committed Jul 31, 2015
1 parent bab6cad commit a379bfd
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 1 deletion.
22 changes: 21 additions & 1 deletion js/angular/directive/menuClose.js
Expand Up @@ -21,9 +21,20 @@
* ```html
* <a menu-close href="#/home" class="item">Home</a>
* ```
*
* Note that if your destination state uses a resolve and that resolve asyncronously
* takes longer than a standard transition (300ms), you'll need to set the
* `nextViewOptions` manually as your resolve completes.
*
* ```JS
* $ionicHistory.nextViewOptions({
* historyRoot: true,
* disableAnimate: true,
* expire: 300
* });
*/
IonicModule
.directive('menuClose', ['$ionicHistory', function($ionicHistory) {
.directive('menuClose', ['$ionicHistory', '$timeout', function($ionicHistory, $timeout) {
return {
restrict: 'AC',
link: function($scope, $element) {
Expand All @@ -35,6 +46,15 @@ IonicModule
disableAnimate: true,
expire: 300
});
// if no transition in 300ms, reset nextViewOptions
// the expire should take care of it, but will be cancelled in some
// cases. This directive is an exception to the rules of history.js
$timeout( function() {
$ionicHistory.nextViewOptions({
historyRoot: false,
disableAnimate: false
});
}, 300);
sideMenuCtrl.close();
}
});
Expand Down
16 changes: 16 additions & 0 deletions test/unit/angular/directive/sideMenu.unit.js
Expand Up @@ -349,4 +349,20 @@ describe('menuClose directive', function() {
el.triggerHandler('click');
expect(closeSpy).toHaveBeenCalled();
}));
it('should set nextViewOptions',
inject(function($compile, $rootScope, $ionicHistory, $timeout) {
var el = angular.element('<div menu-close>');
el.data('$ionSideMenusController', {
close: function() { }
});
$compile(el)($rootScope.$new());
$rootScope.$apply();
expect($ionicHistory.nextViewOptions()).toBe(undefined)
el.triggerHandler('click');
expect($ionicHistory.nextViewOptions().historyRoot).toBe(true);
expect($ionicHistory.nextViewOptions().disableAnimate).toBe(true);
$timeout.flush();
expect($ionicHistory.nextViewOptions().historyRoot).toBe(false);
expect($ionicHistory.nextViewOptions().disableAnimate).toBe(false);
}));
});

0 comments on commit a379bfd

Please sign in to comment.