This repository has been archived by the owner on Oct 10, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
executable file
·77 lines (67 loc) · 2.54 KB
/
script.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
72
73
74
75
76
77
/*
* @copyright Copyright (c) 2015, XdevL
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 2 of the License, or
* any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
var xdevl=xdevl || {} ;
xdevl.contactform=xdevl.contactform || {} ;
jQuery(function($)
{
xdevl.contactform.formToObject=function (id)
{
var obj={} ;
$("#"+id).serializeArray().map(function(x){obj[x.name]=x.value}) ;
obj[xdevl.contactform.FIELD_CAPTCHA]=$("#g-recaptcha-response").val() ;
return obj ;
} ;
xdevl.contactform.submit=function ()
{
// clear the form alert message to notify the user something is going on
$("#"+xdevl.contactform.FORM_ALERT_ID).text("") ;
$("#"+xdevl.contactform.FORM_ALERT_ID).attr("class",null) ;
$.post(xdevl.contactform.AJAX_URL,
xdevl.contactform.formToObject(xdevl.contactform.FORM_ID)
, function (data,textStatus,jqXHR) {
try {
var response=JSON.parse(data) ;
} catch(error) {
var response={formError: 'A internal server error occured, please try again in a few minutes', fieldErrors: []} ;
}
xdevl.contactform.updateForm(response) ;
}
).fail(function(xhr,textStatus,errorThrown) {
xdevl.contactform.updateForm({formError: 'Looks like the server is unavailable, please try again in a few minutes', fieldErrors: []}) ;
}) ;
} ;
xdevl.contactform.updateForm=function (result)
{
$.map(result.fieldErrors,function(value,key) {
$("#"+key).text(value) ;
}) ;
if(result.formSuccess)
{
$("#"+xdevl.contactform.FORM_ALERT_ID).text(result.formSuccess) ;
$("#"+xdevl.contactform.FORM_ALERT_ID).attr("class",xdevl.contactform.ALERT_SUCCESS_CLASSES) ;
$("#"+xdevl.contactform.FORM_ID).trigger("reset") ;
grecaptcha.reset() ;
}
else
{
$("#"+xdevl.contactform.FORM_ALERT_ID).text(result.formError) ;
$("#"+xdevl.contactform.FORM_ALERT_ID).attr("class",xdevl.contactform.ALERT_ERROR_CLASSES) ;
}
// we scroll up to the form alert to let the user know what happened
$('html,body').animate({
scrollTop: $("#"+xdevl.contactform.FORM_ALERT_ID).offset().top
},100) ;
} ;
}) ;