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

154 lines 4.4 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 subscribe_msg = $this.data( 'fca_eoi_sub_msg' );
24 var has_error = false;
25 var form_id = jQuery( '[name=fca_eoi_form_id]', $this ).val();
26
27
28 // Attach tooltips
29 jQuery( '[name=email], [name=name]', $this ).each( function() {
30
31 var $this = jQuery( this );
32 var tooltipWidth = $this.width() * .8;
33
34 $this.tooltipster( {
35 contentAsHTML: true,
36 fixedWidth: tooltipWidth,
37 minWidth: tooltipWidth,
38 maxWidth: tooltipWidth,
39 trigger: 'none',
40 theme: ['tooltipster-borderless', 'tooltipster-optin-cat']
41 } )
42 } )
43
44 // Remove tooltip and tick on focus
45 jQuery( '[name=email], [name=name]', jQuery( this ) ).focus( function() {
46 var $this = jQuery( this );
47 var $button = jQuery( '[type=submit]', $this.closest( '.fca_eoi_form' ) );
48 var button_initial_val = $button.data( 'fca_eoi_initial_val' );
49
50 // Remove any previous icon
51 if( 'undefined' !== typeof( button_initial_val ) ) {
52 $button.val( button_initial_val );
53 }
54
55 // Hide tooltip
56 jQuery( this ).tooltipster( 'hide' );
57 } );
58
59 // Save or save and get initial button value
60 if( $button.data( 'fca_eoi_initial_val' ) ) {
61 button_initial_val = $button.data( 'fca_eoi_initial_val' );
62 } else {
63 button_initial_val = $button.val();
64 $button.data( 'fca_eoi_initial_val', button_initial_val );
65 }
66
67 // Remove any previous icon
68 $button.val( button_initial_val );
69
70 // Get Error Messages from hidden fields
71 fca_eoi.invalid_email = $this.find('.fca_eoi_error_texts_email').val();
72 fca_eoi.field_required = $this.find('.fca_eoi_error_texts_required').val();
73
74
75 // Check email address
76 if( ! email || ! is_email( email ) ) {
77
78 $email_field.tooltipster( 'content', email ? fca_eoi.invalid_email : fca_eoi.field_required );
79 $email_field.tooltipster( 'show' );
80 $button.val( '' + button_initial_val );
81 has_error = true;
82 }
83
84 // Check name
85 if( $name_field.length && ! name ) {
86
87 $name_field.tooltipster( 'content', fca_eoi.field_required );
88 $name_field.tooltipster( 'show' );
89 $button.val( '' + button_initial_val );
90 has_error = true;
91 }
92
93 // Exit if there is any error
94 if( has_error ) {
95 return false;
96 }
97 $button.val( subscribe_msg );
98 //DISABLE BUTTON CLICK EVENT
99 $button.click(function(event) {
100 event.preventDefault();
101 });
102
103
104 $button.attr('style', 'cursor: default' );
105
106 jQuery.ajax({
107 url: fca_eoi.ajax_url,
108 data: { 'email': email, 'name': name, 'action': 'fca_eoi_subscribe', 'list_id': list_id ,'form_id': form_id, 'nonce': fca_eoi.nonce },
109 type: 'POST',
110 datatype: 'text',
111 timeout: 15000
112 }).done( function( data ) {
113
114 if ( thank_you_mode == 'ajax' ) {
115
116 // Stop highlighting and add an icon for success/failure
117 if ( data === '' ) {
118 $button.val( data + ' ' + button_initial_val );
119 } else {
120 $button.val( data );
121 }
122
123 clearInterval( highlight_interval );
124 if ( thank_you_page && '' === data ) {
125 tooltipWidth = $button.width();
126 $button.tooltipster( {
127 contentAsHTML: true,
128 trigger: 'none',
129 fixedWidth: tooltipWidth,
130 minWidth: tooltipWidth,
131 maxWidth: tooltipWidth,
132 arrow: false,
133 theme: ['tooltipster-borderless', 'tooltipster-optin-cat']
134 } );
135
136 $button.tooltipster( 'content', thank_you_page );
137 $button.tooltipster( 'show' );
138 $email_field.prop('disabled', true);
139 $name_field.prop('disabled', true);
140
141 jQuery('.tooltipster-content').css("background-color", "#148544");
142
143 }
144 } else {
145 window.location.href = thank_you_page;
146 }
147 });
148 });
149 });
150
151 function is_email( email ) {
152 var regex = /^([a-zA-Z0-9_.+-])+\@(([a-zA-Z0-9-])+\.)+([a-zA-Z0-9]{2,4})+$/;
153 return regex.test(email);
154 }