mirror of
https://github.com/ansible/awx.git
synced 2026-05-20 07:17:40 -02:30
Move DOM event listener to directive
This commit is contained in:
@@ -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',
|
||||
|
||||
Reference in New Issue
Block a user