mirror of
https://github.com/wassname/DefinitelyTyped.git
synced 2026-08-20 12:00:53 +08:00
Added TSD for ReCaptchaV2
This commit is contained in:
@@ -0,0 +1,21 @@
|
||||
/// <reference path="grecaptcha.d.ts" />
|
||||
|
||||
var params: ReCaptchaV2.Parameters = {
|
||||
"sitekey": "mySuperSecretKey",
|
||||
"theme": "black", // no type-checking here.
|
||||
"type": "image",
|
||||
"tabindex": 5,
|
||||
"callback": (response: string) => { },
|
||||
"expired-callback": () => { },
|
||||
}
|
||||
|
||||
var id1: number = grecaptcha.render("foo");
|
||||
var id2: number = grecaptcha.render("foo", params);
|
||||
var id3: number = grecaptcha.render(document.getElementById("foo"));
|
||||
var id4: number = grecaptcha.render(document.getElementById("foo"), params);
|
||||
|
||||
// response takes a number and returns a string
|
||||
var response1: string = grecaptcha.getResponse(id1);
|
||||
|
||||
// reset takes a number
|
||||
grecaptcha.reset(id1);
|
||||
Vendored
+67
@@ -0,0 +1,67 @@
|
||||
// Type definitions for Google Recaptcha v2
|
||||
// Project: https://www.google.com/recaptcha
|
||||
// Definitions by: Kristof Mattei <http://kristofmattei.be>
|
||||
// Definitions: https://github.com/borisyankov/DefinitelyTyped
|
||||
|
||||
declare var grecaptcha: ReCaptchaV2.ReCaptcha;
|
||||
|
||||
declare module ReCaptchaV2
|
||||
{
|
||||
class 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.
|
||||
* @return the ID of the newly created widget.
|
||||
**/
|
||||
render(container: (string | HTMLElement), parameters?: Parameters): number;
|
||||
/**
|
||||
* Resets the reCAPTCHA widget.
|
||||
* @param opt_widget_id Optional widget ID, defaults to the first widget created if unspecified.
|
||||
**/
|
||||
reset(opt_widget_id?: number): void;
|
||||
/**
|
||||
* Gets the response for the reCAPTCHA widget.
|
||||
* @param opt_widget_id Optional widget ID, defaults to the first widget created if unspecified.
|
||||
* @return the response of the reCAPTCHA widget.
|
||||
**/
|
||||
getResponse(opt_widget_id?: number): string;
|
||||
}
|
||||
|
||||
interface Parameters
|
||||
{
|
||||
/**
|
||||
* Your sitekey.
|
||||
**/
|
||||
sitekey: string;
|
||||
/**
|
||||
* Optional. The color theme of the widget.
|
||||
* Accepted values: "light", "dark"
|
||||
* @default "light"
|
||||
**/
|
||||
theme?: string;
|
||||
/**
|
||||
* Optional. The type of CAPTCHA to serve.
|
||||
* Accepted values: "audio ", "image"
|
||||
* @default "image"
|
||||
**/
|
||||
type?: string;
|
||||
/**
|
||||
* Optional. The tabindex of the widget and challenge.
|
||||
* 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. 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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user