2015-07-10 04:32:30 +00:00
|
|
|
/*global wc_setup_params */
|
2017-10-26 12:39:54 +00:00
|
|
|
/*global wc_setup_currencies */
|
2018-03-27 18:32:04 +00:00
|
|
|
/*global wc_base_state */
|
2020-09-18 16:16:46 +00:00
|
|
|
/* @deprecated 4.6.0 */
|
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
|
|
|
|
2019-09-24 18:26:21 +00:00
|
|
|
$( 'form.address-step' ).on( 'submit', function( e ) {
|
|
|
|
var form = $( this );
|
|
|
|
if ( ( 'function' !== typeof form.checkValidity ) || form.checkValidity() ) {
|
|
|
|
blockWizardUI();
|
|
|
|
}
|
|
|
|
|
|
|
|
e.preventDefault();
|
|
|
|
$('.wc-setup-content').unblock();
|
|
|
|
|
|
|
|
$( this ).WCBackboneModal( {
|
|
|
|
template: 'wc-modal-tracking-setup'
|
|
|
|
} );
|
|
|
|
|
|
|
|
$( document.body ).on( 'wc_backbone_modal_response', function() {
|
2021-02-04 17:35:37 +00:00
|
|
|
form.off( 'submit' ).trigger( 'submit' );
|
2019-09-24 18:26:21 +00:00
|
|
|
} );
|
|
|
|
|
|
|
|
$( '#wc_tracker_checkbox_dialog' ).on( 'change', function( e ) {
|
|
|
|
var eventTarget = $( e.target );
|
|
|
|
$( '#wc_tracker_checkbox' ).prop( 'checked', eventTarget.prop( 'checked' ) );
|
|
|
|
} );
|
|
|
|
|
|
|
|
$( '#wc_tracker_submit' ).on( 'click', function () {
|
2021-02-04 17:35:37 +00:00
|
|
|
form.off( 'submit' ).trigger( 'submit' );
|
2019-09-24 18:26:21 +00:00
|
|
|
} );
|
|
|
|
|
|
|
|
return true;
|
|
|
|
} );
|
|
|
|
|
2018-03-27 18:32:04 +00:00
|
|
|
$( '#store_country' ).on( 'change', function() {
|
|
|
|
// Prevent if we don't have the metabox data
|
|
|
|
if ( wc_setup_params.states === null ){
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
var $this = $( this ),
|
|
|
|
country = $this.val(),
|
|
|
|
$state_select = $( '#store_state' );
|
|
|
|
|
|
|
|
if ( ! $.isEmptyObject( wc_setup_params.states[ country ] ) ) {
|
|
|
|
var states = wc_setup_params.states[ country ];
|
|
|
|
|
|
|
|
$state_select.empty();
|
|
|
|
|
|
|
|
$.each( states, function( index ) {
|
|
|
|
$state_select.append( $( '<option value="' + index + '">' + states[ index ] + '</option>' ) );
|
|
|
|
} );
|
|
|
|
|
|
|
|
$( '.store-state-container' ).show();
|
2021-01-07 22:08:36 +00:00
|
|
|
$state_select.selectWoo().val( wc_base_state ).trigger( 'change' ).prop( 'required', true );
|
2018-03-27 18:32:04 +00:00
|
|
|
} else {
|
|
|
|
$( '.store-state-container' ).hide();
|
2021-01-07 22:08:36 +00:00
|
|
|
$state_select.empty().val( '' ).trigger( 'change' ).prop( 'required', false );
|
2018-03-27 18:32:04 +00:00
|
|
|
}
|
2018-05-03 08:45:01 +00:00
|
|
|
|
2021-01-07 22:08:36 +00:00
|
|
|
$( '#currency_code' ).val( wc_setup_currencies[ country ] ).trigger( 'change' );
|
2018-03-27 18:32:04 +00:00
|
|
|
} );
|
|
|
|
|
2019-06-12 14:54:36 +00:00
|
|
|
/* Setup postcode field and validations */
|
|
|
|
$( '#store_country' ).on( 'change', function() {
|
|
|
|
if ( ! wc_setup_params.postcodes ) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
var $this = $( this ),
|
|
|
|
country = $this.val(),
|
|
|
|
$store_postcode_input = $( '#store_postcode' ),
|
|
|
|
country_postcode_obj = wc_setup_params.postcodes[ country ];
|
|
|
|
|
|
|
|
// Default to required, if its unknown whether postcode is required or not.
|
|
|
|
if ( $.isEmptyObject( country_postcode_obj ) || country_postcode_obj.required ) {
|
|
|
|
$store_postcode_input.attr( 'required', 'true' );
|
|
|
|
} else {
|
2021-03-05 18:58:12 +00:00
|
|
|
$store_postcode_input.prop( 'required', false );
|
2019-06-12 14:54:36 +00:00
|
|
|
}
|
|
|
|
} );
|
|
|
|
|
2021-01-07 22:08:36 +00:00
|
|
|
$( '#store_country' ).trigger( 'change' );
|
2018-03-27 18:32:04 +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' );
|
2017-10-04 19:37:59 +00:00
|
|
|
$( this ).closest( '.wc-wizard-service-item' )
|
|
|
|
.find( '.wc-wizard-service-settings' ).removeClass( 'hide' );
|
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' );
|
2017-10-04 19:37:59 +00:00
|
|
|
$( this ).closest( '.wc-wizard-service-item' )
|
|
|
|
.find( '.wc-wizard-service-settings' ).addClass( 'hide' );
|
2016-04-01 16:30:04 +00:00
|
|
|
}
|
|
|
|
} );
|
|
|
|
|
2019-03-05 14:23:28 +00:00
|
|
|
$( '.wc-wizard-services' ).on( 'keyup', function( e ) {
|
|
|
|
var code = e.keyCode || e.which,
|
|
|
|
$focused = $( document.activeElement );
|
|
|
|
|
|
|
|
if ( $focused.is( '.wc-wizard-service-toggle, .wc-wizard-service-enable' ) && ( 13 === code || 32 === code ) ) {
|
2021-01-07 22:00:55 +00:00
|
|
|
$focused.find( ':input' ).trigger( 'click' );
|
2019-03-05 14:23:28 +00:00
|
|
|
}
|
|
|
|
} );
|
|
|
|
|
2017-09-09 02:11:28 +00:00
|
|
|
$( '.wc-wizard-services' ).on( 'click', '.wc-wizard-service-enable', function( e ) {
|
2017-11-15 14:34:35 +00:00
|
|
|
var eventTarget = $( e.target );
|
|
|
|
|
|
|
|
if ( eventTarget.is( 'input' ) ) {
|
|
|
|
e.stopPropagation();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
var $checkbox = $( this ).find( 'input[type="checkbox"]' );
|
2017-09-09 02:11:28 +00:00
|
|
|
|
2021-01-07 22:08:36 +00:00
|
|
|
$checkbox.prop( 'checked', ! $checkbox.prop( 'checked' ) ).trigger( 'change' );
|
2016-04-01 16:30:04 +00:00
|
|
|
} );
|
2017-09-07 23:24:49 +00:00
|
|
|
|
2018-02-20 01:03:32 +00:00
|
|
|
$( '.wc-wizard-services-list-toggle' ).on( 'click', function() {
|
2021-02-04 21:21:44 +00:00
|
|
|
var listToggle = $( this ).closest( '.wc-wizard-services-list-toggle' );
|
|
|
|
|
|
|
|
if ( listToggle.hasClass( 'closed' ) ) {
|
|
|
|
listToggle.removeClass( 'closed' );
|
|
|
|
} else {
|
|
|
|
listToggle.addClass( 'closed' );
|
|
|
|
}
|
|
|
|
|
2017-11-15 14:34:35 +00:00
|
|
|
$( this ).closest( '.wc-wizard-services' ).find( '.wc-wizard-service-item' )
|
|
|
|
.slideToggle()
|
|
|
|
.css( 'display', 'flex' );
|
2017-09-07 23:24:49 +00:00
|
|
|
} );
|
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 ) {
|
2017-09-21 17:17:55 +00:00
|
|
|
var zone = $( this ).closest( '.wc-wizard-service-description' );
|
2017-09-11 20:56:29 +00:00
|
|
|
var selectedMethod = e.target.value;
|
2017-09-09 03:53:34 +00:00
|
|
|
|
2017-09-21 17:17:55 +00:00
|
|
|
var description = zone.find( '.shipping-method-descriptions' );
|
|
|
|
description.find( '.shipping-method-description' ).addClass( 'hide' );
|
|
|
|
description.find( '.' + selectedMethod ).removeClass( 'hide' );
|
2017-09-09 03:53:34 +00:00
|
|
|
|
2019-01-29 18:24:08 +00:00
|
|
|
var $checkbox = zone.parent().find( 'input[type="checkbox"]' );
|
2017-09-21 17:17:55 +00:00
|
|
|
var settings = zone.find( '.shipping-method-settings' );
|
2017-10-10 15:59:08 +00:00
|
|
|
settings
|
|
|
|
.find( '.shipping-method-setting' )
|
|
|
|
.addClass( 'hide' )
|
|
|
|
.find( '.shipping-method-required-field' )
|
|
|
|
.prop( 'required', false );
|
|
|
|
settings
|
|
|
|
.find( '.' + selectedMethod )
|
|
|
|
.removeClass( 'hide' )
|
|
|
|
.find( '.shipping-method-required-field' )
|
2019-01-29 18:24:08 +00:00
|
|
|
.prop( 'required', $checkbox.prop( 'checked' ) );
|
2021-01-07 22:08:36 +00:00
|
|
|
} ).find( '.wc-wizard-shipping-method-select .method' ).trigger( 'change' );
|
2017-10-10 15:59:08 +00:00
|
|
|
|
2017-10-11 09:50:39 +00:00
|
|
|
$( '.wc-wizard-services' ).on( 'change', '.wc-wizard-shipping-method-enable', function() {
|
2017-10-10 15:59:08 +00:00
|
|
|
var checked = $( this ).is( ':checked' );
|
2020-01-31 11:45:08 +00:00
|
|
|
var selectedMethod = $( this )
|
|
|
|
.closest( '.wc-wizard-service-item' )
|
|
|
|
.find( '.wc-wizard-shipping-method-select .method' )
|
|
|
|
.val();
|
2017-10-10 15:59:08 +00:00
|
|
|
|
|
|
|
$( this )
|
|
|
|
.closest( '.wc-wizard-service-item' )
|
2018-05-07 15:32:00 +00:00
|
|
|
.find( '.' + selectedMethod )
|
2017-10-10 15:59:08 +00:00
|
|
|
.find( '.shipping-method-required-field' )
|
|
|
|
.prop( 'required', checked );
|
2017-09-09 03:53:34 +00:00
|
|
|
} );
|
2017-09-10 22:48:38 +00:00
|
|
|
|
|
|
|
function submitActivateForm() {
|
2021-01-07 22:00:14 +00:00
|
|
|
$( 'form.activate-jetpack' ).trigger( 'submit' );
|
2017-09-10 22:48:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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.
|
2017-09-25 15:24:16 +00:00
|
|
|
$( '.activate-jetpack' ).on( 'click', '.button-primary', function( e ) {
|
2017-09-10 22:48:38 +00:00
|
|
|
blockWizardUI();
|
|
|
|
|
|
|
|
if ( 'no' === wc_setup_params.pending_jetpack_install ) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
e.preventDefault();
|
|
|
|
waitForJetpackInstall();
|
|
|
|
} );
|
2017-10-04 19:37:59 +00:00
|
|
|
|
2019-11-06 19:01:16 +00:00
|
|
|
$( '.activate-new-onboarding' ).on( 'click', '.button-primary', function() {
|
|
|
|
// Show pending spinner while activate happens.
|
|
|
|
blockWizardUI();
|
|
|
|
} );
|
|
|
|
|
2017-12-05 19:58:50 +00:00
|
|
|
$( '.wc-wizard-services' ).on( 'change', 'input#stripe_create_account, input#ppec_paypal_reroute_requests', function() {
|
2017-10-04 19:37:59 +00:00
|
|
|
if ( $( this ).is( ':checked' ) ) {
|
|
|
|
$( this ).closest( '.wc-wizard-service-settings' )
|
|
|
|
.find( 'input.payment-email-input' )
|
2018-08-31 15:36:41 +00:00
|
|
|
.attr( 'type', 'email' )
|
2018-09-20 20:48:43 +00:00
|
|
|
.prop( 'disabled', false )
|
2017-10-04 19:37:59 +00:00
|
|
|
.prop( 'required', true );
|
|
|
|
} else {
|
|
|
|
$( this ).closest( '.wc-wizard-service-settings' )
|
|
|
|
.find( 'input.payment-email-input' )
|
2018-08-31 15:36:41 +00:00
|
|
|
.attr( 'type', null )
|
2018-09-20 20:48:43 +00:00
|
|
|
.prop( 'disabled', true )
|
2017-10-04 19:37:59 +00:00
|
|
|
.prop( 'required', false );
|
|
|
|
}
|
2021-01-07 22:08:36 +00:00
|
|
|
} ).find( 'input#stripe_create_account, input#ppec_paypal_reroute_requests' ).trigger( 'change' );
|
2017-10-26 12:39:54 +00:00
|
|
|
|
2018-05-03 09:18:00 +00:00
|
|
|
function addPlugins( bySlug, $el, hover ) {
|
|
|
|
var plugins = $el.data( 'plugins' );
|
|
|
|
for ( var i in Array.isArray( plugins ) ? plugins : [] ) {
|
|
|
|
var slug = plugins[ i ].slug;
|
|
|
|
bySlug[ slug ] = bySlug[ slug ] ||
|
|
|
|
$( '<span class="plugin-install-info-list-item">' )
|
|
|
|
.append( '<a href="https://wordpress.org/plugins/' + slug + '/" target="_blank">' + plugins[ i ].name + '</a>' );
|
|
|
|
|
|
|
|
bySlug[ slug ].find( 'a' )
|
|
|
|
.on( 'mouseenter mouseleave', ( function( $hover, event ) {
|
|
|
|
$hover.toggleClass( 'plugin-install-source', 'mouseenter' === event.type );
|
2021-01-07 22:16:59 +00:00
|
|
|
} ).bind( null, hover ? $el.closest( hover ) : $el ) );
|
2018-05-02 20:58:56 +00:00
|
|
|
}
|
2018-05-03 09:18:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function updatePluginInfo() {
|
|
|
|
var pluginLinkBySlug = {};
|
2018-08-29 22:47:46 +00:00
|
|
|
var extraPlugins = [];
|
2018-05-02 20:58:56 +00:00
|
|
|
|
|
|
|
$( '.wc-wizard-service-enable input:checked' ).each( function() {
|
2018-05-03 09:18:00 +00:00
|
|
|
addPlugins( pluginLinkBySlug, $( this ), '.wc-wizard-service-item' );
|
2018-05-03 03:35:42 +00:00
|
|
|
|
|
|
|
var $container = $( this ).closest( '.wc-wizard-service-item' );
|
|
|
|
$container.find( 'input.payment-checkbox-input:checked' ).each( function() {
|
2018-08-29 22:47:46 +00:00
|
|
|
extraPlugins.push( $( this ).attr( 'id' ) );
|
2018-05-03 09:18:00 +00:00
|
|
|
addPlugins( pluginLinkBySlug, $( this ), '.wc-wizard-service-settings' );
|
2018-05-02 21:00:29 +00:00
|
|
|
} );
|
2018-05-03 03:35:42 +00:00
|
|
|
$container.find( '.wc-wizard-shipping-method-select .method' ).each( function() {
|
|
|
|
var $this = $( this );
|
|
|
|
if ( 'live_rates' === $this.val() ) {
|
2018-05-03 09:18:00 +00:00
|
|
|
addPlugins( pluginLinkBySlug, $this, '.wc-wizard-service-item' );
|
2018-05-03 03:35:42 +00:00
|
|
|
}
|
|
|
|
} );
|
2018-05-02 21:23:36 +00:00
|
|
|
} );
|
|
|
|
|
2018-05-07 13:39:44 +00:00
|
|
|
$( '.recommended-item input:checked' ).each( function() {
|
2018-05-03 09:18:00 +00:00
|
|
|
addPlugins( pluginLinkBySlug, $( this ), '.recommended-item' );
|
2018-05-02 21:24:11 +00:00
|
|
|
} );
|
|
|
|
|
2018-05-03 09:18:00 +00:00
|
|
|
var $list = $( 'span.plugin-install-info-list' ).empty();
|
2018-08-29 22:47:46 +00:00
|
|
|
|
2018-05-03 09:18:00 +00:00
|
|
|
for ( var slug in pluginLinkBySlug ) {
|
|
|
|
$list.append( pluginLinkBySlug[ slug ] );
|
2018-05-02 20:58:56 +00:00
|
|
|
}
|
2018-08-29 22:47:46 +00:00
|
|
|
|
|
|
|
if (
|
|
|
|
extraPlugins &&
|
|
|
|
wc_setup_params.current_step &&
|
|
|
|
wc_setup_params.i18n.extra_plugins[ wc_setup_params.current_step ] &&
|
|
|
|
wc_setup_params.i18n.extra_plugins[ wc_setup_params.current_step ][ extraPlugins.join( ',' ) ]
|
|
|
|
) {
|
|
|
|
$list.append(
|
|
|
|
wc_setup_params.i18n.extra_plugins[ wc_setup_params.current_step ][ extraPlugins.join( ',' ) ]
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2018-05-03 10:03:25 +00:00
|
|
|
$( 'span.plugin-install-info' ).toggle( $list.children().length > 0 );
|
2018-05-03 09:18:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
updatePluginInfo();
|
|
|
|
$( '.wc-setup-content' ).on( 'change', '[data-plugins]', updatePluginInfo );
|
2018-08-30 18:17:35 +00:00
|
|
|
|
|
|
|
$( document.body ).on( 'init_tooltips', function() {
|
|
|
|
$( '.help_tip' ).tipTip( {
|
|
|
|
'attribute': 'data-tip',
|
|
|
|
'fadeIn': 50,
|
|
|
|
'fadeOut': 50,
|
|
|
|
'delay': 200,
|
|
|
|
'defaultPosition': 'top'
|
|
|
|
} );
|
|
|
|
} ).trigger( 'init_tooltips' );
|
2016-04-01 10:19:55 +00:00
|
|
|
} );
|