PluginProbe
GetResponse Forms by Optin Cat / 2.0.2
GetResponse Forms by Optin Cat v2.0.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
← All changes | assets/script.js +159 -102 1.4.22.0.2 View file →
@@ -1,125 +1,182 @@
1 -jQuery( document ).ready(function(){
1 +/* jshint asi: true */
2 2
3 - jQuery( document ).on( 'submit', '.fca_eoi_form', 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 + }
4 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 + }
5 19
6 -
20 + function get_cookie( name ) {
21 + var value = "; " + document.cookie
22 + var parts = value.split( "; " + name + "=" )
23 +
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) {
32 +
33 + e.preventDefault()
34 +
35 + var $this = $( this )
36 + var $email_field = $( '[name=email]', $this )
37 + var $name_field = $( '[name=name]:visible', $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
43 + var highlight_interval = false;
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 +
7 51 // Attach tooltips
8 - jQuery( '[name=email], [name=name]' ).each( function(index) {
9 -
10 - var $this = jQuery( this );
11 - var tooltipWidth = $this.width() * .8;
52 + $( '[name=email], [name=name]', $this ).not('.tooltipstered').each( function() {
12 53
54 + var $this = $( this )
55 + var tooltipWidth = $this.width() * .8
56 +
13 57 $this.tooltipster( {
14 - contentAsHTML: true
15 - , fixedWidth: tooltipWidth
16 - , minWidth: tooltipWidth
17 - , maxWidth: tooltipWidth
18 - , trigger: 'none'
19 - } );
20 - } );
58 + contentAsHTML: true,
59 + fixedWidth: tooltipWidth,
60 + minWidth: tooltipWidth,
61 + maxWidth: tooltipWidth,
62 + trigger: 'none',
63 + theme: ['tooltipster-borderless', 'tooltipster-optin-cat']
64 + } )
65 + } )
21 66
22 67 // 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' );
68 + $( '[name=email], [name=name]', $( this ) ).focus( function() {
69 + var $this = $( this )
70 + var $button = $( '[type=submit]', $this.closest( '.fca_eoi_form' ) )
71 + var button_initial_val = $button.data( 'fca_eoi_initial_val' )
27 72
28 73 // Remove any previous icon
29 74 if( 'undefined' !== typeof( button_initial_val ) ) {
30 - $button.val( button_initial_val );
75 + $button.val( button_initial_val )
31 76 }
32 77
33 78 // Hide tooltip
34 - jQuery( this ).tooltipster( 'hide' );
35 - } );
79 + $( this ).tooltipster( 'hide' )
80 + } )
81 +
82 + // Save or save and get initial button value
83 + if( $button.data( 'fca_eoi_initial_val' ) ) {
84 + button_initial_val = $button.data( 'fca_eoi_initial_val' )
85 + } else {
86 + button_initial_val = $button.val()
87 + $button.data( 'fca_eoi_initial_val', button_initial_val )
88 + }
36 89
90 + // Remove any previous icon
91 + $button.val( button_initial_val );
37 92
38 - //RN NOTE WHY IS THIS SO OVER COMPLICATED...
93 + // Get Error Messages from hidden fields
94 + fcaEoiScriptData.invalid_email = $this.find('.fca_eoi_error_texts_email').val()
95 + fcaEoiScriptData.field_required = $this.find('.fca_eoi_error_texts_required').val()
39 96
40 - // Handle form submissions
41 - //$( '.fca_eoi_form' ).submit( function( e ) {
97 + // Check email address
98 + if( ! email || ! is_email( email ) ) {
99 + $email_field.tooltipster( 'content', email ? fcaEoiScriptData.invalid_email : fcaEoiScriptData.field_required )
100 + $email_field.tooltipster( 'show' );
101 + $button.val( '✗ ' + button_initial_val );
102 + has_error = true;
103 + }
42 104
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();
105 + // Check name
106 + if( $name_field.length && ! name ) {
107 + $name_field.tooltipster( 'content', fcaEoiScriptData.field_required );
108 + $name_field.tooltipster( 'show' );
109 + $button.val( '✗ ' + button_initial_val );
110 + has_error = true;
111 + }
56 112
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' );
113 + // Exit if there is any error
114 + if( has_error ) {
115 + return false;
116 + }
117 + $button.val( subscribe_msg );
118 + //DISABLE BUTTON CLICK EVENT
119 + $button.click(function(event) {
120 + event.preventDefault();
121 + });
122 +
123 +
124 + $button.attr('style', 'cursor: default' );
125 + var tz = jstz.determine()
126 +
127 + $.ajax({
128 + url: fcaEoiScriptData.ajax_url,
129 + data: { 'email': email, 'name': name, 'action': 'fca_eoi_subscribe', 'list_id': list_id ,'form_id': form_id, 'nonce': fcaEoiScriptData.nonce, 'timezone' : tz.name() },
130 + type: 'POST',
131 + datatype: 'text',
132 + timeout: 15000
133 + }).done( function( data ) {
134 +
135 + // Stop highlighting and add an icon for success/failure
136 + if ( data === '✓' ) {
137 + $button.val( data + ' ' + button_initial_val );
138 +
139 + set_cookie( 'fca_eoi_success_' + form_id, Math.floor(Date.now() / 1000), cookie_duration )
140 +
141 + //REMOVE FROM ACTIVE
142 + var activeOptins = JSON.parse( get_cookie( 'fca_eoi_active_optins' ) )
143 + if ( !Array.isArray( activeOptins ) ) {
144 + activeOptins = []
145 + }
146 + var index = activeOptins.indexOf( form_id )
147 + if ( index !== -1 ) {
148 + activeOptins.splice( index, 1 )
149 + }
150 + set_cookie ( 'fca_eoi_active_optins', JSON.stringify ( activeOptins ) )
151 +
60 152 } else {
61 - button_initial_val = $button.val();
62 - $button.data( 'fca_eoi_initial_val', button_initial_val );
153 + $button.val( data );
63 154 }
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 );
155 +
156 + if ( thank_you_mode === 'ajax' && data === '✓' ) {
157 + clearInterval( highlight_interval )
114 158 if ( thank_you_page && '✓' === data ) {
115 - window.location.href = thank_you_page;
159 + tooltipWidth = $button.width()
160 + $button.tooltipster( {
161 + contentAsHTML: true,
162 + trigger: 'none',
163 + fixedWidth: tooltipWidth,
164 + minWidth: tooltipWidth,
165 + maxWidth: tooltipWidth,
166 + arrow: false,
167 + theme: ['tooltipster-borderless', 'tooltipster-optin-cat']
168 + } );
169 +
170 + $button.tooltipster( 'content', thank_you_page )
171 + $button.tooltipster( 'show' )
172 + $email_field.prop('disabled', true)
173 + $name_field.prop('disabled', true)
174 +
175 + $('.tooltipster-content').css("background-color", "#148544")
116 176 }
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 -}
177 + } else if ( data === '✓' ) {
178 + window.location.href = thank_you_page
179 + }
180 + })
181 + })
182 +})