mirror of
https://github.com/ionic-team/ionic-framework.git
synced 2025-11-06 22:29:44 +08:00
Fixed #40 with test
This commit is contained in:
11
dist/js/ionic-angular.js
vendored
11
dist/js/ionic-angular.js
vendored
@ -858,6 +858,14 @@ angular.module('ionic.ui.tabs', ['ngAnimate'])
|
|||||||
angular.extend(this, ionic.controllers.TabBarController.prototype);
|
angular.extend(this, ionic.controllers.TabBarController.prototype);
|
||||||
|
|
||||||
ionic.controllers.TabBarController.call(this, {
|
ionic.controllers.TabBarController.call(this, {
|
||||||
|
controllerChanged: function(oldC, oldI, newC, newI) {
|
||||||
|
$scope.controllerChanged && $scope.controllerChanged({
|
||||||
|
oldController: oldC,
|
||||||
|
oldIndex: oldI,
|
||||||
|
newController: newC,
|
||||||
|
newIndex: newI
|
||||||
|
});
|
||||||
|
},
|
||||||
tabBar: {
|
tabBar: {
|
||||||
tryTabSelect: function() {},
|
tryTabSelect: function() {},
|
||||||
setSelectedItem: function(index) {},
|
setSelectedItem: function(index) {},
|
||||||
@ -891,7 +899,8 @@ angular.module('ionic.ui.tabs', ['ngAnimate'])
|
|||||||
restrict: 'E',
|
restrict: 'E',
|
||||||
replace: true,
|
replace: true,
|
||||||
scope: {
|
scope: {
|
||||||
animation: '@'
|
animation: '@',
|
||||||
|
controllerChanged: '&'
|
||||||
},
|
},
|
||||||
transclude: true,
|
transclude: true,
|
||||||
controller: 'TabsCtrl',
|
controller: 'TabsCtrl',
|
||||||
|
|||||||
6
dist/js/ionic.js
vendored
6
dist/js/ionic.js
vendored
@ -4923,7 +4923,6 @@ ionic.controllers.TabBarController = ionic.controllers.ViewController.inherit({
|
|||||||
|
|
||||||
if(shouldChange) {
|
if(shouldChange) {
|
||||||
this.setSelectedController(index);
|
this.setSelectedController(index);
|
||||||
this.controllerChanged && this.controllerChanged(this.selectedController, this.selectedIndex);
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
@ -4932,11 +4931,16 @@ ionic.controllers.TabBarController = ionic.controllers.ViewController.inherit({
|
|||||||
if(index >= this.controllers.length) {
|
if(index >= this.controllers.length) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
var lastController = this.selectedController;
|
||||||
|
var lastIndex = this.selectedIndex;
|
||||||
|
|
||||||
this.selectedController = this.controllers[index];
|
this.selectedController = this.controllers[index];
|
||||||
this.selectedIndex = index;
|
this.selectedIndex = index;
|
||||||
|
|
||||||
this._showController(index);
|
this._showController(index);
|
||||||
this.tabBar.setSelectedItem(index);
|
this.tabBar.setSelectedItem(index);
|
||||||
|
|
||||||
|
this.controllerChanged && this.controllerChanged(lastController, lastIndex, this.selectedController, this.selectedIndex);
|
||||||
},
|
},
|
||||||
|
|
||||||
_showController: function(index) {
|
_showController: function(index) {
|
||||||
|
|||||||
@ -55,7 +55,6 @@ ionic.controllers.TabBarController = ionic.controllers.ViewController.inherit({
|
|||||||
|
|
||||||
if(shouldChange) {
|
if(shouldChange) {
|
||||||
this.setSelectedController(index);
|
this.setSelectedController(index);
|
||||||
this.controllerChanged && this.controllerChanged(this.selectedController, this.selectedIndex);
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
@ -64,11 +63,16 @@ ionic.controllers.TabBarController = ionic.controllers.ViewController.inherit({
|
|||||||
if(index >= this.controllers.length) {
|
if(index >= this.controllers.length) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
var lastController = this.selectedController;
|
||||||
|
var lastIndex = this.selectedIndex;
|
||||||
|
|
||||||
this.selectedController = this.controllers[index];
|
this.selectedController = this.controllers[index];
|
||||||
this.selectedIndex = index;
|
this.selectedIndex = index;
|
||||||
|
|
||||||
this._showController(index);
|
this._showController(index);
|
||||||
this.tabBar.setSelectedItem(index);
|
this.tabBar.setSelectedItem(index);
|
||||||
|
|
||||||
|
this.controllerChanged && this.controllerChanged(lastController, lastIndex, this.selectedController, this.selectedIndex);
|
||||||
},
|
},
|
||||||
|
|
||||||
_showController: function(index) {
|
_showController: function(index) {
|
||||||
|
|||||||
11
js/ext/angular/src/directive/ionicTabBar.js
vendored
11
js/ext/angular/src/directive/ionicTabBar.js
vendored
@ -6,6 +6,14 @@ angular.module('ionic.ui.tabs', ['ngAnimate'])
|
|||||||
angular.extend(this, ionic.controllers.TabBarController.prototype);
|
angular.extend(this, ionic.controllers.TabBarController.prototype);
|
||||||
|
|
||||||
ionic.controllers.TabBarController.call(this, {
|
ionic.controllers.TabBarController.call(this, {
|
||||||
|
controllerChanged: function(oldC, oldI, newC, newI) {
|
||||||
|
$scope.controllerChanged && $scope.controllerChanged({
|
||||||
|
oldController: oldC,
|
||||||
|
oldIndex: oldI,
|
||||||
|
newController: newC,
|
||||||
|
newIndex: newI
|
||||||
|
});
|
||||||
|
},
|
||||||
tabBar: {
|
tabBar: {
|
||||||
tryTabSelect: function() {},
|
tryTabSelect: function() {},
|
||||||
setSelectedItem: function(index) {},
|
setSelectedItem: function(index) {},
|
||||||
@ -39,7 +47,8 @@ angular.module('ionic.ui.tabs', ['ngAnimate'])
|
|||||||
restrict: 'E',
|
restrict: 'E',
|
||||||
replace: true,
|
replace: true,
|
||||||
scope: {
|
scope: {
|
||||||
animation: '@'
|
animation: '@',
|
||||||
|
controllerChanged: '&'
|
||||||
},
|
},
|
||||||
transclude: true,
|
transclude: true,
|
||||||
controller: 'TabsCtrl',
|
controller: 'TabsCtrl',
|
||||||
|
|||||||
@ -36,6 +36,28 @@ describe('Tab Bar Controller', function() {
|
|||||||
|
|
||||||
expect(ctrl.getSelectedControllerIndex()).toEqual(1);
|
expect(ctrl.getSelectedControllerIndex()).toEqual(1);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('Calls change callback', function() {
|
||||||
|
scope.onControllerChanged = function(oldC, oldI, newC, newI) {
|
||||||
|
};
|
||||||
|
|
||||||
|
// Add a controller
|
||||||
|
ctrl.add({
|
||||||
|
title: 'Cats',
|
||||||
|
icon: 'icon-kitty-kat'
|
||||||
|
});
|
||||||
|
ctrl.add({
|
||||||
|
title: 'Dogs',
|
||||||
|
icon: 'icon-rufus'
|
||||||
|
});
|
||||||
|
|
||||||
|
spyOn(ctrl, 'controllerChanged');
|
||||||
|
|
||||||
|
expect(ctrl.getSelectedControllerIndex()).toEqual(0);
|
||||||
|
ctrl.select(1);
|
||||||
|
|
||||||
|
expect(ctrl.controllerChanged).toHaveBeenCalled();
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('Tab Bar directive', function() {
|
describe('Tab Bar directive', function() {
|
||||||
|
|||||||
@ -47,8 +47,8 @@
|
|||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body ng-controller="RootCtrl">
|
||||||
<tabs animation="fade-in-out">
|
<tabs animation="fade-in-out" controller-changed="onControllerChanged(oldController, oldIndex, newController, newIndex)">
|
||||||
|
|
||||||
<tab title="Home" icon-on="icon-ios7-filing" icon-off="icon-ios7-filing-outline" ng-controller="HomeCtrl">
|
<tab title="Home" icon-on="icon-ios7-filing" icon-off="icon-ios7-filing-outline" ng-controller="HomeCtrl">
|
||||||
<header class="bar bar-header bar-secondary">
|
<header class="bar bar-header bar-secondary">
|
||||||
@ -111,6 +111,14 @@
|
|||||||
<script>
|
<script>
|
||||||
angular.module('tabsTest', ['ionic.ui', 'ionic.service.modal', 'ionic.service.actionSheet'])
|
angular.module('tabsTest', ['ionic.ui', 'ionic.service.modal', 'ionic.service.actionSheet'])
|
||||||
|
|
||||||
|
.controller('RootCtrl', function($scope) {
|
||||||
|
$scope.onControllerChanged = function(oldController, oldIndex, newController, newIndex) {
|
||||||
|
console.log('Controller changed', oldController, oldIndex, newController, newIndex);
|
||||||
|
console.log(arguments);
|
||||||
|
};
|
||||||
|
})
|
||||||
|
|
||||||
|
|
||||||
.controller('HomeCtrl', function($scope, Modal, ActionSheet) {
|
.controller('HomeCtrl', function($scope, Modal, ActionSheet) {
|
||||||
$scope.items = [];
|
$scope.items = [];
|
||||||
|
|
||||||
|
|||||||
@ -17,6 +17,7 @@
|
|||||||
</header>
|
</header>
|
||||||
|
|
||||||
<main class="has-header content">
|
<main class="has-header content">
|
||||||
|
|
||||||
<div id="tab1">
|
<div id="tab1">
|
||||||
<h2>Tab 1</h2>
|
<h2>Tab 1</h2>
|
||||||
<p>
|
<p>
|
||||||
@ -42,7 +43,7 @@
|
|||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
</main>
|
</main>
|
||||||
<nav id="tab-bar" class="tabs tabs-top tabs-success"></nav>
|
<div id="tab-bar" class="tabs tabs-success"></div>
|
||||||
</section>
|
</section>
|
||||||
|
|
||||||
<script src="../../dist/js/ionic.js"></script>
|
<script src="../../dist/js/ionic.js"></script>
|
||||||
@ -88,7 +89,7 @@
|
|||||||
el: tab2
|
el: tab2
|
||||||
});
|
});
|
||||||
c2.title = 'Dogs';
|
c2.title = 'Dogs';
|
||||||
c2.icon = 'icon-gear';
|
c2.icon = 'icon-gear-a';
|
||||||
var c3 = new controller({
|
var c3 = new controller({
|
||||||
el: tab3
|
el: tab3
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user