blob: c1272de34bcf249de01fed555d0a1d2c9d9df550 [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 Geisslerd27bb132018-05-24 11:07:27 -07004 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 }
Iftekharul Islamcd789502017-04-19 14:37:55 -050043
Andrew Geisslerd27bb132018-05-24 11:07:27 -070044 if ($scope.showNavigation) {
45 paddingTop =
46 document.getElementById('header__wrapper').offsetHeight;
47 }
48 dataService.bodyStyle = {'padding-top': paddingTop + 'px'};
49 $scope.navStyle = {'top': paddingTop + 'px'};
Andrew Geisslerba5e3f32018-05-24 10:58:00 -070050 });
51 }
Andrew Geisslerd27bb132018-05-24 11:07:27 -070052 ],
53 link: function(scope, element, attributes) {
54 var rawNavElement = angular.element(element)[0];
55 angular.element(window.document).bind('click', function(event) {
56 if (rawNavElement.contains(event.target)) return;
57
58 if (scope.showSubMenu) {
59 scope.$apply(function() {
60 scope.showSubMenu = false;
61 });
62 }
63 });
64 }
65 };
66 });
Iftekharul Islam99d199f2017-03-24 15:28:25 -050067})(window.angular);