-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathmain.js
64 lines (58 loc) · 3.32 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
( function( window, visualCaptcha ) {
var captcha = visualCaptcha( 'sample-captcha', {
imgPath: 'img/',
captcha: {
numberOfImages: 5,
callbacks: {
loaded: function( captcha ) {
// 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();
});
});
}
}
}
} );
var statusElement = document.getElementById( 'status-message' ),
queryString = window.location.search;
// Show success/error messages
if ( queryString.indexOf('status=noCaptcha') !== -1 ) {
statusElement.innerHTML = '<div class="status"> <div class="icon-no"></div> <p>visualCaptcha was not started!</p> </div>' + statusElement.innerHTML;
} else if ( queryString.indexOf('status=validImage') !== -1 ) {
statusElement.innerHTML = '<div class="status valid"> <div class="icon-yes"></div> <p>Image was valid!</p> </div>' + statusElement.innerHTML;
} else if ( queryString.indexOf('status=failedImage') !== -1 ) {
statusElement.innerHTML = '<div class="status"> <div class="icon-no"></div> <p>Image was NOT valid!</p> </div>' + statusElement.innerHTML;
} else if ( queryString.indexOf('status=validAudio') !== -1 ) {
statusElement.innerHTML = '<div class="status valid"> <div class="icon-yes"></div> <p>Accessibility answer was valid!</p> </div>' + statusElement.innerHTML;
} else if ( queryString.indexOf('status=failedAudio') !== -1 ) {
statusElement.innerHTML = '<div class="status"> <div class="icon-no"></div> <p>Accessibility answer was NOT valid!</p> </div>' + statusElement.innerHTML;
} else if ( queryString.indexOf('status=failedPost') !== -1 ) {
statusElement.innerHTML = '<div class="status"> <div class="icon-no"></div> <p>No visualCaptcha answer was given!</p> </div>' + statusElement.innerHTML;
}
// 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 );
}
};
// Show an alert saying if visualCaptcha is filled or not
var _sayIsVisualCaptchaFilled = function( event ) {
event.preventDefault();
if ( captcha.getCaptchaData().valid ) {
window.alert( 'visualCaptcha is filled!' );
} else {
window.alert( 'visualCaptcha is NOT filled!' );
}
};
// Bind that function to the appropriate link
var isFilledElement = document.getElementById( 'check-is-filled' );
_bindClick( isFilledElement, _sayIsVisualCaptchaFilled );
}( window, visualCaptcha ) );