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 +114 -103 1.5.02.0.2 View file →
@@ -1,65 +1,91 @@
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 + }
6 30
7 - e.preventDefault();
31 + $( document ).on( 'submit', '.fca_eoi_form', function (e) {
8 32
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;
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
19 43 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();
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()
25 50
26 51 // Attach tooltips
27 - jQuery( '[name=email], [name=name]', jQuery( this ) ).each( function() {
52 + $( '[name=email], [name=name]', $this ).not('.tooltipstered').each( function() {
28 53
29 - var $this = jQuery( this );
30 - var tooltipWidth = $this.width() * .8;
54 + var $this = $( this )
55 + var tooltipWidth = $this.width() * .8
31 56
32 57 $this.tooltipster( {
33 - contentAsHTML: true
34 - , fixedWidth: tooltipWidth
35 - , minWidth: tooltipWidth
36 - , maxWidth: tooltipWidth
37 - , trigger: 'none'
38 - } );
39 - } );
58 + contentAsHTML: true,
59 + fixedWidth: tooltipWidth,
60 + minWidth: tooltipWidth,
61 + maxWidth: tooltipWidth,
62 + trigger: 'none',
63 + theme: ['tooltipster-borderless', 'tooltipster-optin-cat']
64 + } )
65 + } )
40 66
41 67 // 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' );
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' )
46 72
47 73 // Remove any previous icon
48 74 if( 'undefined' !== typeof( button_initial_val ) ) {
49 - $button.val( button_initial_val );
75 + $button.val( button_initial_val )
50 76 }
51 77
52 78 // Hide tooltip
53 - jQuery( this ).tooltipster( 'hide' );
54 - } );
79 + $( this ).tooltipster( 'hide' )
80 + } )
55 81
56 82 // Save or save and get initial button value
57 83 if( $button.data( 'fca_eoi_initial_val' ) ) {
58 - button_initial_val = $button.data( 'fca_eoi_initial_val' );
84 + button_initial_val = $button.data( 'fca_eoi_initial_val' )
59 85 } else {
60 - button_initial_val = $button.val();
61 - $button.data( 'fca_eoi_initial_val', button_initial_val );
86 + button_initial_val = $button.val()
87 + $button.data( 'fca_eoi_initial_val', button_initial_val )
62 88 }
63 89
64 90 // Remove any previous icon
65 91 $button.val( button_initial_val );
@@ -64,16 +90,14 @@
64 90 // Remove any previous icon
65 91 $button.val( button_initial_val );
66 92
67 93 // 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();
94 + fcaEoiScriptData.invalid_email = $this.find('.fca_eoi_error_texts_email').val()
95 + fcaEoiScriptData.field_required = $this.find('.fca_eoi_error_texts_required').val()
70 96
71 -
72 97 // Check email address
73 98 if( ! email || ! is_email( email ) ) {
74 -
75 - $email_field.tooltipster( 'content', email ? fca_eoi.invalid_email : fca_eoi.field_required );
99 + $email_field.tooltipster( 'content', email ? fcaEoiScriptData.invalid_email : fcaEoiScriptData.field_required )
76 100 $email_field.tooltipster( 'show' );
77 101 $button.val( '✗ ' + button_initial_val );
78 102 has_error = true;
79 103 }
@@ -79,10 +103,9 @@
79 103 }
80 104
81 105 // Check name
82 106 if( $name_field.length && ! name ) {
83 -
84 - $name_field.tooltipster( 'content', fca_eoi.field_required );
107 + $name_field.tooltipster( 'content', fcaEoiScriptData.field_required );
85 108 $name_field.tooltipster( 'show' );
86 109 $button.val( '✗ ' + button_initial_val );
87 110 has_error = true;
88 111 }
@@ -90,48 +113,51 @@
90 113 // Exit if there is any error
91 114 if( has_error ) {
92 115 return false;
93 116 }
117 + $button.val( subscribe_msg );
94 118 //DISABLE BUTTON CLICK EVENT
95 119 $button.click(function(event) {
96 120 event.preventDefault();
97 121 });
98 122
123 +
124 + $button.attr('style', 'cursor: default' );
125 + var tz = jstz.determine()
99 126
100 - if (thank_you_mode != 'redirect') {
101 -
102 - // Run function to scale spinner based on button size
103 - scaleSpinnerSize($button, $spinner);
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 ) {
104 134
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
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 +
111 152 } else {
112 - $spinner.parent('.fca_eoi_layout_submit_button_wrapper').attr('style', 'transition: none !important; background-color: #808080 !important; border: 1px solid #808080 !important;');
153 + $button.val( data );
113 154 }
114 - }
115 -
116 155
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();
156 + if ( thank_you_mode === 'ajax' && data === '✓' ) {
157 + clearInterval( highlight_interval )
158 + if ( thank_you_page && '✓' === data ) {
159 + tooltipWidth = $button.width()
134 160 $button.tooltipster( {
135 161 contentAsHTML: true,
136 162 trigger: 'none',
137 163 fixedWidth: tooltipWidth,
@@ -136,36 +162,21 @@
136 162 trigger: 'none',
137 163 fixedWidth: tooltipWidth,
138 164 minWidth: tooltipWidth,
139 165 maxWidth: tooltipWidth,
140 - arrowColor: '#148544'
166 + arrow: false,
167 + theme: ['tooltipster-borderless', 'tooltipster-optin-cat']
141 168 } );
142 - $button.tooltipster( 'content', thank_you_page );
143 - $button.tooltipster( 'show' );
144 - $email_field.prop('disabled', true);
145 - $name_field.prop('disabled', true);
146 169
147 - jQuery('.tooltipster-content').css("background-color", "#148544");
148 -
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")
149 176 }
177 + } else if ( data === '✓' ) {
178 + window.location.href = thank_you_page
150 179 }
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 -}
180 + })
181 + })
182 +})