refactor($ionicTabsDelegate): for .select() take away second argument

Closes #1682
This commit is contained in:
Andrew
2014-08-20 10:02:45 -06:00
parent 2a5595d11e
commit 4595fd3cc4
4 changed files with 9 additions and 41 deletions

View File

@@ -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
};

View File

@@ -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);
}
}

View File

@@ -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',
/**

View File

@@ -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() {