blob: 80d09ec373be24683e3d9a5ae4ba37eb27f9a52a [file] [log] [blame]
Andrew Geisslerba5e3f32018-05-24 10:58:00 -07001window.angular && (function(angular) {
2 'use strict';
Iftekharul Islam99d199f2017-03-24 15:28:25 -05003
Andrew Geisslerba5e3f32018-05-24 10:58:00 -07004 angular
5 .module('app.common.directives')
6 .directive('appNavigation', function() {
7 return {
8 'restrict': 'E',
9 'template': require('./app-navigation.html'),
10 'scope': {
11 'path': '=',
12 'showNavigation': '='
13 },
14 'controller': ['$scope', '$location', 'dataService', function($scope, $location, dataService) {
15 $scope.dataService = dataService;
16 $scope.showSubMenu = false;
17 $scope.change = function(firstLevel) {
18 if (firstLevel != $scope.firstLevel) {
19 $scope.firstLevel = firstLevel;
20 $scope.showSubMenu = true;
21 }
22 else {
23 $scope.showSubMenu = !$scope.showSubMenu;
24 }
25 };
26 $scope.closeSubnav = function() {
27 $scope.showSubMenu = false;
28 };
29 $scope.$watch('path', function() {
30 var urlRoot = $location.path().split('/')[1];
31 if (urlRoot != '') {
32 $scope.firstLevel = urlRoot;
33 }
34 else {
35 $scope.firstLevel = 'overview';
36 }
37 $scope.showSubMenu = false;
38 });
39 $scope.$watch('showNavigation', function() {
40 var paddingTop = 0;
41 var urlRoot = $location.path().split('/')[1];
42 if (urlRoot != '') {
43 $scope.firstLevel = urlRoot;
44 }
45 else {
46 $scope.firstLevel = 'overview';
47 }
Iftekharul Islamcd789502017-04-19 14:37:55 -050048
Andrew Geisslerba5e3f32018-05-24 10:58:00 -070049 if ($scope.showNavigation) {
50 paddingTop = document.getElementById('header__wrapper').offsetHeight;
51 }
52 dataService.bodyStyle = {
53 'padding-top': paddingTop + 'px'
Iftekharul Islam99d199f2017-03-24 15:28:25 -050054 };
Andrew Geisslerba5e3f32018-05-24 10:58:00 -070055 $scope.navStyle = {
56 'top': paddingTop + 'px'
57 };
58 });
59 }],
60 link: function(scope, element, attributes) {
61 var rawNavElement = angular.element(element)[0];
62 angular.element(window.document).bind('click', function(event) {
63 if (rawNavElement.contains(event.target))
64 return;
65
66 if (scope.showSubMenu) {
67 scope.$apply(function() {
68 scope.showSubMenu = false;
69 });
70 }
71 });
72 }
73 };
74 });
Iftekharul Islam99d199f2017-03-24 15:28:25 -050075})(window.angular);