|
1 | 1 | /* Form submission functions for the MailChimp Widget */
|
2 |
| -;(function($){ |
3 |
| - $(function($) { |
4 |
| - // Change our submit type from HTML (default) to JS |
5 |
| - $('#mc_submit_type').val('js'); |
6 |
| - |
7 |
| - // Attach our form submitter action |
8 |
| - $('#mc_signup_form').ajaxForm({ |
9 |
| - url: mailchimpSF.ajax_url, |
10 |
| - type: 'POST', |
11 |
| - dataType: 'text', |
12 |
| - beforeSubmit: mc_beforeForm, |
13 |
| - success: mc_success |
14 |
| - }); |
15 |
| - }); |
16 |
| - |
17 |
| - function mc_beforeForm(){ |
| 2 | +(function ($) { |
| 3 | + function mc_beforeForm() { |
18 | 4 | // Disable the submit button
|
19 |
| - $('#mc_signup_submit').attr("disabled","disabled"); |
| 5 | + $('#mc_signup_submit').attr('disabled', 'disabled'); |
20 | 6 | }
|
21 |
| - function mc_success(data){ |
| 7 | + |
| 8 | + function mc_success(data) { |
22 | 9 | // Re-enable the submit button
|
23 |
| - $('#mc_signup_submit').removeAttr("disabled"); |
24 |
| - |
| 10 | + $('#mc_signup_submit').removeAttr('disabled'); |
| 11 | + |
25 | 12 | // Put the response in the message div
|
26 | 13 | $('#mc_message').html(data);
|
27 |
| - |
| 14 | + |
28 | 15 | // See if we're successful, if so, wipe the fields
|
29 |
| - var reg = new RegExp("class='mc_success_msg'", 'i'); |
30 |
| - if (reg.test(data)){ |
31 |
| - $('#mc_signup_form').each(function(){ |
| 16 | + const reg = /class="|'mc_success_msg"|'/i; |
| 17 | + |
| 18 | + if (reg.test(data)) { |
| 19 | + $('#mc_signup_form').each(function () { |
32 | 20 | this.reset();
|
33 | 21 | });
|
34 | 22 | $('#mc_submit_type').val('js');
|
35 | 23 | }
|
36 |
| - $.scrollTo('#mc_signup', {offset: {top: -28}}); |
| 24 | + $.scrollTo('#mc_signup', { offset: { top: -28 } }); |
37 | 25 | }
|
38 |
| -})(jQuery); |
| 26 | + |
| 27 | + $(function ($) { |
| 28 | + // Change our submit type from HTML (default) to JS |
| 29 | + $('#mc_submit_type').val('js'); |
| 30 | + |
| 31 | + // Attach our form submitter action |
| 32 | + $('#mc_signup_form').ajaxForm({ |
| 33 | + url: window.mailchimpSF.ajax_url, |
| 34 | + type: 'POST', |
| 35 | + dataType: 'text', |
| 36 | + beforeSubmit: mc_beforeForm, |
| 37 | + success: mc_success, |
| 38 | + }); |
| 39 | + }); |
| 40 | +})(window.jQuery); |
0 commit comments