forked from dozoisch/react-google-recaptcha
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[changed] dynamic url creation to allow language change
- probably a good idea to set removeOnUnmount at the same time to avoid conflicts
- Loading branch information
Showing
3 changed files
with
22 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,25 @@ | ||
import ReCAPTCHA from "./recaptcha"; | ||
import makeAsyncScriptLoader from "react-async-script"; | ||
|
||
const callbackName = "onloadcallback"; | ||
const options = (typeof window !== "undefined" && window.recaptchaOptions) || {}; | ||
function getOptions() { | ||
return (typeof window !== "undefined" && window.recaptchaOptions) || {}; | ||
} | ||
function getURL() { | ||
const dynamicOptions = getOptions(); | ||
const lang = dynamicOptions.lang ? `&hl=${dynamicOptions.lang}` : ""; | ||
const hostname = dynamicOptions.useRecaptchaNet | ||
? "recaptcha.net" | ||
: "www.google.com"; | ||
return `https://${hostname}/recaptcha/api.js?onload=${callbackName}&render=explicit${lang}`; | ||
} | ||
|
||
const lang = options.lang ? `&hl=${options.lang}` : ""; | ||
const hostname = options.useRecaptchaNet ? "recaptcha.net" : "www.google.com"; | ||
const URL = `https://${hostname}/recaptcha/api.js?onload=${callbackName}&render=explicit${lang}`; | ||
const callbackName = "onloadcallback"; | ||
const globalName = "grecaptcha"; | ||
const initialOptions = getOptions(); | ||
|
||
export default makeAsyncScriptLoader(ReCAPTCHA, URL, { | ||
export default makeAsyncScriptLoader(ReCAPTCHA, getURL, { | ||
callbackName, | ||
globalName, | ||
exposeFuncs: ["getValue", "getWidgetId", "reset", "execute"], | ||
removeOnMount: initialOptions.removeOnMount || false, | ||
exposeFuncs: ["getValue", "getWidgetId", "reset", "execute"] | ||
}); |