PluginProbe
GetResponse Forms by Optin Cat / 2.4.1
GetResponse Forms by Optin Cat v2.4.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
← All changes | assets/script.js +151 -126 1.7.02.4.1 View file →
@@ -1,35 +1,60 @@
1 +/* jshint asi: true */
1 2
2 -jQuery( document ).ready(function(){
3 +jQuery( document ).ready(function($){
4 +
5 + function is_email( email ) {
6 + var regex = /^([a-zA-Z0-9_.+-])+\@(([a-zA-Z0-9-])+\.)+([a-zA-Z0-9]{2,4})+$/
7 + return regex.test(email)
8 + }
3 9
10 + function set_cookie( name, value, exdays ) {
11 + if ( exdays === 0 ) {
12 + document.cookie = name + "=" + value + "" + ";" + "path=/;"
13 + } else {
14 + var d = new Date()
15 + d.setTime( d.getTime() + ( exdays*24*60*60*1000 ) )
16 + document.cookie = name + "=" + value + "" + ";" + "path=/;" + "expires=" + d.toUTCString()
17 + }
18 + }
19 +
20 + function get_cookie( name ) {
21 + var value = "; " + document.cookie
22 + var parts = value.split( "; " + name + "=" )
4 23
5 - jQuery( document ).on( 'submit', '.fca_eoi_form', function (e) {
24 + if ( parts.length === 2 ) {
25 + return parts.pop().split(";").shift()
26 + } else {
27 + return false
28 + }
29 + }
30 +
31 + $( document ).on( 'submit', '.fca_eoi_form', function (e) {
6 32
7 - e.preventDefault();
33 + e.preventDefault()
8 34
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;
35 + var $this = $( this )
36 + var $email_field = $( '[name=email]', $this )
37 + var $name_field = $( '[name=name]', $this )
38 + var name = $name_field.val()
39 + var email = $email_field.val()
40 + var list_id = $this.data( 'fca_eoi_list_id' )
41 + var $button = $( '[type=submit]', $this )
42 + var button_initial_val
20 43 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 -
44 + var thank_you_mode = $this.data( 'fca_eoi_thank_you_mode' )
45 + var thank_you_page = $this.data( 'fca_eoi_thank_you_page' )
46 + var cookie_duration = $this.data( 'fca_eoi_success_cookie_duration' )
47 + var subscribe_msg = $this.data( 'fca_eoi_sub_msg' )
48 + var has_error = false
49 + var form_id = $( '[name=fca_eoi_form_id]', $this ).val()
50 +
27 51 // Attach tooltips
28 - jQuery( '[name=email], [name=name]', $this ).each( function() {
52 + $this.find('.tooltipstered').tooltipster('hide')
53 + $( '[name=email], [name=name]', $this ).not('.tooltipstered').each( function() {
29 54
30 - var $this = jQuery( this );
31 - var tooltipWidth = $this.width() * .8;
55 + var $this = $( this )
56 + var tooltipWidth = $this.width() * .8
32 57
33 58 $this.tooltipster( {
34 59 contentAsHTML: true,
35 60 fixedWidth: tooltipWidth,
@@ -40,28 +65,28 @@
40 65 } )
41 66 } )
42 67
43 68 // Remove tooltip and tick on focus
44 - jQuery( '[name=email], [name=name]', jQuery( this ) ).focus( function() {
45 - var $this = jQuery( this );
46 - var $button = jQuery( '[type=submit]', $this.closest( '.fca_eoi_form' ) );
47 - var button_initial_val = $button.data( 'fca_eoi_initial_val' );
69 + $( '[name=email], [name=name]', $( this ) ).focus( function() {
70 + var $this = $( this )
71 + var $button = $( '[type=submit]', $this.closest( '.fca_eoi_form' ) )
72 + var button_initial_val = $button.data( 'fca_eoi_initial_val' )
48 73
49 74 // Remove any previous icon
50 75 if( 'undefined' !== typeof( button_initial_val ) ) {
51 - $button.val( button_initial_val );
76 + $button.val( button_initial_val )
52 77 }
53 78
54 79 // Hide tooltip
55 - jQuery( this ).tooltipster( 'hide' );
56 - } );
80 + $( this ).tooltipster( 'hide' )
81 + } )
57 82
58 83 // Save or save and get initial button value
59 84 if( $button.data( 'fca_eoi_initial_val' ) ) {
60 - button_initial_val = $button.data( 'fca_eoi_initial_val' );
85 + button_initial_val = $button.data( 'fca_eoi_initial_val' )
61 86 } else {
62 - button_initial_val = $button.val();
63 - $button.data( 'fca_eoi_initial_val', button_initial_val );
87 + button_initial_val = $button.val()
88 + $button.data( 'fca_eoi_initial_val', button_initial_val )
64 89 }
65 90
66 91 // Remove any previous icon
67 92 $button.val( button_initial_val );
@@ -66,16 +91,14 @@
66 91 // Remove any previous icon
67 92 $button.val( button_initial_val );
68 93
69 94 // Get Error Messages from hidden fields
70 - fca_eoi.invalid_email = $this.find('.fca_eoi_error_texts_email').val();
71 - fca_eoi.field_required = $this.find('.fca_eoi_error_texts_required').val();
95 + fcaEoiScriptData.invalid_email = $this.find('.fca_eoi_error_texts_email').val()
96 + fcaEoiScriptData.field_required = $this.find('.fca_eoi_error_texts_required').val()
72 97
73 -
74 98 // Check email address
75 99 if( ! email || ! is_email( email ) ) {
76 -
77 - $email_field.tooltipster( 'content', email ? fca_eoi.invalid_email : fca_eoi.field_required );
100 + $email_field.tooltipster( 'content', email ? fcaEoiScriptData.invalid_email : fcaEoiScriptData.field_required )
78 101 $email_field.tooltipster( 'show' );
79 102 $button.val( '✗ ' + button_initial_val );
80 103 has_error = true;
81 104 }
@@ -80,69 +103,105 @@
80 103 has_error = true;
81 104 }
82 105
83 106 // Check name
84 - if( $name_field.length && ! name ) {
85 -
86 - $name_field.tooltipster( 'content', fca_eoi.field_required );
107 + if( $name_field.is(':visible') && !name ) {
108 + $name_field.tooltipster( 'content', fcaEoiScriptData.field_required );
87 109 $name_field.tooltipster( 'show' );
88 110 $button.val( '✗ ' + button_initial_val );
89 111 has_error = true;
90 112 }
91 -
113 +
114 + // Exit if honeypot is entered
115 + if( $( '[name=i_agree]', $this ).prop( 'checked' ) ) {
116 + return false;
117 + }
118 +
92 119 // Exit if there is any error
93 120 if( has_error ) {
94 121 return false;
95 122 }
96 123
97 - //DISABLE BUTTON CLICK EVENT
98 - $button.click(function(event) {
99 - event.preventDefault();
100 - });
101 -
102 - if ( $button.closest('.fca_eoi_form').hasClass('fca_eoi_layout_1') ) {
103 - //without extra border
104 - scaleSpinnerDiv($button, $div);
124 + var gdpr_consent = 'unknown'
125 + if( fcaEoiScriptData.gdpr_checkbox ) {
126 + if( $this.find( '.fca_eoi_gdpr_consent' ).length === 0 ) {
127 + $this.find('.fca_eoi_layout_field_wrapper').hide()
128 + $this.find('.fca_eoi_layout_email_field_inner').hide()
129 + $this.find('.fca_eoi_layout_name_field_inner').hide()
130 + if ( $this.closest( '.fca_eoi_form_wrapper ' ).hasClass( 'fca_eoi_layout_banner_wrapper' ) ) {
131 + $this.find('.fca_eoi_layout_headline_copy_wrapper')[0].style.setProperty( 'display', 'block', 'important' )
132 + $this.find('.fca_eoi_layout_headline_copy_wrapper').html( '<div style="font-size: 14px;">' + fcaEoiScriptData.consent_headline + '<br>' + '<label><input class="fca_eoi_gdpr_consent" value="" type="checkbox"></input>'+fcaEoiScriptData.consent_msg+'</label></div>')
133 + } else {
134 + $this.find('.fca_eoi_layout_description_copy_wrapper')[0].style.setProperty( 'display', 'block', 'important' )
135 + $this.find('.fca_eoi_layout_description_copy_wrapper').html( '<div style="text-align:left;">' + fcaEoiScriptData.consent_headline + '<br><br>' + '<label><input class="fca_eoi_gdpr_consent" value="" type="checkbox"></input>'+fcaEoiScriptData.consent_msg+'</label></div>')
136 + }
137 + return false
138 + }
105 139
106 - } else {
107 - //width extra border
108 - scaleSpinnerDiv($input_div, $div);
140 + gdpr_consent = $this.find( '.fca_eoi_gdpr_consent' ).prop('checked')
141 +
142 + if ( gdpr_consent == false ) {
143 + $this.find( '.fca_eoi_gdpr_consent' ).not('.tooltipstered').tooltipster( {
144 + contentAsHTML: true,
145 + trigger: 'none',
146 + theme: ['tooltipster-borderless', 'tooltipster-optin-cat']
147 + } ).tooltipster( 'content', fcaEoiScriptData.field_required ).tooltipster( 'show' )
148 + return false
149 + }
150 +
109 151 }
110 - scaleSpinnerSize($button, $spinner);
111 152
112 - //Match div border radius with button's
113 - var radius = $button.css("borderRadius");
114 - $div.css('borderRadius', radius);
115 -
116 - //animate out the button and in the spinner div
117 - $div.animate({ width: '100%'});
153 + $button.val( subscribe_msg );
154 + //DISABLE BUTTON CLICK EVENT
155 + $button.prop('disabled', true);
156 +
157 + var tz = jstz.determine()
118 158
119 - $spinner.css("display", "block");
120 - $button.attr('style', 'cursor: default' );
121 -
122 - jQuery.ajax({
123 - url: fca_eoi.ajax_url,
124 - data: { 'email': email, 'name': name, 'action': 'fca_eoi_subscribe', 'list_id': list_id ,'form_id': form_id, 'nonce': fca_eoi.nonce },
159 + $.ajax({
125 160 type: 'POST',
126 - datatype: 'text',
127 - timeout: 15000
161 + url: fcaEoiScriptData.ajax_url,
162 + data: {
163 + 'email': email,
164 + 'name': name,
165 + 'action': 'fca_eoi_subscribe',
166 + 'list_id': list_id,
167 + 'form_id': form_id,
168 + 'nonce': fcaEoiScriptData.nonce,
169 + 'timezone': tz.name(),
170 + 'consent_granted': gdpr_consent
171 + }
128 172 }).done( function( data ) {
173 +
174 + // Stop highlighting and add an icon for success/failure
175 + if ( data === '✓' ) {
176 + $button.val( data + ' ' + button_initial_val );
177 +
178 + set_cookie( 'fca_eoi_success_' + form_id, Math.floor(Date.now() / 1000), cookie_duration )
179 +
180 + //REMOVE FROM ACTIVE
181 + var activeOptins = JSON.parse( get_cookie( 'fca_eoi_active_optins' ) )
182 + if ( !Array.isArray( activeOptins ) ) {
183 + activeOptins = []
184 + }
185 + var index = activeOptins.indexOf( form_id )
186 + if ( index !== -1 ) {
187 + activeOptins.splice( index, 1 )
188 + }
189 + set_cookie ( 'fca_eoi_active_optins', JSON.stringify ( activeOptins ) )
190 +
191 + } else if( data === '✗ Failed to add user - denied' ) {
192 + $button.prop('disabled', false);
193 + $button.val( button_initial_val );
194 + $this.find( '.fca_eoi_gdpr_consent' ).tooltipster( 'show' )
195 + } else {
196 + $button.prop('disabled', false);
197 + $button.val( data );
198 + }
129 199
130 - if ( thank_you_mode == 'ajax' ) {
131 -
132 - // Stop highlighting and add an icon for success/failure
133 - if ( data === '✓' ) {
134 - $button.val( data + ' ' + button_initial_val );
135 - } else {
136 - $button.val( data );
137 - }
138 -
139 - $spinner.css("display", "none");
140 - $div.animate({ width: '0', padding: '0', left: '100%' });
141 -
142 - clearInterval( highlight_interval );
200 + if ( thank_you_mode === 'ajax' && data === '✓' ) {
201 + clearInterval( highlight_interval )
143 202 if ( thank_you_page && '✓' === data ) {
144 - tooltipWidth = $button.width();
203 + tooltipWidth = $button.width()
145 204 $button.tooltipster( {
146 205 contentAsHTML: true,
147 206 trigger: 'none',
148 207 fixedWidth: tooltipWidth,
@@ -151,51 +210,17 @@
151 210 arrow: false,
152 211 theme: ['tooltipster-borderless', 'tooltipster-optin-cat']
153 212 } );
154 213
155 - $button.tooltipster( 'content', thank_you_page );
156 - $button.tooltipster( 'show' );
157 - $email_field.prop('disabled', true);
158 - $name_field.prop('disabled', true);
214 + $button.tooltipster( 'content', thank_you_page )
215 + $button.tooltipster( 'show' )
216 + $email_field.prop('disabled', true)
217 + $name_field.prop('disabled', true)
159 218
160 - jQuery('.tooltipster-content').css("background-color", "#148544");
161 - setTimeout(function() {
162 - $button.tooltipster( 'hide' );
163 - }, 5000);
219 + $('.tooltipster-content').css("background-color", "#148544")
164 220 }
165 - } else {
166 - window.location.href = thank_you_page;
221 + } else if ( data === '✓' ) {
222 + window.location.href = thank_you_page
167 223 }
168 - });
169 - });
170 -});
171 -
172 -//set height, top and (-)margin top to same size as the fca_eoi_layout_submit_button_wrapper height
173 -
174 -function scaleSpinnerDiv ($button, $div){
175 -
176 - var h = $button.outerHeight();
177 -
178 - $div.css('height', h + 'px');
179 - $div.css('top', h + 'px');
180 - $div.css('margin-top', '-' + h + 'px');
181 - $div.css('z-index', '1');
182 -
183 -}
184 -
185 -function scaleSpinnerSize( $button, $spinner ) {
186 - var h = $button.outerHeight();
187 - var w = $button.outerWidth();
188 - h = h - 8; //account for borders
189 -
190 - var newWidth = ( w / 2 ) - ( h / 2);
191 -
192 - $spinner.css('margin-left', newWidth + 'px' );
193 - $spinner.css('height', h + 'px');
194 - $spinner.css('width', h + 'px');
195 -
196 -}
197 -
198 -function is_email( email ) {
199 - var regex = /^([a-zA-Z0-9_.+-])+\@(([a-zA-Z0-9-])+\.)+([a-zA-Z0-9]{2,4})+$/;
200 - return regex.test(email);
201 -}
224 + })
225 + })
226 +})