2015-07-10 04:32:30 +00:00
|
|
|
/*global wc_setup_params */
|
2016-04-01 10:19:55 +00:00
|
|
|
jQuery( function( $ ) {
|
2017-09-10 22:48:38 +00:00
|
|
|
function blockWizardUI() {
|
|
|
|
$('.wc-setup-content').block({
|
|
|
|
message: null,
|
|
|
|
overlayCSS: {
|
|
|
|
background: '#fff',
|
|
|
|
opacity: 0.6
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2016-03-31 16:17:11 +00:00
|
|
|
$( '.button-next' ).on( 'click', function() {
|
2017-09-09 01:45:57 +00:00
|
|
|
var form = $( this ).parents( 'form' ).get( 0 );
|
|
|
|
|
2017-09-10 22:33:04 +00:00
|
|
|
if ( ( 'function' !== typeof form.checkValidity ) || form.checkValidity() ) {
|
2017-09-10 22:48:38 +00:00
|
|
|
blockWizardUI();
|
2017-09-09 01:45:57 +00:00
|
|
|
}
|
|
|
|
|
2015-08-21 18:12:36 +00:00
|
|
|
return true;
|
2016-04-01 10:19:55 +00:00
|
|
|
} );
|
2015-08-21 18:12:36 +00:00
|
|
|
|
2017-09-07 23:03:16 +00:00
|
|
|
$( '.wc-wizard-services' ).on( 'change', '.wc-wizard-service-enable input', function() {
|
2016-04-01 16:30:04 +00:00
|
|
|
if ( $( this ).is( ':checked' ) ) {
|
2017-09-07 23:03:16 +00:00
|
|
|
$( this ).closest( '.wc-wizard-service-toggle' ).removeClass( 'disabled' );
|
2017-09-17 00:57:17 +00:00
|
|
|
$( this ).closest( '.wc-wizard-service-item' ).addClass( 'checked' );
|
2016-04-01 16:30:04 +00:00
|
|
|
} else {
|
2017-09-07 23:03:16 +00:00
|
|
|
$( this ).closest( '.wc-wizard-service-toggle' ).addClass( 'disabled' );
|
2017-09-17 00:57:17 +00:00
|
|
|
$( this ).closest( '.wc-wizard-service-item' ).removeClass( 'checked' );
|
2016-04-01 16:30:04 +00:00
|
|
|
}
|
|
|
|
} );
|
|
|
|
|
2017-09-09 02:11:28 +00:00
|
|
|
$( '.wc-wizard-services' ).on( 'click', '.wc-wizard-service-enable', function( e ) {
|
2016-04-01 16:30:04 +00:00
|
|
|
e.stopPropagation();
|
2017-09-09 02:11:28 +00:00
|
|
|
|
|
|
|
var $checkbox = $( this ).find( '.wc-wizard-service-toggle input' );
|
|
|
|
$checkbox.prop( 'checked', ! $checkbox.prop( 'checked' ) ).change();
|
2016-04-01 16:30:04 +00:00
|
|
|
} );
|
2017-09-07 23:24:49 +00:00
|
|
|
|
|
|
|
$( '.wc-wizard-services-list-toggle' ).on( 'change', '.wc-wizard-service-enable input', function() {
|
|
|
|
$( this ).closest( '.wc-wizard-services' ).find( '.wc-wizard-service-item' )
|
|
|
|
.slideToggle()
|
|
|
|
.css( 'display', 'flex' );
|
|
|
|
} );
|
2017-09-09 03:53:34 +00:00
|
|
|
|
2017-09-10 16:39:38 +00:00
|
|
|
$( '.wc-wizard-services' ).on( 'change', '.wc-wizard-shipping-method-select .method', function( e ) {
|
|
|
|
var $zone = $( this ).parent( 'div' );
|
2017-09-11 20:56:29 +00:00
|
|
|
var selectedMethod = e.target.value;
|
2017-09-09 03:53:34 +00:00
|
|
|
|
|
|
|
var $descriptions = $zone.find( '.shipping-method-description' );
|
|
|
|
$descriptions.find( 'p' ).hide();
|
2017-09-11 20:56:29 +00:00
|
|
|
$descriptions.find( 'p.' + selectedMethod ).show();
|
2017-09-09 03:53:34 +00:00
|
|
|
|
|
|
|
var $settings = $zone.find( '.shipping-method-settings' );
|
|
|
|
$settings.find( 'div' ).hide();
|
2017-09-11 20:56:29 +00:00
|
|
|
$settings.find( 'div.' + selectedMethod ).show();
|
2017-09-09 03:53:34 +00:00
|
|
|
} );
|
2017-09-10 22:48:38 +00:00
|
|
|
|
|
|
|
function submitActivateForm() {
|
|
|
|
$( 'form.activate-jetpack' ).submit();
|
|
|
|
}
|
|
|
|
|
|
|
|
function waitForJetpackInstall() {
|
|
|
|
wp.ajax.post( 'setup_wizard_check_jetpack' )
|
|
|
|
.then( function( result ) {
|
|
|
|
// If we receive success, or an unexpected result
|
|
|
|
// let the form submit.
|
|
|
|
if (
|
|
|
|
! result ||
|
|
|
|
! result.is_active ||
|
|
|
|
'yes' === result.is_active
|
|
|
|
) {
|
|
|
|
return submitActivateForm();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Wait until checking the status again
|
|
|
|
setTimeout( waitForJetpackInstall, 3000 );
|
|
|
|
} )
|
|
|
|
.fail( function() {
|
|
|
|
// Submit the form as normal if the request fails
|
|
|
|
submitActivateForm();
|
|
|
|
} );
|
|
|
|
}
|
|
|
|
|
|
|
|
// Wait for a pending Jetpack install to finish before triggering a "save"
|
|
|
|
// on the activate step, which launches the Jetpack connection flow.
|
|
|
|
$( '.button-jetpack-connect' ).on( 'click', function( e ) {
|
|
|
|
blockWizardUI();
|
|
|
|
|
|
|
|
if ( 'no' === wc_setup_params.pending_jetpack_install ) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
e.preventDefault();
|
|
|
|
waitForJetpackInstall();
|
|
|
|
} );
|
2016-04-01 10:19:55 +00:00
|
|
|
} );
|