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 ...

106 lines 3.67 kB
(function ($, angular, underscore, window, document, undefined) { 'use strict'; angular.module('frontend.directives').factory('accordionService', function () { var getOption = function (step, name, def) { if (step.hasAttribute(name)) return step.getAttribute(name); return def; }; return { parse: function (html) { var steps = []; var given = $(html); given.each(function (idx, step) { steps.push({ disabled: getOption(step, 'disabled', false), cssClass: getOption(step, 'css-class', ''), title: getOption(step, 'title', ''), titleTranslate: getOption(step, 'title-translate', null), icon: getOption(step, 'icon', null), onEnter: getOption(step, 'on-enter', null), onExit: getOption(step, 'on-exit', null), content: step.innerHTML }); }); return steps; } }; }).directive('accordion', [ '$compile', '$templateCache', 'accordionService', function ($compile, $templateCache, accordionService) { return { restrict: 'E', replace: true, scope: { disabled: '=?', visible: '=?', cssClass: '=?', onChanged: '<?', steps: '=?', model: '=?' }, compile: function ($$element) { var templateUrl = '/templates/framework/directives/accordion/template.html'; var template = $templateCache.get(templateUrl); var markup = $$element.html(); $$element.empty(); return { pre: function (scope, element, attr) { scope.vm = {}; 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.steps)) { scope.steps = accordionService.parse(markup); } if (angular.isUndefined(scope.model) && scope.steps.length) { scope.model = scope.steps[0]; } scope.vm.compile(); scope.vm.bind(); }; scope.vm.onPick = function (step) { if (scope.disabled || step.disabled) return; scope.model = step; }; scope.vm.bind = function () { scope.$watch('model', function (val, old) { if (!val) return; var onEnter = scope.$eval(val.onEnter); if (angular.isFunction(onEnter)) { onEnter(val); } if (old) { var oldOnExit = scope.$eval(old.onExit); if (angular.isFunction(oldOnExit)) oldOnExit(old, val); } if (angular.isFunction(scope.onChanged)) { scope.onChanged(val); } }); }; scope.vm.compile = function () { var content = $(template); element.append(content); $compile(content)(scope); }; scope.vm.init(); } }; } }; } ]); }(jQuery, angular, _, window, document));