| 1 |
( function ( $ ) { |
| 2 |
const wcf_back_step_button = function () { |
| 3 |
if ( 'cartflows_step' === typenow ) { |
| 4 |
const step_back_button = $( '#wcf-gutenberg-back-step-button' ); |
| 5 |
|
| 6 |
if ( step_back_button.length > 0 ) { |
| 7 |
$( '#editor' ) |
| 8 |
.find( '.edit-post-header__toolbar' ) |
| 9 |
.append( step_back_button.html() ); |
| 10 |
} |
| 11 |
} |
| 12 |
}; |
| 13 |
|
| 14 |
$( function () { |
| 15 |
setTimeout( function () { |
| 16 |
wcf_back_step_button(); |
| 17 |
}, 300 ); |
| 18 |
} ); |
| 19 |
|
| 20 |
function installSuccess( event, args ) { |
| 21 |
event.preventDefault(); |
| 22 |
const plugin_slug = args.slug; |
| 23 |
activatePlugin( plugin_slug ); |
| 24 |
} |
| 25 |
|
| 26 |
function activatePlugin( plugin_slug ) { |
| 27 |
const plugin_init = plugin_slug + '/' + plugin_slug + '.php'; |
| 28 |
$.ajax( { |
| 29 |
type: 'POST', |
| 30 |
dataType: 'json', |
| 31 |
url: cartflows_admin.ajax_url, |
| 32 |
data: { |
| 33 |
action: 'cartflows_activate_plugin', |
| 34 |
security: cartflows_admin.activate_plugin_nonce, |
| 35 |
init: plugin_init, |
| 36 |
}, |
| 37 |
success( response ) { |
| 38 |
if ( response.data && response.data.success ) { |
| 39 |
if ( 'woocommerce-payments' === plugin_slug ) { |
| 40 |
window.location.replace( |
| 41 |
cartflows_admin.admin_base_url + |
| 42 |
`admin.php?page=wc-admin&path=/payments/connect` |
| 43 |
); |
| 44 |
} else { |
| 45 |
window.location.reload(); |
| 46 |
} |
| 47 |
} |
| 48 |
}, |
| 49 |
error() { |
| 50 |
$( 'body' ).css( 'cursor', 'default' ); |
| 51 |
alert( 'Something went wrong!' ); |
| 52 |
}, |
| 53 |
} ); |
| 54 |
} |
| 55 |
|
| 56 |
$( document ).on( 'wp-plugin-install-success', installSuccess ); |
| 57 |
} )( jQuery ); |
| 58 |
|