From fbc13e7029c8217353ae1b03754bb7b3c2de9022 Mon Sep 17 00:00:00 2001 From: Rafael Tavares Date: Wed, 6 Jun 2018 18:03:05 -0300 Subject: [PATCH] Updates reCAPTCHA v2 definitions according to the docs --- types/grecaptcha/grecaptcha-tests.ts | 3 +++ types/grecaptcha/index.d.ts | 37 +++++++++++++++++++++------- 2 files changed, 31 insertions(+), 9 deletions(-) diff --git a/types/grecaptcha/grecaptcha-tests.ts b/types/grecaptcha/grecaptcha-tests.ts index f1da1b35b4..288836d6b3 100644 --- a/types/grecaptcha/grecaptcha-tests.ts +++ b/types/grecaptcha/grecaptcha-tests.ts @@ -4,8 +4,10 @@ const params: ReCaptchaV2.Parameters = { type: "image", size: "normal", tabindex: 5, + isolated: false, callback: (response: string) => { }, "expired-callback": () => { }, + "error-callback": () => { }, }; const size1: ReCaptchaV2.Size = "compact"; @@ -25,6 +27,7 @@ const id1: number = grecaptcha.render("foo"); const id2: number = grecaptcha.render("foo", params); const id3: number = grecaptcha.render(document.getElementById("foo")); const id4: number = grecaptcha.render(document.getElementById("foo"), params); +const id5: number = grecaptcha.render(document.getElementById("foo"), params, true); // response takes a number and returns a string const response1: string = grecaptcha.getResponse(id1); diff --git a/types/grecaptcha/index.d.ts b/types/grecaptcha/index.d.ts index 067139e6c9..c9dedbfb74 100644 --- a/types/grecaptcha/index.d.ts +++ b/types/grecaptcha/index.d.ts @@ -1,19 +1,24 @@ // Type definitions for Google Recaptcha 2.0 // Project: https://www.google.com/recaptcha -// Definitions by: Kristof Mattei , Martin Costello , Ruslan Arkhipau +// Definitions by: Kristof Mattei +// Martin Costello +// Ruslan Arkhipau +// Rafael Tavares // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped declare var grecaptcha: ReCaptchaV2.ReCaptcha; declare namespace ReCaptchaV2 { - class ReCaptcha { + interface ReCaptcha { /** * Renders the container as a reCAPTCHA widget and returns the ID of the newly created widget. * @param container The HTML element to render the reCAPTCHA widget. Specify either the ID of the container (string) or the DOM element itself. * @param parameters An object containing parameters as key=value pairs, for example, {"sitekey": "your_site_key", "theme": "light"}. See @see render parameters. + * @param inherit Invisible reCAPTCHA only. Use existing data-* attributes on the element if the corresponding parameter is not specified. + * The values in parameters will take precedence over the attributes. * @return the ID of the newly created widget. */ - render(container: (string | HTMLElement), parameters?: Parameters): number; + render(container: (string | HTMLElement), parameters?: Parameters, inherit?: boolean): number; /** * Resets the reCAPTCHA widget. * @param opt_widget_id Optional widget ID, defaults to the first widget created if unspecified. @@ -65,11 +70,6 @@ declare namespace ReCaptchaV2 { * If other elements in your page use tabindex, it should be set to make user navigation easier. */ tabindex?: number; - /** - * Optional. Your callback function that's executed when the user submits a successful CAPTCHA response. - * The user's response, g-recaptcha-response, will be the input for your callback function. - */ - callback?(response: string): void; /** * Optional. The badge location for g-recaptcha with size of "invisible". * @@ -77,10 +77,29 @@ declare namespace ReCaptchaV2 { */ badge?: Badge; /** - * Optional. Your callback function that's executed when the recaptcha response expires and the user needs to solve a new CAPTCHA. + * Optional. Invisible reCAPTCHA only. For plugin owners to not interfere with existing reCAPTCHA installations on a page. + * If true, this reCAPTCHA instance will be part of a separate ID space. + * + * @default false + */ + isolated?: boolean; + /** + * Optional. Your callback function that's executed when the user submits a successful CAPTCHA response. + * The user's response, g-recaptcha-response, will be the input for your callback function. + */ + callback?(response: string): void; + /** + * Optional. Your callback function that's executed when the reCAPTCHA response expires and the user needs to solve a new CAPTCHA. */ // Notice to the reader // I need to surround this object with quotes, this will however break intellisense in VS 2013. "expired-callback"?(): void; + /** + * Optional. Your callback function that's executed when reCAPTCHA encounters an error (usually network connectivity) and cannot continue until connectivity is restored. + * If you specify this function, you are responsible for informing the user that they should retry. + */ + // Notice to the reader + // I need to surround this object with quotes, this will however break intellisense in VS 2013. + "error-callback"?(): void; } }