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 | d27bb13 | 2018-05-24 11:07:27 -0700 | [diff] [blame^] | 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 | } |
Iftekharul Islam | cd78950 | 2017-04-19 14:37:55 -0500 | [diff] [blame] | 43 | |
Andrew Geissler | d27bb13 | 2018-05-24 11:07:27 -0700 | [diff] [blame^] | 44 | 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 Geissler | ba5e3f3 | 2018-05-24 10:58:00 -0700 | [diff] [blame] | 50 | }); |
| 51 | } |
Andrew Geissler | d27bb13 | 2018-05-24 11:07:27 -0700 | [diff] [blame^] | 52 | ], |
| 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 Islam | 99d199f | 2017-03-24 15:28:25 -0500 | [diff] [blame] | 67 | })(window.angular); |