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

171 lines 5.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1
2 jQuery( document ).ready(function(){
3
4
5 jQuery( document ).on( 'submit', '.fca_eoi_form', function (e) {
6
7 e.preventDefault();
8
9 var $this = jQuery( this );
10 var $email_field = jQuery( '[name=email]', $this );
11 var $name_field = jQuery( '[name=name]', $this );
12 var name = $name_field.val();
13 var email = $email_field.val();
14 var list_id = $this.data( 'fca_eoi_list_id' );
15 //var url = 'https://api.createsend.com/api/v3.1/subscribers/' + list_id + '.json';
16 var $button = jQuery( '[type=submit]', $this );
17 var $spinner = jQuery( '.fca_eoi_loading_spinner', $this );
18 var button_initial_val;
19 var highlight_interval = false;
20 var thank_you_mode = $this.data( 'fca_eoi_thank_you_mode' );
21 var thank_you_page = $this.data( 'fca_eoi_thank_you_page' );
22 var has_error = false;
23 var form_id = jQuery( '[name=fca_eoi_form_id]', $this ).val();
24 var nonceValue = jQuery( '#fca_eoi_nonce' ).val();
25
26 // Attach tooltips
27 jQuery( '[name=email], [name=name]', jQuery( this ) ).each( function() {
28
29 var $this = jQuery( this );
30 var tooltipWidth = $this.width() * .8;
31
32 $this.tooltipster( {
33 contentAsHTML: true
34 , fixedWidth: tooltipWidth
35 , minWidth: tooltipWidth
36 , maxWidth: tooltipWidth
37 , trigger: 'none'
38 } );
39 } );
40
41 // Remove tooltip and tick on focus
42 jQuery( '[name=email], [name=name]', jQuery( this ) ).focus( function() {
43 var $this = jQuery( this );
44 var $button = jQuery( '[type=submit]', $this.closest( '.fca_eoi_form' ) );
45 var button_initial_val = $button.data( 'fca_eoi_initial_val' );
46
47 // Remove any previous icon
48 if( 'undefined' !== typeof( button_initial_val ) ) {
49 $button.val( button_initial_val );
50 }
51
52 // Hide tooltip
53 jQuery( this ).tooltipster( 'hide' );
54 } );
55
56 // Save or save and get initial button value
57 if( $button.data( 'fca_eoi_initial_val' ) ) {
58 button_initial_val = $button.data( 'fca_eoi_initial_val' );
59 } else {
60 button_initial_val = $button.val();
61 $button.data( 'fca_eoi_initial_val', button_initial_val );
62 }
63
64 // Remove any previous icon
65 $button.val( button_initial_val );
66
67 // Get Error Messages from hidden fields
68 fca_eoi.invalid_email = $this.find('.fca_eoi_error_texts_email').val();
69 fca_eoi.field_required = $this.find('.fca_eoi_error_texts_required').val();
70
71
72 // Check email address
73 if( ! email || ! is_email( email ) ) {
74
75 $email_field.tooltipster( 'content', email ? fca_eoi.invalid_email : fca_eoi.field_required );
76 $email_field.tooltipster( 'show' );
77 $button.val( '' + button_initial_val );
78 has_error = true;
79 }
80
81 // Check name
82 if( $name_field.length && ! name ) {
83
84 $name_field.tooltipster( 'content', fca_eoi.field_required );
85 $name_field.tooltipster( 'show' );
86 $button.val( '' + button_initial_val );
87 has_error = true;
88 }
89
90 // Exit if there is any error
91 if( has_error ) {
92 return false;
93 }
94 //DISABLE BUTTON CLICK EVENT
95 $button.click(function(event) {
96 event.preventDefault();
97 });
98
99
100 if (thank_you_mode != 'redirect') {
101
102 // Run function to scale spinner based on button size
103 scaleSpinnerSize($button, $spinner);
104
105 $spinner.css("visibility", "visible");
106
107 $button.attr('style', 'cursor: default; transition: none !important; background-color: #808080 !important; border: 1px solid #808080 !important; color: white !important;');
108
109 if ( $button.closest('.fca_eoi_form').hasClass('fca_eoi_layout_1') ) {
110 //do nothing for this layout, we don't want the extra gray button wrapper
111 } else {
112 $spinner.parent('.fca_eoi_layout_submit_button_wrapper').attr('style', 'transition: none !important; background-color: #808080 !important; border: 1px solid #808080 !important;');
113 }
114 }
115
116
117 jQuery.ajax( {
118 url: fca_eoi.ajax_url
119 , data: { 'email': email, 'name': name, 'action': 'fca_eoi_subscribe', 'list_id': list_id ,'form_id': form_id, 'nonce': nonceValue }
120 , type: 'POST'
121 , datatype: 'text'
122 } ).done( function( data ) {
123 // Stop highlighting and add an icon for success/failure
124 $button.val( data + ' ' + button_initial_val );
125
126 $spinner.css("visibility", "hidden");
127 clearInterval( highlight_interval );
128 if ( thank_you_page && '' === data ) {
129
130 if ( thank_you_mode == 'redirect' ) {
131 window.location.href = thank_you_page;
132 } else {
133 tooltipWidth = $button.width();
134 $button.tooltipster( {
135 contentAsHTML: true,
136 trigger: 'none',
137 fixedWidth: tooltipWidth,
138 minWidth: tooltipWidth,
139 maxWidth: tooltipWidth,
140 arrowColor: '#148544'
141 } );
142 $button.tooltipster( 'content', thank_you_page );
143 $button.tooltipster( 'show' );
144 $email_field.prop('disabled', true);
145 $name_field.prop('disabled', true);
146
147 jQuery('.tooltipster-content').css("background-color", "#148544");
148
149 }
150 }
151 } );
152 } );
153 } );
154
155 function scaleSpinnerSize( $button, $spinner ) {
156 var h = $button.outerHeight();
157
158 h = h - 8; //account for borders
159 var newTop = h + 4;
160
161 $spinner.css('margin-top', '-' + h + 'px' );
162 $spinner.css('top', newTop );
163 $spinner.css('height', h + 'px');
164 $spinner.css('width', h + 'px');
165
166 }
167
168 function is_email( email ) {
169 var regex = /^([a-zA-Z0-9_.+-])+\@(([a-zA-Z0-9-])+\.)+([a-zA-Z0-9]{2,4})+$/;
170 return regex.test(email);
171 }