vendor
5 days ago
connect.js
5 days ago
connect.min.js
5 days ago
smtp-about.js
5 days ago
smtp-about.min.js
5 days ago
smtp-activelayer-wc.js
5 days ago
smtp-activelayer-wc.min.js
5 days ago
smtp-admin-notices.js
5 days ago
smtp-admin-notices.min.js
5 days ago
smtp-admin.js
5 days ago
smtp-admin.min.js
5 days ago
smtp-ai-mcp.js
5 days ago
smtp-ai-mcp.min.js
5 days ago
smtp-code-snippets.js
5 days ago
smtp-code-snippets.min.js
5 days ago
smtp-dashboard-widget.js
5 days ago
smtp-dashboard-widget.min.js
5 days ago
smtp-notifications.js
5 days ago
smtp-notifications.min.js
5 days ago
smtp-recommendations.js
5 days ago
smtp-recommendations.min.js
5 days ago
smtp-tools-debug-events.js
5 days ago
smtp-tools-debug-events.min.js
5 days ago
smtp-activelayer-wc.js
175 lines
| 1 | /* global wp_mail_smtp_activelayer_wc */ |
| 2 | |
| 3 | 'use strict'; |
| 4 | |
| 5 | ( function( $ ) { |
| 6 | |
| 7 | const l10n = wp_mail_smtp_activelayer_wc; |
| 8 | |
| 9 | const WPMailSMTPActiveLayerWC = { |
| 10 | |
| 11 | /** |
| 12 | * Bind the section controls. |
| 13 | * |
| 14 | * @since 4.9.0 |
| 15 | */ |
| 16 | init: function() { |
| 17 | |
| 18 | $( document ) |
| 19 | .on( 'click', '.wp-mail-smtp-activelayer-button', WPMailSMTPActiveLayerWC.onClick ) |
| 20 | .on( 'click', '.wp-mail-smtp-activelayer-wc-dismiss', WPMailSMTPActiveLayerWC.onDismiss ); |
| 21 | }, |
| 22 | |
| 23 | /** |
| 24 | * Handle a click on the section button based on its data-action. |
| 25 | * |
| 26 | * @since 4.9.0 |
| 27 | * |
| 28 | * @param {Event} e Click event. |
| 29 | */ |
| 30 | onClick: function( e ) { |
| 31 | |
| 32 | e.preventDefault(); |
| 33 | |
| 34 | const $btn = $( this ), |
| 35 | action = $btn.attr( 'data-action' ); |
| 36 | |
| 37 | if ( $btn.hasClass( 'disabled' ) ) { |
| 38 | return; |
| 39 | } |
| 40 | |
| 41 | if ( action === 'goto-url' ) { |
| 42 | window.open( $btn.attr( 'data-url' ), '_blank', 'noopener' ); |
| 43 | return; |
| 44 | } |
| 45 | |
| 46 | if ( action === 'goto-settings' ) { |
| 47 | window.location.href = $btn.attr( 'data-url' ); |
| 48 | return; |
| 49 | } |
| 50 | |
| 51 | if ( action === 'install' ) { |
| 52 | WPMailSMTPActiveLayerWC.run( $btn, 'about_plugin_install', l10n.download_url, l10n.installing ); |
| 53 | } else if ( action === 'activate' ) { |
| 54 | WPMailSMTPActiveLayerWC.run( $btn, 'about_plugin_activate', l10n.plugin, l10n.activating ); |
| 55 | } |
| 56 | }, |
| 57 | |
| 58 | /** |
| 59 | * Run an install or activate task through the shared plugin dispatcher. |
| 60 | * |
| 61 | * @since 4.9.0 |
| 62 | * |
| 63 | * @param {jQuery} $btn The section button. |
| 64 | * @param {string} task The dispatcher task name. |
| 65 | * @param {string} plugin The download URL (install) or basename (activate). |
| 66 | * @param {string} processingText Button text while the request runs. |
| 67 | */ |
| 68 | run: function( $btn, task, plugin, processingText ) { |
| 69 | |
| 70 | $btn.addClass( 'disabled' ).text( processingText ); |
| 71 | |
| 72 | $.post( |
| 73 | l10n.ajax_url, |
| 74 | { |
| 75 | action: 'wp_mail_smtp_ajax', |
| 76 | task: task, |
| 77 | plugin: plugin, |
| 78 | nonce: l10n.nonce |
| 79 | } |
| 80 | ) |
| 81 | .done( function( res ) { |
| 82 | |
| 83 | if ( task === 'about_plugin_install' ) { |
| 84 | |
| 85 | if ( res && res.success && res.data && res.data.is_activated ) { |
| 86 | WPMailSMTPActiveLayerWC.toSettings( $btn ); |
| 87 | return; |
| 88 | } |
| 89 | |
| 90 | // Installed but not auto-activated: try activating. |
| 91 | if ( res && res.success ) { |
| 92 | WPMailSMTPActiveLayerWC.run( $btn, 'about_plugin_activate', l10n.plugin, l10n.activating ); |
| 93 | return; |
| 94 | } |
| 95 | |
| 96 | WPMailSMTPActiveLayerWC.fail( $btn, task ); |
| 97 | return; |
| 98 | } |
| 99 | |
| 100 | if ( res && res.success ) { |
| 101 | WPMailSMTPActiveLayerWC.toSettings( $btn ); |
| 102 | return; |
| 103 | } |
| 104 | |
| 105 | WPMailSMTPActiveLayerWC.fail( $btn, task ); |
| 106 | } ) |
| 107 | .fail( function() { |
| 108 | |
| 109 | WPMailSMTPActiveLayerWC.fail( $btn, task ); |
| 110 | } ); |
| 111 | }, |
| 112 | |
| 113 | /** |
| 114 | * Turn the button into the "Connect Your Free Account" CTA. |
| 115 | * |
| 116 | * @since 4.9.0 |
| 117 | * |
| 118 | * @param {jQuery} $btn The section button. |
| 119 | */ |
| 120 | toSettings: function( $btn ) { |
| 121 | |
| 122 | $btn |
| 123 | .removeClass( 'disabled' ) |
| 124 | .attr( 'data-action', 'goto-settings' ) |
| 125 | .attr( 'data-url', l10n.settings_url ) |
| 126 | .text( l10n.goto_settings ); |
| 127 | }, |
| 128 | |
| 129 | /** |
| 130 | * Show an inline error and fall back to the WordPress.org link. |
| 131 | * |
| 132 | * @since 4.9.0 |
| 133 | * |
| 134 | * @param {jQuery} $btn The section button. |
| 135 | * @param {string} task The dispatcher task that failed. |
| 136 | */ |
| 137 | fail: function( $btn, task ) { |
| 138 | |
| 139 | const msg = task === 'about_plugin_install' ? l10n.error_install : l10n.error_activate; |
| 140 | |
| 141 | $btn |
| 142 | .removeClass( 'disabled' ) |
| 143 | .attr( 'data-action', 'goto-url' ) |
| 144 | .attr( 'data-url', l10n.wporg_url ) |
| 145 | .text( l10n.get_activelayer ); |
| 146 | |
| 147 | if ( ! $btn.siblings( '.wp-mail-smtp-activelayer-error' ).length ) { |
| 148 | $btn.after( '<p class="wp-mail-smtp-activelayer-error">' + msg + '</p>' ); |
| 149 | } |
| 150 | }, |
| 151 | |
| 152 | /** |
| 153 | * Dismiss the section for the current user. |
| 154 | * |
| 155 | * @since 4.9.0 |
| 156 | */ |
| 157 | onDismiss: function() { |
| 158 | |
| 159 | $.post( |
| 160 | l10n.ajax_url, |
| 161 | { |
| 162 | action: 'wp_mail_smtp_activelayer_wc_dismiss', |
| 163 | nonce: l10n.nonce |
| 164 | } |
| 165 | ); |
| 166 | |
| 167 | // Remove optimistically; persistence failures only resurface the section on reload. |
| 168 | $( this ).closest( '.wpms-activelayer-wc' ).remove(); |
| 169 | } |
| 170 | }; |
| 171 | |
| 172 | $( WPMailSMTPActiveLayerWC.init ); |
| 173 | |
| 174 | }( jQuery ) ); |
| 175 |