diff options
Diffstat (limited to 'alias-angular/app/js/directives.js')
| -rw-r--r-- | alias-angular/app/js/directives.js | 33 |
1 files changed, 27 insertions, 6 deletions
diff --git a/alias-angular/app/js/directives.js b/alias-angular/app/js/directives.js index 8ed47bb..3b9b652 100644 --- a/alias-angular/app/js/directives.js +++ b/alias-angular/app/js/directives.js @@ -2,9 +2,30 @@ /* http://docs-next.angularjs.org/api/angular.module.ng.$compileProvider.directive */ -angular.module('myApp.directives', []). - directive('appVersion', ['version', function(version) { - return function(scope, elm, attrs) { - elm.text(version); - }; - }]); +angular.module('Alias.directives', []). + directive('navTabs', function($log) { + var directiveDefinition = { + restrict: 'C', + link: function(scope, elm, attrs) { + var tabs = elm.find('li'); + var selectedTab = tabs.filter('.active'); + if (!selectedTab.length) { + selectedTab = tabs.filter(':first'); + selectedTab.addClass('active'); + } + var selectedPane = $(selectedTab.find('a').attr('href')); + selectedPane.addClass('active'); + + elm.on('click', function(event) { + selectedTab.removeClass('active'); + selectedPane.removeClass('active'); + selectedTab = angular.element(event.target).parent(); + selectedPane = $(selectedTab.find('a').attr('href')); + selectedTab.addClass('active'); + selectedPane.addClass('active'); + event.preventDefault(); + }); + } + }; + return directiveDefinition; + }); |
