1window.angular && (function(angular) { 2 'use strict'; 3 4 angular.module('app.common.directives') 5 .directive('appNavigation', function() { 6 return { 7 'restrict': 'E', 8 'template': require('./app-navigation.html'), 9 'scope': {'path': '=', 'showNavigation': '='}, 10 'controller': [ 11 '$scope', '$location', 'dataService', 12 function($scope, $location, dataService) { 13 $scope.dataService = dataService; 14 $scope.showSubMenu = false; 15 $scope.change = function(firstLevel) { 16 if (firstLevel != $scope.firstLevel) { 17 $scope.firstLevel = firstLevel; 18 $scope.showSubMenu = true; 19 } else { 20 $scope.showSubMenu = !$scope.showSubMenu; 21 } 22 }; 23 $scope.closeSubnav = function() { 24 $scope.showSubMenu = false; 25 }; 26 $scope.$watch('path', function() { 27 var urlRoot = $location.path().split('/')[1]; 28 if (urlRoot != '') { 29 $scope.firstLevel = urlRoot; 30 } else { 31 $scope.firstLevel = 'overview'; 32 } 33 $scope.showSubMenu = false; 34 }); 35 $scope.$watch('showNavigation', function() { 36 var paddingTop = 0; 37 var urlRoot = $location.path().split('/')[1]; 38 if (urlRoot != '') { 39 $scope.firstLevel = urlRoot; 40 } else { 41 $scope.firstLevel = 'overview'; 42 } 43 44 if ($scope.showNavigation) { 45 paddingTop = document.getElementById('header').offsetHeight; 46 } 47 dataService.bodyStyle = {'padding-top': paddingTop + 'px'}; 48 $scope.navStyle = {'top': paddingTop + 'px'}; 49 }); 50 } 51 ], 52 link: function(scope, element, attributes) { 53 var rawNavElement = angular.element(element)[0]; 54 angular.element(window.document).bind('click', function(event) { 55 if (rawNavElement.contains(event.target)) return; 56 57 if (scope.showSubMenu) { 58 scope.$apply(function() { 59 scope.showSubMenu = false; 60 }); 61 } 62 }); 63 } 64 }; 65 }); 66})(window.angular); 67