From bb625264d47dfa086d2818384dabbf34464fa20b Mon Sep 17 00:00:00 2001 From: Marliana Lara Date: Mon, 25 Sep 2017 11:56:26 -0400 Subject: [PATCH] Move DOM event listener to directive --- awx/ui/client/legacy/styles/ansible-ui.less | 8 ------ .../client/lib/components/layout/_index.less | 14 ++++++++--- .../components/layout/side-nav.directive.js | 25 +++++++++++++------ 3 files changed, 28 insertions(+), 19 deletions(-) diff --git a/awx/ui/client/legacy/styles/ansible-ui.less b/awx/ui/client/legacy/styles/ansible-ui.less index c66fff4412..b05aa51148 100644 --- a/awx/ui/client/legacy/styles/ansible-ui.less +++ b/awx/ui/client/legacy/styles/ansible-ui.less @@ -2327,12 +2327,4 @@ body { .btn { text-transform: uppercase; -} - -@breakpoint-sm: 700px; - -@media screen and (max-width: @breakpoint-sm) { - #content-container { - padding-top: 100px; - } } \ No newline at end of file diff --git a/awx/ui/client/lib/components/layout/_index.less b/awx/ui/client/lib/components/layout/_index.less index 64b07eda2c..78e7bf42b6 100644 --- a/awx/ui/client/lib/components/layout/_index.less +++ b/awx/ui/client/lib/components/layout/_index.less @@ -83,6 +83,7 @@ } &-side { + background: @at-color-side-nav-background; position: fixed; bottom: 0; top: @at-height-top-side-nav-makeup; @@ -92,7 +93,7 @@ z-index: @at-z-index-side-nav; .at-Layout-sideNavItem { - background: @at-color-side-nav-background; + background: inherit; color: @at-color-side-nav-content; display: flex; cursor: pointer; @@ -122,8 +123,8 @@ } .at-Layout-sideNavSpacer { + background: inherit; height: @at-height-side-nav-spacer; - background: @at-color-side-nav-background; } &--expanded { @@ -174,13 +175,13 @@ } } - @breakpoint-sm: 700px; @media screen and (max-width: @breakpoint-sm) { .at-Layout { &-side { top: 60px; + background-color: transparent; .at-Layout-sideNavItem.at-Layout-sideNavToggle { display: flex; @@ -192,6 +193,7 @@ .at-Layout-sideNavItem, .at-Layout-sideNavSpacer { display: none; + background-color: @at-color-side-nav-background; } &--expanded { @@ -207,6 +209,10 @@ .at-Layout-main { padding-left: 0; + + #content-container { + padding-top: 100px; + } } } -} +} \ No newline at end of file diff --git a/awx/ui/client/lib/components/layout/side-nav.directive.js b/awx/ui/client/lib/components/layout/side-nav.directive.js index e819549e83..85ee926cec 100644 --- a/awx/ui/client/lib/components/layout/side-nav.directive.js +++ b/awx/ui/client/lib/components/layout/side-nav.directive.js @@ -2,28 +2,39 @@ const templateUrl = require('~components/layout/side-nav.partial.html'); function atSideNavLink (scope, element, attrs, ctrl) { scope.layoutVm = ctrl; + + document.on('click', (e) => { + if ($(e.target).parents('.at-Layout-side').length === 0) { + scope.$emit('clickOutsideSideNav'); + } + }); } -function AtSideNavController ($scope) { +function AtSideNavController ($scope, $window) { let vm = this || {}; + const breakpoint = 700; vm.isExpanded = false; vm.toggleExpansion = () => { vm.isExpanded = !vm.isExpanded; - } + }; - document.body.onclick = (e) => { - if ($(e.target).parents(".at-Layout-side").length === 0) { + $scope.$watch('layoutVm.currentState', () => { + if ($window.innerWidth <= breakpoint) { vm.isExpanded = false; } - } + }); - $scope.$on('$locationChangeStart', function(event) { - vm.isExpanded = false; + $scope.$on('clickOutsideSideNav', () => { + if ($window.innerWidth <= breakpoint) { + vm.isExpanded = false; + } }); } +AtSideNavController.$inject = ['$scope', '$window']; + function atSideNav () { return { restrict: 'E',