mirror of
https://github.com/ionic-team/ionic-framework.git
synced 2026-03-13 10:22:08 +08:00
refactor($ionicTabsDelegate): for .select() take away second argument
Closes #1682
This commit is contained in:
12
js/angular/controller/tabsController.js
vendored
12
js/angular/controller/tabsController.js
vendored
@@ -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
|
||||
};
|
||||
|
||||
4
js/angular/directive/tab.js
vendored
4
js/angular/directive/tab.js
vendored
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
5
js/angular/service/tabsDelegate.js
vendored
5
js/angular/service/tabsDelegate.js
vendored
@@ -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',
|
||||
/**
|
||||
|
||||
@@ -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() {
|
||||
|
||||
Reference in New Issue
Block a user