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

66 lines 1.97 kB
(function ($, angular, underscore, window, document, undefined) { 'use strict'; angular.module('frontend.directives').factory('captchaService', [ 'apiService', function (apiService) { return { get: function () { return apiService.get('captcha/generate'); } }; } ]).directive('captcha', [ 'captchaService', function (captchaService) { return { restrict: 'E', replace: true, scope: { tag: '<?', disabled: '=?', visible: '=?', cssClass: '=?', triggerRefresh: '=?', model: '=?' }, templateUrl: '/templates/framework/directives/captcha/template.html', link: 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.model)) { scope.model = { value: '', key: '' }; } scope.vm.bind(); scope.vm.refresh(); }; scope.vm.refresh = scope.triggerRefresh = function () { scope.vm.waiting = true; captchaService.get().then(function (res) { scope.vm.waiting = false; if (res.status) { scope.vm.image = 'data:image/png;base64,' + res.data.image; scope.model.key = res.data.key; scope.model.value = ''; } }); }; scope.vm.bind = function () { }; scope.vm.init(); } }; } ]); }(jQuery, angular, _, window, document));