Iftekharul Islam | 99d199f | 2017-03-24 15:28:25 -0500 | [diff] [blame] | 1 | window.angular && (function (angular) { |
| 2 | 'use strict'; |
| 3 | |
| 4 | angular |
| 5 | .module('app.common.directives') |
| 6 | .directive('appNavigation', function () { |
| 7 | return { |
| 8 | 'restrict': 'E', |
Ed Tanous | bbcf670 | 2017-10-06 13:53:06 -0700 | [diff] [blame] | 9 | 'template': require('./app-navigation.html'), |
Iftekharul Islam | 99d199f | 2017-03-24 15:28:25 -0500 | [diff] [blame] | 10 | 'scope': { |
| 11 | 'path': '=', |
| 12 | 'showNavigation': '=' |
| 13 | }, |
Iftekharul Islam | cd78950 | 2017-04-19 14:37:55 -0500 | [diff] [blame] | 14 | 'controller': ['$scope', '$location', 'dataService', function($scope, $location, dataService){ |
Iftekharul Islam | 3471409 | 2017-09-06 10:45:27 -0500 | [diff] [blame] | 15 | $scope.dataService = dataService; |
Iftekharul Islam | 685fe75 | 2017-05-05 09:17:54 -0500 | [diff] [blame] | 16 | $scope.showSubMenu = false; |
Iftekharul Islam | cd78950 | 2017-04-19 14:37:55 -0500 | [diff] [blame] | 17 | $scope.change = function(firstLevel){ |
Iftekharul Islam | 685fe75 | 2017-05-05 09:17:54 -0500 | [diff] [blame] | 18 | if(firstLevel != $scope.firstLevel) { |
| 19 | $scope.firstLevel = firstLevel; |
| 20 | $scope.showSubMenu = true; |
| 21 | }else{ |
| 22 | $scope.showSubMenu = !$scope.showSubMenu; |
| 23 | } |
Michael Davis | 272297b | 2017-04-24 12:11:53 -0500 | [diff] [blame] | 24 | }; |
| 25 | $scope.closeSubnav = function(){ |
Iftekharul Islam | 685fe75 | 2017-05-05 09:17:54 -0500 | [diff] [blame] | 26 | $scope.showSubMenu = false; |
Michael Davis | 272297b | 2017-04-24 12:11:53 -0500 | [diff] [blame] | 27 | }; |
Iftekharul Islam | 3471409 | 2017-09-06 10:45:27 -0500 | [diff] [blame] | 28 | $scope.$watch('path', function(){ |
| 29 | var urlRoot = $location.path().split("/")[1]; |
| 30 | if(urlRoot != ""){ |
| 31 | $scope.firstLevel = urlRoot; |
| 32 | }else{ |
| 33 | $scope.firstLevel = 'overview'; |
| 34 | } |
| 35 | $scope.showSubMenu = false; |
| 36 | }); |
Iftekharul Islam | 99d199f | 2017-03-24 15:28:25 -0500 | [diff] [blame] | 37 | $scope.$watch('showNavigation', function(){ |
| 38 | var paddingTop = 0; |
Iftekharul Islam | 685fe75 | 2017-05-05 09:17:54 -0500 | [diff] [blame] | 39 | var urlRoot = $location.path().split("/")[1]; |
| 40 | if(urlRoot != ""){ |
| 41 | $scope.firstLevel = urlRoot; |
| 42 | }else{ |
| 43 | $scope.firstLevel = 'overview'; |
| 44 | } |
Iftekharul Islam | cd78950 | 2017-04-19 14:37:55 -0500 | [diff] [blame] | 45 | |
Iftekharul Islam | 99d199f | 2017-03-24 15:28:25 -0500 | [diff] [blame] | 46 | if($scope.showNavigation){ |
| 47 | paddingTop = document.getElementById('header__wrapper').offsetHeight; |
| 48 | } |
| 49 | dataService.bodyStyle = {'padding-top': paddingTop + 'px'}; |
| 50 | $scope.navStyle = {'top': paddingTop + 'px'}; |
| 51 | }); |
Iftekharul Islam | f74f8a0 | 2018-02-08 13:58:10 -0600 | [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)) |
| 57 | return; |
| 58 | |
| 59 | if(scope.showSubMenu){ |
| 60 | scope.$apply(function(){ |
| 61 | scope.showSubMenu = false; |
| 62 | }); |
| 63 | } |
| 64 | }); |
| 65 | } |
Iftekharul Islam | 99d199f | 2017-03-24 15:28:25 -0500 | [diff] [blame] | 66 | }; |
| 67 | }); |
| 68 | })(window.angular); |