UNPKG

primeng

Version:

[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT) [![npm version](https://badge.fury.io/js/primeng.svg)](https://badge.fury.io/js/primeng) [![npm downloads](https://img.shields.io/npm/dm/primeng.sv

121 lines (117 loc) 3.44 kB
import { EventEmitter, Component, ChangeDetectionStrategy, ViewEncapsulation, ElementRef, NgZone, ChangeDetectorRef, Input, Output, NgModule } from '@angular/core'; import { CommonModule } from '@angular/common'; class Captcha { constructor(el, _zone, cd) { this.el = el; this._zone = _zone; this.cd = cd; this.siteKey = null; this.theme = 'light'; this.type = 'image'; this.size = 'normal'; this.tabindex = 0; this.initCallback = "initRecaptcha"; this.onResponse = new EventEmitter(); this.onExpire = new EventEmitter(); this._instance = null; this._language = null; } get language() { return this._language; } set language(language) { this._language = language; this.init(); } ngAfterViewInit() { if (window.grecaptcha) { if (!window.grecaptcha.render) { setTimeout(() => { this.init(); }, 100); } else { this.init(); } } else { window[this.initCallback] = () => { this.init(); }; } } init() { this._instance = window.grecaptcha.render(this.el.nativeElement.children[0], { 'sitekey': this.siteKey, 'theme': this.theme, 'type': this.type, 'size': this.size, 'tabindex': this.tabindex, 'hl': this.language, 'callback': (response) => { this._zone.run(() => this.recaptchaCallback(response)); }, 'expired-callback': () => { this._zone.run(() => this.recaptchaExpiredCallback()); } }); } reset() { if (this._instance === null) return; window.grecaptcha.reset(this._instance); this.cd.markForCheck(); } getResponse() { if (this._instance === null) return null; return window.grecaptcha.getResponse(this._instance); } recaptchaCallback(response) { this.onResponse.emit({ response: response }); } recaptchaExpiredCallback() { this.onExpire.emit(); } ngOnDestroy() { if (this._instance != null) { window.grecaptcha.reset(this._instance); } } } Captcha.decorators = [ { type: Component, args: [{ selector: 'p-captcha', template: `<div></div>`, changeDetection: ChangeDetectionStrategy.OnPush, encapsulation: ViewEncapsulation.None },] } ]; Captcha.ctorParameters = () => [ { type: ElementRef }, { type: NgZone }, { type: ChangeDetectorRef } ]; Captcha.propDecorators = { siteKey: [{ type: Input }], theme: [{ type: Input }], type: [{ type: Input }], size: [{ type: Input }], tabindex: [{ type: Input }], initCallback: [{ type: Input }], onResponse: [{ type: Output }], onExpire: [{ type: Output }], language: [{ type: Input }] }; class CaptchaModule { } CaptchaModule.decorators = [ { type: NgModule, args: [{ imports: [CommonModule], exports: [Captcha], declarations: [Captcha] },] } ]; /** * Generated bundle index. Do not edit. */ export { Captcha, CaptchaModule }; //# sourceMappingURL=primeng-captcha.js.map