angular.module('ionic.ui.tabs', ['ngAnimate']) .controller('TabsCtrl', ['$scope', '$element', '$animate', function($scope, $element, $animate) { var _this = this; angular.extend(this, ionic.controllers.TabBarController.prototype); ionic.controllers.TabBarController.call(this, { tabBar: { tryTabSelect: function() {}, setSelectedItem: function(index) {}, addItem: function(item) {} } }); this.add = function(controller) { this.addController(controller); this.select(0); }; this.select = function(controllerIndex) { var oldIndex = _this.getSelectedIndex(); $scope.activeAnimation = $scope.animation; /* if(controllerIndex > oldIndex) { } else if(controllerIndex < oldIndex) { $scope.activeAnimation = $scope.animation + '-reverse'; } */ _this.selectController(controllerIndex); }; $scope.controllers = this.controllers; }]) .directive('tabs', function() { return { restrict: 'E', replace: true, scope: { animation: '@' }, transclude: true, controller: 'TabsCtrl', //templateUrl: 'ext/angular/tmpl/ionicTabBar.tmpl.html', template: '
', compile: function(element, attr, transclude, tabsCtrl) { return function($scope, $element, $attr) { $scope.$watch('activeAnimation', function(value) { //$element.removeClass($scope.animation + ' ' + $scope.animation + '-reverse'); $element.addClass($scope.activeAnimation); }); transclude($scope, function(cloned) { $element.prepend(cloned); }); }; } }; }) // Generic controller directive .directive('tab', ['$animate', function($animate) { return { restrict: 'E', replace: true, require: '^tabs', scope: true, transclude: 'element', compile: function(element, attr, transclude) { return function($scope, $element, $attr, tabsCtrl) { var childScope, childElement; $scope.$watch('isVisible', function(value) { if(childElement) { $animate.leave(childElement); childElement = undefined; } if(childScope) { childScope.$destroy(); childScope = undefined; } if(value) { childScope = $scope.$new(); transclude(childScope, function(clone) { childElement = clone; childElement.addClass('view-full'); $animate.enter(clone, $element.parent(), $element); }); } }); $scope.title = $attr.title; $scope.icon = $attr.icon; $scope.iconOn = $attr.iconOn; $scope.iconOff = $attr.iconOff; tabsCtrl.add($scope); } } }; }]) .directive('tabControllerBar', function() { return { restrict: 'E', require: '^tabs', transclude: true, replace: true, scope: true, template: '
' + '' + '
' }; }) .directive('tabControllerItem', function() { return { restrict: 'E', replace: true, require: '^tabs', scope: { title: '@', iconOn: '@', iconOff: '@', active: '=', tabSelected: '@', index: '=' }, link: function(scope, element, attrs, tabsCtrl) { scope.selectTab = function(index) { tabsCtrl.select(scope.index); }; }, template: '' + '' + '' + ' {{title}}' + '' }; }) .directive('tabBar', function() { return { restrict: 'E', replace: true, transclude: true, template: '
' + '
' } }) .directive('tabItem', function() { return { restrict: 'E', replace: true, scope: { title: '@', iconOn: '@', iconOff: '@', active: '=', tabSelected: '@', index: '=' }, link: function(scope, element, attrs) { }, template: '' + '' + '' + ' {{title}}' + '' }; });