PluginProbe
AutomatorWP – No-Code Workflow Automation, Integration & Webhooks Plugin, now with AI / 6.0.4
AutomatorWP – No-Code Workflow Automation, Integration & Webhooks Plugin, now with AI v6.0.4
6.0.4 6.0.3 6.0.2 6.0.1 6.0.0 5.8.6 5.8.5 5.8.4 5.8.3 5.8.2 5.8.1 5.8.0 5.7.9.2 5.7.9.1 5.7.8 5.7.9 5.7.6 5.7.7 5.7.5 5.7.4 5.7.3 5.7.2 5.7.1 trunk 5.6.0 All 35 releases
automatorwp / integrations / mailerlite / assets / js / automatorwp-mailerlite.js

automatorwp-mailerlite.js in AutomatorWP – No-Code Workflow Automation, Integration & Webhooks Plugin, now with AI 6.0.4, at integrations/mailerlite/assets/js/automatorwp-mailerlite.js

75 lines 2.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 (function( $ ) {
2
3 var prefix = 'automatorwp-mailerlite-';
4 var _prefix = 'automatorwp_mailerlite_';
5
6 // On click authorize button
7 $('body').on('click', '.automatorwp_settings #' + _prefix + 'authorize', function(e) {
8 e.preventDefault();
9
10 var button = $(this);
11 var wrapper = button.parent();
12
13 var token = $('#' + _prefix + 'token').val();
14
15 // Check if response div exists
16 var response_wrap = wrapper.find('#' + _prefix + 'response');
17
18 if( ! response_wrap.length ) {
19 wrapper.append( '<div id="' + _prefix + 'response" style="display: none; margin-top: 10px;"></div>' );
20 response_wrap = wrapper.find('#' + _prefix + 'response');
21 }
22
23 // Show error message if not correctly configured
24 if( token.length === 0 ) {
25 response_wrap.addClass( 'automatorwp-notice-error' );
26 response_wrap.html( 'API token is required to connect with MailerLite' );
27 response_wrap.slideDown('fast');
28 return;
29 }
30
31 response_wrap.slideUp('fast');
32 response_wrap.attr('class', '');
33
34 // Show spinner
35 wrapper.append('<span class="spinner is-active" style="float: none;"></span>');
36
37 // Disable button
38 button.prop('disabled', true);
39
40 $.post(
41 ajaxurl,
42 {
43 action: 'automatorwp_mailerlite_authorize',
44 nonce: automatorwp_mailerlite.nonce,
45 token: token,
46 },
47 function( response ) {
48
49 // Add class automatorwp-notice-success on successful unlock, if not will add the class automatorwp-notice-error
50 response_wrap.addClass( 'automatorwp-notice-' + ( response.success === true ? 'success' : 'error' ) );
51 response_wrap.html( ( response.data.message !== undefined ? response.data.message : response.data ) );
52 response_wrap.slideDown('fast');
53
54 // Hide spinner
55 wrapper.find('.spinner').remove();
56
57 // Redirect on success
58 if( response.success === true && response.data.redirect_url !== undefined ) {
59 window.location = response.data.redirect_url;
60 return;
61 }
62
63
64 // Enable button
65 button.prop('disabled', false);
66
67 }
68 );
69
70
71 });
72
73
74
75 })( jQuery );