UNPKG

acha-framework

Version:

is a modular framework on both client (angular.js) and server (node.js) side, it provides security, orm, ioc, obfuscation and ...

141 lines 5.02 kB
(function ($, angular, underscore, window, document, undefined) { 'use strict'; angular.module('frontend.directives').directive('crumbNav', [ '$document', 'cultureService', function ($document, cultureService) { return { restrict: 'E', replace: true, scope: { tag: '<?', disabled: '=?', visible: '=?', cssClass: '=?', waiting: '=?', onSelect: '=?', onRefresh: '=?', model: '=?' }, templateUrl: '/templates/framework/directives/crumb-nav/template.html', link: function (scope, element, attr) { scope.vm = { rtl: cultureService.rtl }; scope.vm.init = function () { if (angular.isUndefined(scope.disabled)) { scope.disabled = false; } if (angular.isUndefined(scope.visible)) { scope.visible = true; } if (angular.isUndefined(scope.cssClass)) { scope.cssClass = ''; } if (angular.isUndefined(scope.model)) { scope.model = []; } scope.vm.bind(); }; scope.vm.bind = function () { $document.on('click', scope.vm.closeElseWhere); scope.$on('$destroy', function () { $document.off('click', scope.vm.closeElseWhere); $(window).off('resize', scope.vm.calculateWidth); }); scope.$watch('model', function () { scope.vm.calculateWidth(); }); $(window).on('resize', scope.vm.calculateWidth); }; scope.vm.onRoot = function () { if (angular.isFunction(scope.onSelect)) scope.onSelect({ path: '/' }); }; scope.vm.onAction = function (item) { if (item.action) item.action(item); if (angular.isFunction(scope.onSelect)) scope.onSelect(item); }; scope.vm.closeElseWhere = function () { scope.$timeout(function () { scope.vm.collapse(); }); }; scope.vm.collapse = function (except) { scope.model.forEach(function (item) { if (item === except) return; item.expand = false; }); }; scope.vm.onExpand = function (item, $event) { $event.stopPropagation(); $event.preventDefault(); scope.vm.collapse(item); if (item.expand === undefined) { item.expand = false; } item.expand = !item.expand; }; scope.vm.calculateWidth = underscore.debounce(function () { var totalWidth = 0; var sections = element.find('.root-folder'); sections.each(function (idx, elem) { totalWidth += $(elem).width(); totalWidth += 10; }); var container = element.find('.path-inner-container'); if (container.width() >= totalWidth) { container.removeClass('slide'); scope.vm.currentPosition = 0; element.find('.root-folders').css({ left: scope.vm.currentPosition }); } else { container.addClass('slide'); scope.vm.currentPosition = 25; element.find('.root-folders').css({ width: totalWidth, left: scope.vm.currentPosition }); } scope.vm.available = container.width(); scope.vm.totalWidth = totalWidth; scope.vm.gap = scope.vm.totalWidth - scope.vm.available; }, 300); scope.vm.scrollLeft = function () { if (scope.vm.currentPosition - 100 >= -25) { scope.vm.currentPosition -= 100; } else { scope.vm.currentPosition = -25; } var css = {}; if (cultureService.rtl) { css.left = scope.vm.currentPosition; } else { css.left = -scope.vm.currentPosition; } element.find('.root-folders').css(css); }; scope.vm.scrollRight = function () { if (scope.vm.currentPosition + 100 <= scope.vm.gap) { scope.vm.currentPosition += 100; } else { scope.vm.currentPosition = scope.vm.gap; } var css = {}; if (cultureService.rtl) { css.left = scope.vm.currentPosition; } else { css.left = -scope.vm.currentPosition; } element.find('.root-folders').css(css); }; scope.vm.refresh = function () { if (angular.isFunction(scope.onRefresh)) scope.onRefresh(); }; scope.vm.init(); } }; } ]); }(jQuery, angular, _, window, document));