UNPKG

ng2-recaptcha-fallback

Version:

Angular 2 component for Google reCAPTCHA

99 lines (98 loc) 3.97 kB
"use strict"; 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); }; var core_1 = require('@angular/core'); var recaptcha_loader_service_1 = require('./recaptcha-loader.service'); var nextId = 0; var RecaptchaComponent = (function () { function RecaptchaComponent(_el, _loader, _zone) { this._el = _el; this._loader = _loader; this._zone = _zone; this.id = "ngrecaptcha-" + nextId++; this.resolved = new core_1.EventEmitter(); } RecaptchaComponent.prototype.ngAfterViewInit = function () { var _this = this; this.subscription = this._loader.ready.subscribe(function (grecaptcha) { if (grecaptcha != null) { _this._grecaptcha = grecaptcha; _this._renderRecaptcha(); } }); }; RecaptchaComponent.prototype.ngOnDestroy = function () { this.subscription.unsubscribe(); }; RecaptchaComponent.prototype.reset = function () { if (this.widget != null) { this._grecaptcha.reset(this.widget); this.resolved.emit(null); } }; /** @internal */ RecaptchaComponent.prototype.captchaReponseCallback = function (response) { this.resolved.emit(response); }; /** @internal */ RecaptchaComponent.prototype._renderRecaptcha = function () { var _this = this; this.widget = this._grecaptcha.render(this.id, { callback: function (response) { _this._zone.run(function () { return _this.captchaReponseCallback(response); }); }, 'expired-callback': function () { _this._zone.run(function () { return _this.reset(); }); }, sitekey: this.siteKey, size: this.size, tabindex: this.tabIndex, theme: this.theme, type: this.type, }); }; __decorate([ core_1.Input(), __metadata('design:type', Object) ], RecaptchaComponent.prototype, "id", void 0); __decorate([ core_1.Input(), __metadata('design:type', String) ], RecaptchaComponent.prototype, "siteKey", void 0); __decorate([ core_1.Input(), __metadata('design:type', Object) ], RecaptchaComponent.prototype, "theme", void 0); __decorate([ core_1.Input(), __metadata('design:type', Object) ], RecaptchaComponent.prototype, "type", void 0); __decorate([ core_1.Input(), __metadata('design:type', Object) ], RecaptchaComponent.prototype, "size", void 0); __decorate([ core_1.Input(), __metadata('design:type', Number) ], RecaptchaComponent.prototype, "tabIndex", void 0); __decorate([ core_1.Output(), __metadata('design:type', Object) ], RecaptchaComponent.prototype, "resolved", void 0); RecaptchaComponent = __decorate([ core_1.Component({ selector: 'recaptcha', template: "<div [id]=\"id\"></div>", }), __metadata('design:paramtypes', [core_1.ElementRef, recaptcha_loader_service_1.RecaptchaLoaderService, core_1.NgZone]) ], RecaptchaComponent); return RecaptchaComponent; }()); exports.RecaptchaComponent = RecaptchaComponent;