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

Commit c59c81e

Browse files
committed
[release]
1 parent dae2ea1 commit c59c81e

File tree

4 files changed

+74
-12
lines changed

4 files changed

+74
-12
lines changed

bower.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "angular-recaptcha",
3-
"version": "3.2.0",
3+
"version": "3.2.1",
44
"keywords": ["angular", "captcha", "recaptcha", "vividcortex", "human", "form", "validation", "signup", "security", "login"],
55
"main": "release/angular-recaptcha.js",
66
"ignore": [

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "angular-recaptcha",
3-
"version": "3.2.0",
3+
"version": "3.2.1",
44
"description": "An AngularJS module to ease usage of reCaptcha inside a form",
55
"author": "VividCortex",
66
"license": "MIT",

release/angular-recaptcha.js

Lines changed: 68 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/**
2-
* angular-recaptcha build:2016-07-19
3-
* https://github.com/vividcortex/angular-recaptcha
4-
* Copyright (c) 2016 VividCortex
2+
* @license angular-recaptcha build:2016-12-07
3+
* https://github.com/vividcortex/angular-recaptcha
4+
* Copyright (c) 2016 VividCortex
55
**/
66

77
/*global angular, Recaptcha */
@@ -90,6 +90,15 @@
9090
config.type = type;
9191
};
9292

93+
/**
94+
* Sets the reCaptcha language which will be used by default is not specified in a specific directive instance.
95+
*
96+
* @param lang The reCaptcha language.
97+
*/
98+
provider.setLang = function(lang){
99+
config.lang = lang;
100+
};
101+
93102
/**
94103
* Sets the reCaptcha configuration values which will be used by default is not specified in a specific directive instance.
95104
*
@@ -101,7 +110,7 @@
101110
};
102111

103112
provider.$get = ['$rootScope','$window', '$q', function ($rootScope, $window, $q) {
104-
var deferred = $q.defer(), promise = deferred.promise, recaptcha;
113+
var deferred = $q.defer(), promise = deferred.promise, instances = {}, recaptcha;
105114

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

@@ -156,12 +165,15 @@
156165
conf.stoken = conf.stoken || config.stoken;
157166
conf.size = conf.size || config.size;
158167
conf.type = conf.type || config.type;
168+
conf.hl = conf.lang || config.lang;
159169

160170
if (!conf.sitekey || conf.sitekey.length !== 40) {
161171
throwNoKeyException();
162172
}
163173
return getRecaptcha().then(function (recaptcha) {
164-
return recaptcha.render(elm, conf);
174+
var widgetId = recaptcha.render(elm, conf);
175+
instances[widgetId] = elm;
176+
return widgetId;
165177
});
166178
},
167179

@@ -171,13 +183,45 @@
171183
reload: function (widgetId) {
172184
validateRecaptchaInstance();
173185

174-
// $log.info('Reloading captcha');
175186
recaptcha.reset(widgetId);
176187

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

192+
/**
193+
* Get/Set reCaptcha language
194+
*/
195+
useLang: function (widgetId, lang) {
196+
var instance = instances[widgetId];
197+
198+
if (instance) {
199+
var iframe = instance.querySelector('iframe');
200+
if (lang) {
201+
// Setter
202+
if (iframe && iframe.src) {
203+
var s = iframe.src;
204+
if (/[?&]hl=/.test(s)) {
205+
s = s.replace(/([?&]hl=)\w+/, '$1' + lang);
206+
} else {
207+
s += ((s.indexOf('?') === -1) ? '?' : '&') + 'hl=' + lang;
208+
}
209+
210+
iframe.src = s;
211+
}
212+
} else {
213+
// Getter
214+
if (iframe && iframe.src && /[?&]hl=\w+/.test(iframe.src)) {
215+
return iframe.src.replace(/.+[?&]hl=(\w+)([^\w].+)?/, '$1');
216+
} else {
217+
return null;
218+
}
219+
}
220+
} else {
221+
throw new Error('reCaptcha Widget ID not exists', widgetId);
222+
}
223+
},
224+
181225
/**
182226
* Gets the response from the reCaptcha widget.
183227
*
@@ -189,6 +233,20 @@
189233
validateRecaptchaInstance();
190234

191235
return recaptcha.getResponse(widgetId);
236+
},
237+
238+
/**
239+
* Gets reCaptcha instance and configuration
240+
*/
241+
getInstance: function (widgetId) {
242+
return instances[widgetId];
243+
},
244+
245+
/**
246+
* Destroy reCaptcha instance.
247+
*/
248+
destroy: function (widgetId) {
249+
delete instances[widgetId];
192250
}
193251
};
194252

@@ -215,6 +273,7 @@
215273
theme: '=?',
216274
size: '=?',
217275
type: '=?',
276+
lang: '=?',
218277
tabindex: '=?',
219278
required: '=?',
220279
onCreate: '&',
@@ -247,6 +306,7 @@
247306
stoken: scope.stoken || attrs.stoken || null,
248307
theme: scope.theme || attrs.theme || null,
249308
type: scope.type || attrs.type || null,
309+
lang: scope.lang || attrs.lang || null,
250310
tabindex: scope.tabindex || attrs.tabindex || null,
251311
size: scope.size || attrs.size || null,
252312
'expired-callback': expired
@@ -299,6 +359,8 @@
299359
}
300360

301361
function cleanup(){
362+
vcRecaptcha.destroy(scope.widgetId);
363+
302364
// removes elements reCaptcha added.
303365
ng.element($document[0].querySelectorAll('.pls-container')).parent().remove();
304366
}

release/angular-recaptcha.min.js

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)