Skip to content
This repository has been archived by the owner on Aug 17, 2021. It is now read-only.

Commit

Permalink
Merge pull request #110 from TheSharpieOne/feature/iss-25
Browse files Browse the repository at this point in the history
Add ability to set onload function name
  • Loading branch information
iambrosi committed Feb 18, 2016
2 parents 96f940a + 89b7e15 commit a15c614
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,10 @@ See [the demo file](demo/usage.html) for a quick usage example.
async defer
></script>
```
As you can see, we are specifying a `onload` callback, which will notify the
angular service once the api is ready for usage.

As you can see, we are specifying a `onload` callback, which will notify the angular service once the api is ready for usage.

The `onload` callback name defaults to `vcRecaptchaApiLoaded`, but can be overridden by the service provider via `vcRecaptchaServiceProvider.setOnLoadFunctionName('myOtherFunctionName');`.

- Also include the vc-recaptcha script and make your angular app depend on the `vcRecaptcha` module.

Expand Down
13 changes: 12 additions & 1 deletion src/service.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
app.provider('vcRecaptchaService', function(){
var provider = this;
var config = {};
provider.onLoadFunctionName = 'vcRecaptchaApiLoaded';

/**
* Sets the reCaptcha configuration values which will be used by default is not specified in a specific directive instance.
Expand Down Expand Up @@ -75,6 +76,16 @@
config.type = type;
};

/**
* Sets the reCaptcha configuration values which will be used by default is not specified in a specific directive instance.
*
* @since 2.5.0
* @param onLoadFunctionName string name which overrides the name of the onload function. Should match what is in the recaptcha script querystring onload value.
*/
provider.setOnLoadFunctionName = function(onLoadFunctionName){
provider.onLoadFunctionName = onLoadFunctionName;
};

provider.$get = ['$window', '$q', function ($window, $q) {
var deferred = $q.defer(), promise = deferred.promise, recaptcha;

Expand All @@ -88,7 +99,7 @@

$window.vcRecaptchaApiLoadedCallback.push(callback);

$window.vcRecaptchaApiLoaded = function () {
$window[provider.onLoadFunctionName] = function () {
$window.vcRecaptchaApiLoadedCallback.forEach(function(callback) {
callback();
});
Expand Down

0 comments on commit a15c614

Please sign in to comment.