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

Commit

Permalink
[Release] v2.4.1
Browse files Browse the repository at this point in the history
  • Loading branch information
iambrosi committed Feb 8, 2016
1 parent 369e3e9 commit 5327446
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 28 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": "2.4.0",
"version": "2.4.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": "2.4.0",
"version": "2.4.1",
"description": "An AngularJS module to ease usage of reCaptcha inside a form",
"author": "VividCortex",
"license": "MIT",
Expand Down
52 changes: 28 additions & 24 deletions release/angular-recaptcha.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* angular-recaptcha build:2016-02-03
* angular-recaptcha build:2016-02-08
* https://github.com/vividcortex/angular-recaptcha
* Copyright (c) 2016 VividCortex
**/
Expand Down Expand Up @@ -132,7 +132,9 @@
stoken: '=?',
theme: '=?',
size: '=?',
type: '=?',
tabindex: '=?',
required: '=?',
onCreate: '&',
onSuccess: '&',
onExpire: '&'
Expand All @@ -144,7 +146,10 @@

scope.widgetId = null;

var sessionTimeout;
if(ctrl && angular.isDefined(attrs.required)){
scope.$watch('required', validate);
}

var removeCreationListener = scope.$watch('key', function (key) {
if (!key) {
return;
Expand All @@ -157,37 +162,26 @@
var callback = function (gRecaptchaResponse) {
// Safe $apply
$timeout(function () {
if(ctrl){
ctrl.$setValidity('recaptcha',true);
}
scope.response = gRecaptchaResponse;
validate();

// Notify about the response availability
scope.onSuccess({response: gRecaptchaResponse, widgetId: scope.widgetId});
});

// captcha session lasts 2 mins after set.
sessionTimeout = $timeout(function (){
if(ctrl){
ctrl.$setValidity('recaptcha',false);
}
scope.response = "";
// Notify about the response availability
scope.onExpire({widgetId: scope.widgetId});
}, 2 * 60 * 1000);
};

vcRecaptcha.create(elm[0], key, callback, {

stoken: scope.stoken || attrs.stoken || null,
theme: scope.theme || attrs.theme || null,
type: scope.type || attrs.type || null,
tabindex: scope.tabindex || attrs.tabindex || null,
size: scope.size || attrs.size || null
size: scope.size || attrs.size || null,
'expired-callback': expired

}).then(function (widgetId) {
// The widget has been created
if(ctrl){
ctrl.$setValidity('recaptcha',false);
}
validate();
scope.widgetId = widgetId;
scope.onCreate({widgetId: widgetId});

Expand All @@ -204,14 +198,24 @@
// reset the validity of the form if we were removed
ctrl.$setValidity('recaptcha', null);
}
if (sessionTimeout) {
// don't trigger the session timeout if we are no longer active
$timeout.cancel(sessionTimeout);
sessionTimeout = null;
}

cleanup();
}

function expired(){
scope.response = "";
validate();

// Notify about the response availability
scope.onExpire({widgetId: scope.widgetId});
}

function validate(){
if(ctrl){
ctrl.$setValidity('recaptcha', scope.required === false ? null : Boolean(scope.response));
}
}

function cleanup(){
// removes elements reCaptcha added.
angular.element($document[0].querySelectorAll('.pls-container')).parent().remove();
Expand Down
4 changes: 2 additions & 2 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 5327446

Please sign in to comment.