-
Notifications
You must be signed in to change notification settings - Fork 3.1k
/
Copy pathbaSidebar.directive.js
61 lines (53 loc) · 1.91 KB
/
baSidebar.directive.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
/**
* @author v.lugovksy
* created on 16.12.2015
*/
(function () {
'use strict';
angular.module('BlurAdmin.theme.components')
.directive('baSidebar', baSidebar);
/** @ngInject */
function baSidebar($timeout, baSidebarService, baUtil, layoutSizes) {
var jqWindow = $(window);
return {
restrict: 'E',
templateUrl: 'app/theme/components/baSidebar/ba-sidebar.html',
controller: 'BaSidebarCtrl',
link: function(scope, el) {
scope.menuHeight = el[0].childNodes[0].clientHeight - 84;
jqWindow.on('click', _onWindowClick);
jqWindow.on('resize', _onWindowResize);
scope.$on('$destroy', function() {
jqWindow.off('click', _onWindowClick);
jqWindow.off('resize', _onWindowResize);
});
function _onWindowClick($evt) {
if (!baUtil.isDescendant(el[0], $evt.target) &&
$evt.originalEvent &&
!$evt.originalEvent.$sidebarEventProcessed &&
!baSidebarService.isMenuCollapsed() &&
baSidebarService.canSidebarBeHidden()) {
$evt.originalEvent.$sidebarEventProcessed = true;
$timeout(function () {
baSidebarService.setMenuCollapsed(true);
}, 10);
}
}
// watch window resize to change menu collapsed state if needed
function _onWindowResize() {
var newMenuCollapsed = baSidebarService.shouldMenuBeCollapsed();
var newMenuHeight = _calculateMenuHeight();
if (newMenuCollapsed != baSidebarService.isMenuCollapsed() || scope.menuHeight != newMenuHeight) {
scope.$apply(function () {
scope.menuHeight = newMenuHeight;
baSidebarService.setMenuCollapsed(newMenuCollapsed)
});
}
}
function _calculateMenuHeight() {
return el[0].childNodes[0].clientHeight - 84;
}
}
};
}
})();