PluginProbe
GetResponse Forms by Optin Cat / 1.3.9
GetResponse Forms by Optin Cat v1.3.9
1.3.4 1.3.5 1.3.6 1.3.8 1.3.9 1.4.0 1.4.1 1.4.2 1.5.0 1.5.1 1.5.2 1.5.4 1.5.5 1.5.6 1.5.7 1.5.8 1.6.1 1.6.2 1.6.3 1.7.0 1.7.1 1.7.2 1.8.0 1.8.1 2.0.0 All 36 releases
getresponse / assets / script.js

script.js in GetResponse Forms by Optin Cat 1.3.9, at assets/script.js

115 lines 3.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 jQuery( document ).ready(function( $ ){
2
3 $( document ).on( 'submit', '.fca_eoi_form', function () {
4
5 // Attach tooltips
6 $( '[name=email], [name=name]', $( this ) ).each( function() {
7
8 var $this = $( this );
9 var tooltipWidth = $this.width() * .8;
10
11 $this.tooltipster( {
12 contentAsHTML: true
13 , fixedWidth: tooltipWidth
14 , minWidth: tooltipWidth
15 , maxWidth: tooltipWidth
16 , trigger: 'none'
17 } );
18 } );
19
20 // Remove tooltip and tick on focus
21 $( '[name=email], [name=name]', $( this ) ).focus( function() {
22 var $this = $( this );
23 var $button = $( '[type=submit]', $this.closest( '.fca_eoi_form' ) );
24 var button_initial_val = $button.data( 'fca_eoi_initial_val' );
25
26 // Remove any previous icon
27 if( 'undefined' !== typeof( button_initial_val ) ) {
28 $button.val( button_initial_val );
29 }
30
31 // Hide tooltip
32 $( this ).tooltipster( 'hide' );
33 } );
34
35 // Handle form submissions
36 //$( '.fca_eoi_form' ).submit( function( e ) {
37
38 var $this = $( this );
39 var $email_field = $( '[name=email]', $this );
40 var $name_field = $( '[name=name]', $this );
41 var name = $name_field.val();
42 var email = $email_field.val();
43 var list_id = $this.data( 'fca_eoi_list_id' );
44 var url = 'https://api.createsend.com/api/v3.1/subscribers/' + list_id + '.json';
45 var $button = $( '[type=submit]', $this );
46 var button_initial_val;
47 var highlight_interval = false;
48 var thank_you_page = $this.data( 'fca_eoi_thank_you_page' );
49 var has_error = false;
50 var fca_eoi_form_id = $( '[name=fca_eoi_form_id]', $this ).val();
51
52 // Save or save and get initial button value
53 if( $button.data( 'fca_eoi_initial_val' ) ) {
54 button_initial_val = $button.data( 'fca_eoi_initial_val' );
55 } else {
56 button_initial_val = $button.val();
57 $button.data( 'fca_eoi_initial_val', button_initial_val );
58 }
59
60 // Remove any previous icon
61 $button.val( button_initial_val );
62
63 // Check email address
64 if( ! email || ! is_email( email ) ) {
65
66 $email_field.tooltipster( 'content', email ? fca_eoi.invalid_email : fca_eoi.field_required );
67 $email_field.tooltipster( 'show' );
68 $button.val( '' + button_initial_val );
69 has_error = true;
70 }
71
72 // Check name
73 if( $name_field.length && ! name ) {
74
75 $name_field.tooltipster( 'content', fca_eoi.field_required );
76 $name_field.tooltipster( 'show' );
77 $button.val( '' + button_initial_val );
78 has_error = true;
79 }
80
81 // Exit if there is any error
82 if( has_error ) {
83 return false;
84 }
85
86 $( '.fca_eoi_form_button_element', $this ).attr( 'disabled', 'disabled' );
87
88 return true;
89
90 // Start highlighting
91 highlight_interval = setInterval( function() {
92 $button.fadeTo( 200, 0.25 ).fadeTo( 200, 1.0 );
93 }, 500 );
94
95 $.ajax( {
96 url: fca_eoi.ajax_url
97 , data: { 'email': email, 'name': name, 'action': 'fca_eoi_subscribe', 'list_id': list_id ,'form_id': fca_eoi_form_id}
98 , type: 'POST'
99 , datatype: 'text'
100 } ).done( function( data ) {
101 // Stop highlighting and add an icon for success/failure
102 $button.val( data + ' ' + button_initial_val );
103 clearInterval( highlight_interval );
104 if ( thank_you_page && '' === data ) {
105 window.location.href = thank_you_page;
106 }
107 } );
108 //} );
109 } );
110 } );
111
112 function is_email( email ) {
113 var regex = /^([a-zA-Z0-9_.+-])+\@(([a-zA-Z0-9-])+\.)+([a-zA-Z0-9]{2,4})+$/;
114 return regex.test(email);
115 }