Skip to content

Commit

Permalink
fix(navClear): only set viewOptions if click leads to state change
Browse files Browse the repository at this point in the history
Closes #1043
  • Loading branch information
ajoslin committed Apr 7, 2014
1 parent d6c960c commit 4dffc5f
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 23 deletions.
28 changes: 21 additions & 7 deletions js/ext/angular/src/directive/ionicViewState.js
Original file line number Diff line number Diff line change
Expand Up @@ -300,19 +300,33 @@ angular.module('ionic.ui.viewState', ['ionic.service.view', 'ionic.service.gestu
*/
.directive('navClear', [
'$ionicViewService',
function($ionicViewService) {
'$state',
'$location',
'$window',
'$rootScope',
function($ionicViewService, $location, $state, $window, $rootScope) {
$rootScope.$on('$stateChangeError', function() {
$ionicViewService.nextViewOptions(null);
});
return {
priority: 100,
restrict: 'AC',
compile: function($element) {
return { pre: prelink };
function prelink($scope, $element) {
$element.on('click', function(e){
$ionicViewService.nextViewOptions({
disableAnimate: true,
disableBack: true
function prelink($scope, $element, $attrs) {
var unregisterListener;
function listenForStateChange() {
unregisterListener = $scope.$on('$stateChangeStart', function() {
$ionicViewService.nextViewOptions({
disableAnimate: true,
disableBack: true
});
unregisterListener();
});
});
$window.setTimeout(unregisterListener, 300);
}

$element.on('click', listenForStateChange);
}
}
};
Expand Down
21 changes: 5 additions & 16 deletions js/ext/angular/test/directive/ionicNavClear.unit.js
Original file line number Diff line number Diff line change
@@ -1,28 +1,17 @@
describe('navClear directive', function() {
ddescribe('navClear directive', function() {
beforeEach(module('ionic'));
it('should call nextViewOptions on click', inject(function($rootScope, $compile, $ionicViewService) {

it('should call nextViewOptions on click & stateChangeSuccess', inject(function($rootScope, $compile, $ionicViewService) {
spyOn($ionicViewService, 'nextViewOptions');
var el = $compile('<div nav-clear>')($rootScope.$new());

expect($ionicViewService.nextViewOptions).not.toHaveBeenCalled();
el.triggerHandler('click');
el.scope().$broadcast('$stateChangeStart');
expect($ionicViewService.nextViewOptions).toHaveBeenCalled();
expect($ionicViewService.nextViewOptions.mostRecentCall.args[0]).toEqual({
disableAnimate: true,
disableBack: true
});
}));

it('should run its click action before ngClick', inject(function($rootScope, $compile, $ionicViewService) {
spyOn($ionicViewService, 'nextViewOptions');
var el = $compile('<div nav-clear ng-click="method()">')($rootScope.$new());
var done = false;

//navClear should've called nextViewOptions by the time the ngClick handler runs
el.scope().method = function() {
expect($ionicViewService.nextViewOptions).toHaveBeenCalled();
done = true;
};
el.triggerHandler('click');
expect(done).toBe(true);
}));
});

0 comments on commit 4dffc5f

Please sign in to comment.