PluginProbe
GetResponse Forms by Optin Cat / 1.4.2
GetResponse Forms by Optin Cat v1.4.2
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.4.2, at assets/script.js

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