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

Commit 3bff3a0

Browse files
committed
Create releases.
1 parent d001b38 commit 3bff3a0

File tree

2 files changed

+47
-42
lines changed

2 files changed

+47
-42
lines changed

release/angular-recaptcha.js

Lines changed: 44 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/**
2-
* @license angular-recaptcha build:2017-11-22
2+
* @license angular-recaptcha build:2018-01-03
33
* https://github.com/vividcortex/angular-recaptcha
4-
* Copyright (c) 2017 VividCortex
4+
* Copyright (c) 2018 VividCortex
55
**/
66

77
/*global angular, Recaptcha */
@@ -295,11 +295,11 @@
295295

296296
var app = ng.module('vcRecaptcha');
297297

298-
app.directive('vcRecaptcha', ['$document', '$timeout', 'vcRecaptchaService', function ($document, $timeout, vcRecaptcha) {
298+
app.directive('vcRecaptcha', ['$document', '$timeout', 'vcRecaptchaService', '$q', function ($document, $timeout, vcRecaptcha, $q) {
299299

300300
return {
301301
restrict: 'A',
302-
require: "?^^form",
302+
require: '?^^form',
303303
scope: {
304304
response: '=?ngModel',
305305
key: '=?',
@@ -318,11 +318,16 @@
318318
link: function (scope, elm, attrs, ctrl) {
319319
scope.widgetId = null;
320320

321-
if(ctrl && ng.isDefined(attrs.required)){
321+
if (ctrl && ng.isDefined(attrs.required)) {
322322
scope.$watch('required', validate);
323323
}
324324

325325
var removeCreationListener = scope.$watch('key', function (key) {
326+
// Abort if undefined or null
327+
if (ng.isUndefined(key) || key === null) {
328+
return;
329+
}
330+
326331
var callback = function (gRecaptchaResponse) {
327332
// Safe $apply
328333
$timeout(function () {
@@ -334,19 +339,20 @@
334339
});
335340
};
336341

337-
vcRecaptcha.create(elm[0], {
338-
339-
callback: callback,
340-
key: key,
341-
stoken: scope.stoken || attrs.stoken || null,
342-
theme: scope.theme || attrs.theme || null,
343-
type: scope.type || attrs.type || null,
344-
lang: scope.lang || attrs.lang || null,
345-
tabindex: scope.tabindex || attrs.tabindex || null,
346-
size: scope.size || attrs.size || null,
347-
badge: scope.badge || attrs.badge || null,
348-
'expired-callback': expired
349-
342+
// Accept a promise, or resolve immediately if the value is a bare string
343+
$q.resolve(key).then(function (resolved) {
344+
return vcRecaptcha.create(elm[0], {
345+
callback: callback,
346+
key: resolved,
347+
stoken: scope.stoken || attrs.stoken || null,
348+
theme: scope.theme || attrs.theme || null,
349+
type: scope.type || attrs.type || null,
350+
lang: scope.lang || attrs.lang || null,
351+
tabindex: scope.tabindex || attrs.tabindex || null,
352+
size: scope.size || attrs.size || null,
353+
badge: scope.badge || attrs.badge || null,
354+
'expired-callback': expired
355+
});
350356
}).then(function (widgetId) {
351357
// The widget has been created
352358
validate();
@@ -355,50 +361,49 @@
355361

356362
scope.$on('$destroy', destroy);
357363

358-
scope.$on('reCaptchaReset', function(event, resetWidgetId){
359-
if(ng.isUndefined(resetWidgetId) || widgetId === resetWidgetId){
360-
scope.response = "";
361-
validate();
362-
}
363-
})
364-
364+
scope.$on('reCaptchaReset', function (event, resetWidgetId) {
365+
if (ng.isUndefined(resetWidgetId) || widgetId === resetWidgetId) {
366+
scope.response = '';
367+
validate();
368+
}
369+
});
365370
});
366371

367372
// Remove this listener to avoid creating the widget more than once.
368373
removeCreationListener();
369374
});
370375

371376
function destroy() {
372-
if (ctrl) {
373-
// reset the validity of the form if we were removed
374-
ctrl.$setValidity('recaptcha', null);
375-
}
377+
if (ctrl) {
378+
// reset the validity of the form if we were removed
379+
ctrl.$setValidity('recaptcha', null);
380+
}
376381

377-
cleanup();
382+
cleanup();
378383
}
379384

380-
function expired(){
385+
function expired() {
381386
// Safe $apply
382387
$timeout(function () {
383-
scope.response = "";
388+
scope.response = '';
384389
validate();
385390

386391
// Notify about the response availability
387-
scope.onExpire({ widgetId: scope.widgetId });
392+
scope.onExpire({widgetId: scope.widgetId});
388393
});
389394
}
390395

391-
function validate(){
392-
if(ctrl){
396+
function validate() {
397+
if (ctrl) {
393398
ctrl.$setValidity('recaptcha', scope.required === false ? null : Boolean(scope.response));
394399
}
395400
}
396401

397-
function cleanup(){
398-
vcRecaptcha.destroy(scope.widgetId);
402+
function cleanup() {
403+
vcRecaptcha.destroy(scope.widgetId);
399404

400-
// removes elements reCaptcha added.
401-
ng.element($document[0].querySelectorAll('.pls-container')).parent().remove();
405+
// removes elements reCaptcha added.
406+
ng.element($document[0].querySelectorAll('.pls-container')).parent().remove();
402407
}
403408
}
404409
};

release/angular-recaptcha.min.js

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

0 commit comments

Comments
 (0)