-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathmain.js
71 lines (66 loc) · 3.39 KB
/
main.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
( function( window, angular ) {
angular
.module( 'app', [ 'visualCaptcha' ] )
.controller( 'captchaController', function( $scope ) {
$scope.captchaOptions = {
imgPath: 'img/',
captcha: {
numberOfImages: 5,
callbacks: {
loaded: function( captcha ) {
// Binds an element to callback on click
// @param element object like document.getElementById() (has to be a single element)
// @param callback function to run when the element is clicked
var _bindClick = function( element, callback ) {
if ( element.addEventListener ) {
element.addEventListener( 'click', callback, false );
} else {
element.attachEvent( 'onclick', callback );
}
};
// Avoid adding the hashtag to the URL when clicking/selecting visualCaptcha options
var anchorOptions = document.getElementById( 'sample-captcha' ).getElementsByTagName( 'a' );
var anchorList = Array.prototype.slice.call( anchorOptions );// .getElementsByTagName does not return an actual array
anchorList.forEach( function( anchorItem ) {
_bindClick( anchorItem, function( event ) {
event.preventDefault();
});
});
}
}
},
init: function ( captcha ) {
$scope.captcha = captcha;
}
};
$scope.isVisualCaptchaFilled = function() {
if ( $scope.captcha.getCaptchaData().valid ) {
window.alert( 'visualCaptcha is filled!' );
} else {
window.alert( 'visualCaptcha is NOT filled!' );
}
};
var queryString = window.location.search;
// Show success/error messages
$scope.status = null;
if ( queryString.indexOf('status=noCaptcha') !== -1 ) {
$scope.valid = false;
$scope.status = 'visualCaptcha was not started!';
} else if ( queryString.indexOf('status=validImage') !== -1 ) {
$scope.valid = true;
$scope.status = 'Image was valid!';
} else if ( queryString.indexOf('status=failedImage') !== -1 ) {
$scope.valid = false;
$scope.status = 'Image was NOT valid!';
} else if ( queryString.indexOf('status=validAudio') !== -1 ) {
$scope.valid = true;
$scope.status = 'Accessibility answer was valid!';
} else if ( queryString.indexOf('status=failedAudio') !== -1 ) {
$scope.valid = false;
$scope.status = 'Accessibility answer was NOT valid!';
} else if ( queryString.indexOf('status=failedPost') !== -1 ) {
$scope.valid = false;
$scope.status = 'No visualCaptcha answer was given!';
}
} );
}( window, angular ) );