From 4595fd3cc411cd5350617fac6c454391ac6f5b2d Mon Sep 17 00:00:00 2001 From: Andrew Date: Wed, 20 Aug 2014 10:02:45 -0600 Subject: [PATCH] refactor($ionicTabsDelegate): for .select() take away second argument Closes #1682 --- js/angular/controller/tabsController.js | 12 +++++----- js/angular/directive/tab.js | 4 ++-- js/angular/service/tabsDelegate.js | 5 ---- test/unit/angular/directive/tabs.unit.js | 29 +----------------------- 4 files changed, 9 insertions(+), 41 deletions(-) diff --git a/js/angular/controller/tabsController.js b/js/angular/controller/tabsController.js index f3a7a39155..f5f46a4bd2 100644 --- a/js/angular/controller/tabsController.js +++ b/js/angular/controller/tabsController.js @@ -1,8 +1,8 @@ IonicModule .controller('$ionicTabs', [ - '$scope', - '$ionicViewService', - '$element', + '$scope', + '$ionicViewService', + '$element', function($scope, $ionicViewService, $element) { var _selectedTab = null; var self = this; @@ -59,8 +59,9 @@ function($scope, $ionicViewService, $element) { } else { tabIndex = self.tabs.indexOf(tab); } - if (!tab || tabIndex == -1) { - throw new Error('Cannot select tab "' + tabIndex + '"!'); + + if (arguments.length === 1) { + shouldEmitEvent = !!(tab.navViewName || tab.uiSref); } if (_selectedTab && _selectedTab.$historyId == tab.$historyId) { @@ -85,7 +86,6 @@ function($scope, $ionicViewService, $element) { navViewName: tab.navViewName, hasNavView: !!tab.navViewName, title: tab.title, - //Skip the first character of href if it's # url: tab.href, uiSref: tab.uiSref }; diff --git a/js/angular/directive/tab.js b/js/angular/directive/tab.js index 5d913a4258..11812af4b9 100644 --- a/js/angular/directive/tab.js +++ b/js/angular/directive/tab.js @@ -107,13 +107,13 @@ function($rootScope, $animate, $ionicBind, $compile) { $element[0].removeAttribute('title'); if (navViewName) { - tabCtrl.navViewName = navViewName; + tabCtrl.navViewName = $scope.navViewName = navViewName; } $scope.$on('$stateChangeSuccess', selectIfMatchesState); selectIfMatchesState(); function selectIfMatchesState() { if (tabCtrl.tabMatchesState()) { - tabsCtrl.select($scope); + tabsCtrl.select($scope, false); } } diff --git a/js/angular/service/tabsDelegate.js b/js/angular/service/tabsDelegate.js index e505d404a4..ada6ef42e2 100644 --- a/js/angular/service/tabsDelegate.js +++ b/js/angular/service/tabsDelegate.js @@ -41,11 +41,6 @@ IonicModule * @description Select the tab matching the given index. * * @param {number} index Index of the tab to select. - * @param {boolean=} shouldChangeHistory Whether this selection should load this tab's - * view history (if it exists) and use it, or just load the default page. - * Default false. - * Hint: you probably want this to be true if you have an - * {@link ionic.directive:ionNavView} inside your tab. */ 'select', /** diff --git a/test/unit/angular/directive/tabs.unit.js b/test/unit/angular/directive/tabs.unit.js index 3f505a9709..040a7b423b 100644 --- a/test/unit/angular/directive/tabs.unit.js +++ b/test/unit/angular/directive/tabs.unit.js @@ -100,33 +100,6 @@ describe('tabs', function() { expect(ctrl.selectedTab()).toBe('foo'); }); - it('.select should throw error if tab doesnt exist', function() { - var tab = {}; - ctrl.add(tab); - expect(function() { - ctrl.select({}); - }).toThrow(); - expect(function() { - ctrl.select(null); - }).toThrow(); - expect(function() { - ctrl.select(tab); - }).not.toThrow(); - }); - - it('.select should throw error if number is bad', function() { - ctrl.add({}); - expect(function() { - ctrl.select(1); - }).toThrow(); - expect(function() { - ctrl.select(-1); - }).toThrow(); - expect(function() { - ctrl.select(0); - }).not.toThrow(); - }); - it('.select should allow number', function() { var tab1 = {}, tab2 = {}; ctrl.add(tab1); @@ -513,7 +486,7 @@ describe('tabs', function() { tabEl.scope().$broadcast('$stateChangeSuccess'); expect(tabMatchesState).toHaveBeenCalled(); - expect(tabsCtrl.select).toHaveBeenCalledWith(tabEl.scope()); + expect(tabsCtrl.select).toHaveBeenCalledWith(tabEl.scope(), false); }); it('should transclude on $tabSelected=true', function() {