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

199 lines 5.5 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]:visible', $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 $button = jQuery( '[type=submit]', $this );
16 var $input_div = jQuery( '.fca_eoi_layout_submit_button_wrapper', $this );
17 var $spinner = jQuery( '.fca_eoi_loading_spinner', $this );
18 var $div = jQuery( '.fca_eoi_spiner_div', $this );
19 var button_initial_val;
20 var highlight_interval = false;
21 var thank_you_mode = $this.data( 'fca_eoi_thank_you_mode' );
22 var thank_you_page = $this.data( 'fca_eoi_thank_you_page' );
23 var has_error = false;
24 var form_id = jQuery( '[name=fca_eoi_form_id]', $this ).val();
25
26
27 // Attach tooltips
28 jQuery( '[name=email], [name=name]', $this ).each( function() {
29
30 var $this = jQuery( this );
31 var tooltipWidth = $this.width() * .8;
32
33 $this.tooltipster( {
34 contentAsHTML: true,
35 fixedWidth: tooltipWidth,
36 minWidth: tooltipWidth,
37 maxWidth: tooltipWidth,
38 trigger: 'none'
39 } )
40 } )
41
42 // Remove tooltip and tick on focus
43 jQuery( '[name=email], [name=name]', jQuery( this ) ).focus( function() {
44 var $this = jQuery( this );
45 var $button = jQuery( '[type=submit]', $this.closest( '.fca_eoi_form' ) );
46 var button_initial_val = $button.data( 'fca_eoi_initial_val' );
47
48 // Remove any previous icon
49 if( 'undefined' !== typeof( button_initial_val ) ) {
50 $button.val( button_initial_val );
51 }
52
53 // Hide tooltip
54 jQuery( this ).tooltipster( 'hide' );
55 } );
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 fca_eoi.invalid_email = $this.find('.fca_eoi_error_texts_email').val();
70 fca_eoi.field_required = $this.find('.fca_eoi_error_texts_required').val();
71
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 //DISABLE BUTTON CLICK EVENT
97 $button.click(function(event) {
98 event.preventDefault();
99 });
100
101 if ( $button.closest('.fca_eoi_form').hasClass('fca_eoi_layout_1') ) {
102 //without extra border
103 scaleSpinnerDiv($button, $div);
104
105 } else {
106 //width extra border
107 scaleSpinnerDiv($input_div, $div);
108 }
109 scaleSpinnerSize($button, $spinner);
110
111 //Match div border radius with button's
112 var radius = $button.css("borderRadius");
113 $div.css('borderRadius', radius);
114
115 //animate out the button and in the spinner div
116 $div.animate({ width: '100%'});
117
118 $spinner.css("display", "block");
119 $button.attr('style', 'cursor: default' );
120
121 jQuery.ajax({
122 url: fca_eoi.ajax_url,
123 data: { 'email': email, 'name': name, 'action': 'fca_eoi_subscribe', 'list_id': list_id ,'form_id': form_id, 'nonce': fca_eoi.nonce },
124 type: 'POST',
125 datatype: 'text',
126 timeout: 15000
127 }).done( function( data ) {
128
129 if ( thank_you_mode == 'ajax' ) {
130
131 // Stop highlighting and add an icon for success/failure
132 if ( data === '' ) {
133 $button.val( data + ' ' + button_initial_val );
134 } else {
135 $button.val( data );
136 }
137
138 $spinner.css("display", "none");
139 $div.animate({ width: '0', padding: '0', left: '100%' });
140
141 clearInterval( highlight_interval );
142 if ( thank_you_page && '' === data ) {
143 tooltipWidth = $button.width();
144 $button.tooltipster( {
145 contentAsHTML: true,
146 trigger: 'none',
147 fixedWidth: tooltipWidth,
148 minWidth: tooltipWidth,
149 maxWidth: tooltipWidth,
150 arrowColor: '#148544'
151 } );
152
153 $button.tooltipster( 'content', thank_you_page );
154 $button.tooltipster( 'show' );
155 $email_field.prop('disabled', true);
156 $name_field.prop('disabled', true);
157
158 jQuery('.tooltipster-content').css("background-color", "#148544");
159 setTimeout(function() {
160 $button.tooltipster( 'hide' );
161 }, 5000);
162 }
163 } else {
164 window.location.href = thank_you_page;
165 }
166 });
167 });
168 });
169
170 //set height, top and (-)margin top to same size as the fca_eoi_layout_submit_button_wrapper height
171
172 function scaleSpinnerDiv ($button, $div){
173
174 var h = $button.outerHeight();
175
176 $div.css('height', h + 'px');
177 $div.css('top', h + 'px');
178 $div.css('margin-top', '-' + h + 'px');
179 $div.css('z-index', '1');
180
181 }
182
183 function scaleSpinnerSize( $button, $spinner ) {
184 var h = $button.outerHeight();
185 var w = $button.outerWidth();
186 h = h - 8; //account for borders
187
188 var newWidth = ( w / 2 ) - ( h / 2);
189
190 $spinner.css('margin-left', newWidth + 'px' );
191 $spinner.css('height', h + 'px');
192 $spinner.css('width', h + 'px');
193
194 }
195
196 function is_email( email ) {
197 var regex = /^([a-zA-Z0-9_.+-])+\@(([a-zA-Z0-9-])+\.)+([a-zA-Z0-9]{2,4})+$/;
198 return regex.test(email);
199 }