From c0e29234f7681f88ada9aa4ce09a32f655cb3388 Mon Sep 17 00:00:00 2001 From: brentj73 Date: Wed, 23 Jul 2014 12:19:26 +0100 Subject: [PATCH] Added typing for recaptcha.js --- recaptcha/recaptcha-tests.ts | 52 ++++++++++++++++++++++++++++++++++++ recaptcha/recaptcha.d.ts | 39 +++++++++++++++++++++++++++ 2 files changed, 91 insertions(+) create mode 100644 recaptcha/recaptcha-tests.ts create mode 100644 recaptcha/recaptcha.d.ts diff --git a/recaptcha/recaptcha-tests.ts b/recaptcha/recaptcha-tests.ts new file mode 100644 index 000000000..61ef51d9f --- /dev/null +++ b/recaptcha/recaptcha-tests.ts @@ -0,0 +1,52 @@ +/// + +var recaptchaOptions: RecaptchaOptions = { + theme : 'custom', + custom_theme_widget: 'recaptcha_widget' + }; + +var recaptchaOptions: RecaptchaOptions = { + custom_translations: { instructions_visual: "This is my text:" } +}; + +var recaptchaOptions: RecaptchaOptions = { + custom_translations: { + instructions_visual: "Scrivi le due parole:", + instructions_audio: "Trascrivi ci\u00f2 che senti:", + play_again: "Riascolta la traccia audio", + cant_hear_this: "Scarica la traccia in formato MP3", + visual_challenge: "Modalit\u00e0 visiva", + audio_challenge: "Modalit\u00e0 auditiva", + refresh_btn: "Chiedi due nuove parole", + help_btn: "Aiuto", + incorrect_try_again: "Scorretto. Riprova.", + }, + lang: 'it', + theme: 'red' +}; + +var recaptchaOptions: RecaptchaOptions = { + theme : 'white', + tabindex : 2 +}; + +Recaptcha.create("public_key_a", + "element_id_a", + { + theme: "red", + callback: Recaptcha.focus_response_field + } +); + +Recaptcha.create("public_key_b", + "element_id_b", + recaptchaOptions +); + +Recaptcha.switch_type("audio"); +Recaptcha.get_challenge(); +Recaptcha.get_response(); +Recaptcha.reload(); +Recaptcha.showhelp(); +Recaptcha.focus_response_field(); +Recaptcha.destroy(); diff --git a/recaptcha/recaptcha.d.ts b/recaptcha/recaptcha.d.ts new file mode 100644 index 000000000..410db7651 --- /dev/null +++ b/recaptcha/recaptcha.d.ts @@ -0,0 +1,39 @@ +// Type definitions for Google Recaptcha +// Project: https://www.google.com/recaptcha +// Definitions by: Brent Jenkins +// Definitions: https://github.com/borisyankov/DefinitelyTyped + +declare class Recaptcha { + constructor(); + static reload(): void; + static switch_type(newtype: any); + static showhelp(): void; + static get_challenge(): string; + static get_response(): string; + static focus_response_field(): void; + static create(public_key: string, element: string, options: RecaptchaOptions): void; + static destroy(): void; +} + +interface RecaptchaOptions { + tabindex?: number; + theme?: string; + callback?: Function; + lang?: string; + custom_theme_widget?: string; + custom_translations?: CustomTranslations; +} + +interface CustomTranslations { + visual_challenge?: string; + audio_challenge?: string; + refresh_btn?: string; + instructions_visual?: string; + instructions_audio?: string; + help_btn?: string; + play_again?: string; + cant_hear_this?: string; + incorrect_try_again?: string; + image_alt_text?: string; + privacy_and_terms?: string; +} \ No newline at end of file