6294b4f139ea6874487a95c611cf8cfff96f65da
[toast/cookiecaptcha.git] / ext.confirmedit.asirra.js
1 /*======================================================================*\
2 || #################################################################### ||
3 || # Asirra module for ConfirmEdit by Bachsau                         # ||
4 || # ---------------------------------------------------------------- # ||
5 || # This code is released into public domain, in the hope that it    # ||
6 || # will be useful, but without any warranty.                        # ||
7 || # ------------ YOU CAN DO WITH IT WHATEVER YOU LIKE! ------------- # ||
8 || #################################################################### ||
9 \*======================================================================*/
10
11 jQuery( function( $ ) {
12         var asirraform = $( "form#userlogin2" )
13         var submitButtonClicked = document.createElement("input");
14         var passThroughFormSubmit = false;
15
16         function PrepareSubmit() {
17                 console.log( 'daa' );
18                 submitButtonClicked.type = "hidden";
19                 var inputFields = asirraform.find( "input" );
20                 for (var i=0; i<inputFields.length; i++) {
21                         if (inputFields[i].type === "submit") {
22                                 inputFields[i].onclick = function(event) {
23                                         console.log( this );
24                                         submitButtonClicked.name = this.name;
25                                         submitButtonClicked.value = this.value;
26                                 }
27                         }
28                 }
29
30                 asirraform.submit( function() {
31                         return MySubmitForm();
32                 } );
33         }
34
35         function MySubmitForm() {
36                 if (passThroughFormSubmit) {
37                         return true;
38                 }
39                 Asirra_CheckIfHuman(HumanCheckComplete);
40                 return false;
41         }
42
43         function HumanCheckComplete(isHuman) {
44                 if (!isHuman) {
45                         alert( mw.msg( 'asirra-failed' ) );
46                 } else {
47                         asirraform.append(submitButtonClicked);
48                         passThroughFormSubmit = true;
49                         asirraform.submit();
50                 }
51         }
52         
53         PrepareSubmit();
54         
55 } );