aboutsummaryrefslogtreecommitdiffstats
path: root/alias-angular/app/js/directives.js
diff options
context:
space:
mode:
authorGuillaume Horel <guillaume.horel@gmail.com>2012-04-22 22:48:30 -0400
committerGuillaume Horel <guillaume.horel@gmail.com>2012-04-22 22:48:30 -0400
commit58bd41bf1d15e9a8d70c9c9d88ccb39b81fdf8cb (patch)
tree5173c26597c6dc0d9e9efa0ebf98cbfa2c929c9f /alias-angular/app/js/directives.js
parenta7459f66525f4b1016146824506b016b718def1b (diff)
downloadalias-58bd41bf1d15e9a8d70c9c9d88ccb39b81fdf8cb.tar.gz
New version of the tabs using a directive
Diffstat (limited to 'alias-angular/app/js/directives.js')
-rw-r--r--alias-angular/app/js/directives.js33
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;
+ });