aboutsummaryrefslogtreecommitdiffstats
path: root/alias-angular/app/js/directives.js
blob: 3b9b652c1e26af21d6ebdea1faf8379cd827320b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
'use strict';
/* http://docs-next.angularjs.org/api/angular.module.ng.$compileProvider.directive */


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;
    });