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

Add ability to set onload function name #110

Merged
merged 1 commit into from
Feb 18, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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