2 lines
3.9 KiB
JavaScript
2 lines
3.9 KiB
JavaScript
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("react");function t(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var n=t(e);function r(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function o(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}function c(e,t){return c=Object.setPrototypeOf||function(e,t){return e.__proto__=t,e},c(e,t)}function i(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function");e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),Object.defineProperty(e,"prototype",{writable:!1}),t&&c(e,t)}function a(e){return a="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},a(e)}function p(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}function u(e,t){if(t&&("object"===a(t)||"function"==typeof t))return t;if(void 0!==t)throw new TypeError("Derived constructors may only return object or undefined");return p(e)}function s(e){return s=Object.setPrototypeOf?Object.getPrototypeOf:function(e){return e.__proto__||Object.getPrototypeOf(e)},s(e)}function l(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(e){return!1}}var f,h,y,d=function(t){i(d,e.Component);var c,a,p,f,h,y=(c=d,a=l(),function(){var e,t=s(c);if(a){var n=s(this).constructor;e=Reflect.construct(t,arguments,n)}else e=t.apply(this,arguments);return u(this,e)});function d(){return r(this,d),y.apply(this,arguments)}return p=d,(f=[{key:"init",value:function(){var e=this;this._instance=window.grecaptcha.render(this.targetEL,{sitekey:this.props.siteKey,theme:this.props.theme,type:this.props.type,size:this.props.size,tabindex:this.props.tabIndex,hl:this.props.language,callback:function(t){e.recaptchaCallback(t)},"expired-callback":function(){e.recaptchaExpiredCallback()}})}},{key:"reset",value:function(){null!==this._instance&&window.grecaptcha.reset(this._instance)}},{key:"getResponse",value:function(){return null===this._instance?null:window.grecaptcha.getResponse(this._instance)}},{key:"recaptchaCallback",value:function(e){this.props.onResponse&&this.props.onResponse({response:e})}},{key:"recaptchaExpiredCallback",value:function(){this.props.onExpire&&this.props.onExpire()}},{key:"addRecaptchaScript",value:function(){var e=this;if(this.recaptchaScript=null,!window.grecaptcha){var t=document.head||document.getElementsByTagName("head")[0];this.recaptchaScript=document.createElement("script"),this.recaptchaScript.src="https://www.google.com/recaptcha/api.js?render=explicit",this.recaptchaScript.async=!0,this.recaptchaScript.defer=!0,this.recaptchaScript.onload=function(){window.grecaptcha?window.grecaptcha.ready((function(){e.init()})):console.warn("Recaptcha is not loaded")},t.appendChild(this.recaptchaScript)}}},{key:"componentDidMount",value:function(){this.addRecaptchaScript(),window.grecaptcha&&this.init()}},{key:"componentWillUnmount",value:function(){this.recaptchaScript&&this.recaptchaScript.parentNode.removeChild(this.recaptchaScript)}},{key:"render",value:function(){var e=this;return n.default.createElement("div",{id:this.props.id,ref:function(t){return e.targetEL=t}})}}])&&o(p.prototype,f),h&&o(p,h),Object.defineProperty(p,"prototype",{writable:!1}),d}();y={id:null,siteKey:null,theme:"light",type:"image",size:"normal",tabIndex:0,language:"en",onResponse:null,onExpire:null},(h="defaultProps")in(f=d)?Object.defineProperty(f,h,{value:y,enumerable:!0,configurable:!0,writable:!0}):f[h]=y,exports.Captcha=d;
|