source: trunk/www.guidonia.net/wp/wp-content/plugins/contact-form-7/contact-form-7.js@ 44

Last change on this file since 44 was 44, checked in by luciano, 15 years ago
File size: 3.7 KB
Line 
1jQuery(document).ready(function() {
2 try {
3 jQuery('div.wpcf7 > form').ajaxForm({
4 beforeSubmit: wpcf7BeforeSubmit,
5 dataType: 'json',
6 success: wpcf7ProcessJson
7 });
8 } catch (e) {
9 }
10
11 try {
12 jQuery('div.wpcf7 > form').each(function(i, n) {
13 wpcf7ToggleSubmit(jQuery(n));
14 });
15 } catch (e) {
16 }
17});
18
19// Exclusive checkbox
20function wpcf7ExclusiveCheckbox(elem) {
21 jQuery(elem.form).find('input:checkbox[name="' + elem.name + '"]').not(elem).removeAttr('checked');
22}
23
24// Toggle submit button
25function wpcf7ToggleSubmit(form) {
26 var submit = jQuery(form).find('input:submit');
27 if (! submit.length) return;
28
29 var acceptances = jQuery(form).find('input:checkbox.wpcf7-acceptance');
30 if (! acceptances.length) return;
31
32 submit.removeAttr('disabled');
33 acceptances.each(function(i, n) {
34 n = jQuery(n);
35 if (n.hasClass('wpcf7-invert') && n.is(':checked') || ! n.hasClass('wpcf7-invert') && ! n.is(':checked'))
36 submit.attr('disabled', 'disabled');
37 });
38}
39
40function wpcf7BeforeSubmit(formData, jqForm, options) {
41 wpcf7ClearResponseOutput();
42 jQuery('img.ajax-loader', jqForm[0]).css({ visibility: 'visible' });
43
44 formData.push({name: '_wpcf7_is_ajax_call', value: 1});
45 jQuery(jqForm[0]).append('<input type="hidden" name="_wpcf7_is_ajax_call" value="1" />');
46
47 return true;
48}
49
50function wpcf7NotValidTip(into, message) {
51 jQuery(into).append('<span class="wpcf7-not-valid-tip">' + message + '</span>');
52 jQuery('span.wpcf7-not-valid-tip').mouseover(function() {
53 jQuery(this).fadeOut('fast');
54 });
55 jQuery(into).find(':input').mouseover(function() {
56 jQuery(into).find('.wpcf7-not-valid-tip').not(':hidden').fadeOut('fast');
57 });
58 jQuery(into).find(':input').focus(function() {
59 jQuery(into).find('.wpcf7-not-valid-tip').not(':hidden').fadeOut('fast');
60 });
61}
62
63function wpcf7ProcessJson(data) {
64 var wpcf7ResponseOutput = jQuery(data.into).find('div.wpcf7-response-output');
65 wpcf7ClearResponseOutput();
66 if (data.invalids) {
67 jQuery.each(data.invalids, function(i, n) {
68 wpcf7NotValidTip(jQuery(data.into).find(n.into), n.message);
69 });
70 wpcf7ResponseOutput.addClass('wpcf7-validation-errors');
71 }
72 if (data.captcha) {
73 jQuery.each(data.captcha, function(i, n) {
74 jQuery(data.into).find(':input[name="' + i + '"]').clearFields();
75 jQuery(data.into).find('img.wpcf7-captcha-' + i).attr('src', n);
76 var match = /([0-9]+)\.(png|gif|jpeg)$/.exec(n);
77 jQuery(data.into).find('input:hidden[name="_wpcf7_captcha_challenge_' + i + '"]').attr('value', match[1]);
78 });
79 }
80 if (data.quiz) {
81 jQuery.each(data.quiz, function(i, n) {
82 jQuery(data.into).find(':input[name="' + i + '"]').clearFields();
83 jQuery(data.into).find(':input[name="' + i + '"]').siblings('span.wpcf7-quiz-label').text(n[0]);
84 jQuery(data.into).find('input:hidden[name="_wpcf7_quiz_answer_' + i + '"]').attr('value', n[1]);
85 });
86 }
87 if (1 == data.spam) {
88 wpcf7ResponseOutput.addClass('wpcf7-spam-blocked');
89 }
90 if (1 == data.mailSent) {
91 jQuery(data.into).find('form').resetForm().clearForm();
92 wpcf7ResponseOutput.addClass('wpcf7-mail-sent-ok');
93
94 if (data.onSentOk)
95 jQuery.each(data.onSentOk, function(i, n) { eval(n) });
96 } else {
97 wpcf7ResponseOutput.addClass('wpcf7-mail-sent-ng');
98 }
99 wpcf7ResponseOutput.append(data.message).fadeIn('fast');
100}
101
102function wpcf7ClearResponseOutput() {
103 jQuery('div.wpcf7-response-output').hide().empty().removeClass('wpcf7-mail-sent-ok wpcf7-mail-sent-ng wpcf7-validation-errors wpcf7-spam-blocked');
104 jQuery('span.wpcf7-not-valid-tip').remove();
105 jQuery('img.ajax-loader').css({ visibility: 'hidden' });
106}
Note: See TracBrowser for help on using the repository browser.