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

Commit

Permalink
[release]
Browse files Browse the repository at this point in the history
  • Loading branch information
iambrosi committed Dec 7, 2016
1 parent dae2ea1 commit c59c81e
Show file tree
Hide file tree
Showing 4 changed files with 74 additions and 12 deletions.
2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "angular-recaptcha",
"version": "3.2.0",
"version": "3.2.1",
"keywords": ["angular", "captcha", "recaptcha", "vividcortex", "human", "form", "validation", "signup", "security", "login"],
"main": "release/angular-recaptcha.js",
"ignore": [
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "angular-recaptcha",
"version": "3.2.0",
"version": "3.2.1",
"description": "An AngularJS module to ease usage of reCaptcha inside a form",
"author": "VividCortex",
"license": "MIT",
Expand Down
74 changes: 68 additions & 6 deletions release/angular-recaptcha.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* angular-recaptcha build:2016-07-19
* https://github.com/vividcortex/angular-recaptcha
* Copyright (c) 2016 VividCortex
* @license angular-recaptcha build:2016-12-07
* https://github.com/vividcortex/angular-recaptcha
* Copyright (c) 2016 VividCortex
**/

/*global angular, Recaptcha */
Expand Down Expand Up @@ -90,6 +90,15 @@
config.type = type;
};

/**
* Sets the reCaptcha language which will be used by default is not specified in a specific directive instance.
*
* @param lang The reCaptcha language.
*/
provider.setLang = function(lang){
config.lang = lang;
};

/**
* Sets the reCaptcha configuration values which will be used by default is not specified in a specific directive instance.
*
Expand All @@ -101,7 +110,7 @@
};

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

$window.vcRecaptchaApiLoadedCallback = $window.vcRecaptchaApiLoadedCallback || [];

Expand Down Expand Up @@ -156,12 +165,15 @@
conf.stoken = conf.stoken || config.stoken;
conf.size = conf.size || config.size;
conf.type = conf.type || config.type;
conf.hl = conf.lang || config.lang;

if (!conf.sitekey || conf.sitekey.length !== 40) {
throwNoKeyException();
}
return getRecaptcha().then(function (recaptcha) {
return recaptcha.render(elm, conf);
var widgetId = recaptcha.render(elm, conf);
instances[widgetId] = elm;
return widgetId;
});
},

Expand All @@ -171,13 +183,45 @@
reload: function (widgetId) {
validateRecaptchaInstance();

// $log.info('Reloading captcha');
recaptcha.reset(widgetId);

// Let everyone know this widget has been reset.
$rootScope.$broadcast('reCaptchaReset', widgetId);
},

/**
* Get/Set reCaptcha language
*/
useLang: function (widgetId, lang) {
var instance = instances[widgetId];

if (instance) {
var iframe = instance.querySelector('iframe');
if (lang) {
// Setter
if (iframe && iframe.src) {
var s = iframe.src;
if (/[?&]hl=/.test(s)) {
s = s.replace(/([?&]hl=)\w+/, '$1' + lang);
} else {
s += ((s.indexOf('?') === -1) ? '?' : '&') + 'hl=' + lang;
}

iframe.src = s;
}
} else {
// Getter
if (iframe && iframe.src && /[?&]hl=\w+/.test(iframe.src)) {
return iframe.src.replace(/.+[?&]hl=(\w+)([^\w].+)?/, '$1');
} else {
return null;
}
}
} else {
throw new Error('reCaptcha Widget ID not exists', widgetId);
}
},

/**
* Gets the response from the reCaptcha widget.
*
Expand All @@ -189,6 +233,20 @@
validateRecaptchaInstance();

return recaptcha.getResponse(widgetId);
},

/**
* Gets reCaptcha instance and configuration
*/
getInstance: function (widgetId) {
return instances[widgetId];
},

/**
* Destroy reCaptcha instance.
*/
destroy: function (widgetId) {
delete instances[widgetId];
}
};

Expand All @@ -215,6 +273,7 @@
theme: '=?',
size: '=?',
type: '=?',
lang: '=?',
tabindex: '=?',
required: '=?',
onCreate: '&',
Expand Down Expand Up @@ -247,6 +306,7 @@
stoken: scope.stoken || attrs.stoken || null,
theme: scope.theme || attrs.theme || null,
type: scope.type || attrs.type || null,
lang: scope.lang || attrs.lang || null,
tabindex: scope.tabindex || attrs.tabindex || null,
size: scope.size || attrs.size || null,
'expired-callback': expired
Expand Down Expand Up @@ -299,6 +359,8 @@
}

function cleanup(){
vcRecaptcha.destroy(scope.widgetId);

// removes elements reCaptcha added.
ng.element($document[0].querySelectorAll('.pls-container')).parent().remove();
}
Expand Down
8 changes: 4 additions & 4 deletions release/angular-recaptcha.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit c59c81e

Please sign in to comment.