|
|
|
@ -8,6 +8,7 @@
|
|
|
|
|
angular.module('BlurAdmin.theme.components')
|
|
|
|
|
.directive('baSidebarToggleMenu', baSidebarToggleMenu)
|
|
|
|
|
.directive('baSidebarCollapseMenu', baSidebarCollapseMenu)
|
|
|
|
|
.directive('baSidebarTogglingItem', baSidebarTogglingItem)
|
|
|
|
|
.directive('baUiSrefTogglingSubmenu', baUiSrefTogglingSubmenu)
|
|
|
|
|
.directive('baUiSrefToggler', baUiSrefToggler);
|
|
|
|
|
|
|
|
|
@ -44,33 +45,70 @@
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/** @ngInject */
|
|
|
|
|
function baUiSrefTogglingSubmenu($state) {
|
|
|
|
|
function baSidebarTogglingItem($state, baSidebarService) {
|
|
|
|
|
return {
|
|
|
|
|
restrict: 'A',
|
|
|
|
|
link: function(scope, el, attrs) {
|
|
|
|
|
var stateToWatch = scope.$eval(attrs.baUiSrefTogglingSubmenu);
|
|
|
|
|
controller: function ($scope, $element, $attrs) {
|
|
|
|
|
var vm = this;
|
|
|
|
|
var menuItem = vm.$$menuItem = $scope.$eval($attrs.baSidebarTogglingItem);
|
|
|
|
|
if (menuItem && menuItem.subMenu && menuItem.subMenu.length) {
|
|
|
|
|
vm.$$expandSubmenu = function() { console.warn('$$expandMenu should be overwritten by baUiSrefTogglingSubmenu') };
|
|
|
|
|
vm.$$collapseSubmenu = function() { console.warn('$$collapseSubmenu should be overwritten by baUiSrefTogglingSubmenu') };
|
|
|
|
|
|
|
|
|
|
var subItemsStateRefs = baSidebarService.getAllStateRefsRecursive(menuItem);
|
|
|
|
|
|
|
|
|
|
vm.$expand = function() {
|
|
|
|
|
vm.$$expandSubmenu();
|
|
|
|
|
$element.addClass('ba-sidebar-item-expanded');
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
vm.$collapse = function() {
|
|
|
|
|
vm.$$collapseSubmenu();
|
|
|
|
|
$element.removeClass('ba-sidebar-item-expanded');
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
vm.$toggle = function() {
|
|
|
|
|
$element.hasClass('ba-sidebar-item-expanded') ?
|
|
|
|
|
vm.$collapse() :
|
|
|
|
|
vm.$expand();
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
if (_isState($state.current)) {
|
|
|
|
|
el.parent().addClass('ba-sidebar-item-expanded');
|
|
|
|
|
$element.addClass('ba-sidebar-item-expanded');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
scope.$on('$stateChangeStart', function (event, toState) {
|
|
|
|
|
if (!_isState(toState) && el.parent().hasClass('ba-sidebar-item-expanded')) {
|
|
|
|
|
el.slideToggle();
|
|
|
|
|
el.parent().removeClass('ba-sidebar-item-expanded');
|
|
|
|
|
$scope.$on('$stateChangeStart', function (event, toState) {
|
|
|
|
|
if (!_isState(toState) && $element.hasClass('ba-sidebar-item-expanded')) {
|
|
|
|
|
vm.$collapse();
|
|
|
|
|
$element.removeClass('ba-sidebar-item-expanded');
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
scope.$on('$stateChangeSuccess', function (event, toState) {
|
|
|
|
|
if (_isState(toState) && !el.parent().hasClass('ba-sidebar-item-expanded')) {
|
|
|
|
|
el.slideToggle();
|
|
|
|
|
el.parent().addClass('ba-sidebar-item-expanded');
|
|
|
|
|
$scope.$on('$stateChangeSuccess', function (event, toState) {
|
|
|
|
|
if (_isState(toState) && !$element.hasClass('ba-sidebar-item-expanded')) {
|
|
|
|
|
vm.$expand();
|
|
|
|
|
$element.addClass('ba-sidebar-item-expanded');
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function _isState(state) {
|
|
|
|
|
return state && state.name.indexOf(stateToWatch) == 0;
|
|
|
|
|
return state && subItemsStateRefs.some(function(subItemState) {
|
|
|
|
|
return state.name.indexOf(subItemState) == 0;
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/** @ngInject */
|
|
|
|
|
function baUiSrefTogglingSubmenu($state) {
|
|
|
|
|
return {
|
|
|
|
|
restrict: 'A',
|
|
|
|
|
require: '^baSidebarTogglingItem',
|
|
|
|
|
link: function(scope, el, attrs, baSidebarTogglingItem) {
|
|
|
|
|
baSidebarTogglingItem.$$expandSubmenu = function() { el.slideDown(); };
|
|
|
|
|
baSidebarTogglingItem.$$collapseSubmenu = function() { el.slideUp(); };
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
@ -79,10 +117,10 @@
|
|
|
|
|
function baUiSrefToggler() {
|
|
|
|
|
return {
|
|
|
|
|
restrict: 'A',
|
|
|
|
|
link: function(scope, el, attrs) {
|
|
|
|
|
require: '^baSidebarTogglingItem',
|
|
|
|
|
link: function(scope, el, attrs, baSidebarTogglingItem) {
|
|
|
|
|
el.on('click', function() {
|
|
|
|
|
el.next().slideToggle();
|
|
|
|
|
el.parent().toggleClass('ba-sidebar-item-expanded');
|
|
|
|
|
baSidebarTogglingItem.$toggle();
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|