angular.module('zuykov', ['ui.bootstrap']); angular.module('zuykov') .controller('MainCtrl', ['$scope', function ($scope) { $scope.GetNoun = function(number, one, two, five) { number = Math.abs(number); number %= 100; if (number >= 5 && number <= 20) { return five; } number %= 10; if (number == 1) { return one; } if (number >= 2 && number <= 4) { return two; } return five; }; // GetNoun(6, 'яблоко', 'яблока', 'яблок') // Вернет «яблок» $scope.GetAdj = function(number, one, two) { number %= 100; if (number == 11) return two; number %= 10; if (number == 1) return one; return two; }; // GetAdj(6,'свежее', 'свежих') // Вернет «свежих» }]) .controller('TabsCtrl', ['$scope', function ($scope) { }]) .directive( 'ngTabs', function() { return { scope: true, restrict: 'EAC', controller: function( $scope ) { $scope.tabs = { index: 0, count: 0 }; this.headIndex = 0; this.bodyIndex = 0; this.getTabHeadIndex = function() { return $scope.tabs.count = ++this.headIndex; }; this.getTabBodyIndex = function() { return ++this.bodyIndex; }; } }; }) .directive( 'ngTabHead', function() { return { scope: false, restrict: 'EAC', require: '^ngTabs', link: function( scope, element, attributes, controller ) { var index = controller.getTabHeadIndex(); var value = attributes.ngTabHead; var active = /[-*\/%^=!<>&|]/.test( value ) ? scope.$eval( value ) : !!value; scope.tabs.index = scope.tabs.index || ( active ? index : null ); element.bind( 'click', function() { scope.tabs.index = index; scope.$$phase || scope.$apply(); }); scope.$watch( 'tabs.index', function() { element.toggleClass( 'active', scope.tabs.index === index ); }); } }; }) .directive( 'ngTabBody', function() { return { scope: false, restrict: 'EAC', require: '^ngTabs', link: function( scope, element, attributes, controller ) { var index = controller.getTabBodyIndex(); scope.$watch( 'tabs.index', function() { element.toggleClass( attributes.ngTabBody + ' show', scope.tabs.index === index ); }); } }; }); ;