Andrew Geissler | ba5e3f3 | 2018-05-24 10:58:00 -0700 | [diff] [blame^] | 1 | window.angular && (function(angular) { |
| 2 | 'use strict'; |
Iftekharul Islam | 99d199f | 2017-03-24 15:28:25 -0500 | [diff] [blame] | 3 | |
Andrew Geissler | ba5e3f3 | 2018-05-24 10:58:00 -0700 | [diff] [blame^] | 4 | 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 Islam | cd78950 | 2017-04-19 14:37:55 -0500 | [diff] [blame] | 48 | |
Andrew Geissler | ba5e3f3 | 2018-05-24 10:58:00 -0700 | [diff] [blame^] | 49 | if ($scope.showNavigation) { |
| 50 | paddingTop = document.getElementById('header__wrapper').offsetHeight; |
| 51 | } |
| 52 | dataService.bodyStyle = { |
| 53 | 'padding-top': paddingTop + 'px' |
Iftekharul Islam | 99d199f | 2017-03-24 15:28:25 -0500 | [diff] [blame] | 54 | }; |
Andrew Geissler | ba5e3f3 | 2018-05-24 10:58:00 -0700 | [diff] [blame^] | 55 | $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 Islam | 99d199f | 2017-03-24 15:28:25 -0500 | [diff] [blame] | 75 | })(window.angular); |