UNPKG

google-recaptcha-angular

Version:
79 lines 3.69 kB
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; return c > 3 && r && Object.defineProperty(target, key, r), r; }; var __metadata = (this && this.__metadata) || function (k, v) { if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v); }; import { Directive, EventEmitter, Input, Output } from '@angular/core'; var ReCaptchaRenderDirective = (function () { function ReCaptchaRenderDirective() { } ReCaptchaRenderDirective.prototype.ngOnInit = function () { var _this = this; this.key = null; this.render = 2500; this.recaptchaRenderElm = null; this.onCaptchaSubmit = new EventEmitter(); setTimeout(function () { var recaptchaStyle = _this.propertiesReCaptcha(); var reCaptchaElm = document.getElementById(_this.recaptchaId); var scripts = document.createElement('script'); scripts.src = 'https://www.google.com/recaptcha/api.js'; scripts.async = true; scripts.defer = true; var $this = _this; scripts.onload = function () { setTimeout(function () { $this.recaptchaRenderElm = grecaptcha.render(reCaptchaElm, recaptchaStyle); }, 10); }; document.getElementsByTagName('head')[0].appendChild(scripts); }, this.render); }; ReCaptchaRenderDirective.prototype.recaptchaRestar = function () { this.recaptchaExpired(); }; ReCaptchaRenderDirective.prototype.propertiesReCaptcha = function () { var _this = this; var recaptchaProperties = {}; recaptchaProperties['key'] = this.key; recaptchaProperties['callback'] = function (data) { return _this.onCaptchaSubmit.emit(data); }; recaptchaProperties['expired-callback'] = function () { return _this.recaptchaExpired(); }; return recaptchaProperties; }; ReCaptchaRenderDirective.prototype.recaptchaExpired = function () { if (this.recaptchaRenderElm === null) { return; } grecaptcha.reset(this.recaptchaRenderElm); this.onCaptchaSubmit.emit(null); }; __decorate([ Output('onCaptchaSubmit'), __metadata("design:type", EventEmitter) ], ReCaptchaRenderDirective.prototype, "onCaptchaSubmit", void 0); __decorate([ Input('key'), __metadata("design:type", String) ], ReCaptchaRenderDirective.prototype, "key", void 0); __decorate([ Input('render'), __metadata("design:type", Number) ], ReCaptchaRenderDirective.prototype, "render", void 0); __decorate([ Input('recaptchaId'), __metadata("design:type", String) ], ReCaptchaRenderDirective.prototype, "recaptchaId", void 0); ReCaptchaRenderDirective = __decorate([ Directive({ selector: '[appReCaptchaRender]' }), __metadata("design:paramtypes", []) ], ReCaptchaRenderDirective); return ReCaptchaRenderDirective; }()); export { ReCaptchaRenderDirective }; //# sourceMappingURL=re-captcha-render.directive.js.map