woocommerce/assets/js/admin/wc-setup.min.js

1 line
6.3 KiB
JavaScript

jQuery(function(r){function t(){r(".wc-setup-content").block({message:null,overlayCSS:{background:"#fff",opacity:.6}})}function i(){r("form.activate-jetpack").trigger("submit")}function s(){wp.ajax.post("setup_wizard_check_jetpack").then(function(e){return e&&e.is_active&&"yes"!==e.is_active?void setTimeout(s,3e3):i()}).fail(function(){i()})}function c(e,i,t){var s,c=i.data("plugins");for(s in Array.isArray(c)?c:[]){var n=c[s].slug;e[n]=e[n]||r('<span class="plugin-install-info-list-item">').append('<a href="https://wordpress.org/plugins/'+n+'/" target="_blank">'+c[s].name+"</a>"),e[n].find("a").on("mouseenter mouseleave",function(e,i){e.toggleClass("plugin-install-source","mouseenter"===i.type)}.bind(null,t?i.closest(t):i))}}function e(){var i={},t=[];r(".wc-wizard-service-enable input:checked").each(function(){c(i,r(this),".wc-wizard-service-item");var e=r(this).closest(".wc-wizard-service-item");e.find("input.payment-checkbox-input:checked").each(function(){t.push(r(this).attr("id")),c(i,r(this),".wc-wizard-service-settings")}),e.find(".wc-wizard-shipping-method-select .method").each(function(){var e=r(this);"live_rates"===e.val()&&c(i,e,".wc-wizard-service-item")})}),r(".recommended-item input:checked").each(function(){c(i,r(this),".recommended-item")});var e,s=r("span.plugin-install-info-list").empty();for(e in i)s.append(i[e]);t&&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][t.join(",")]&&s.append(wc_setup_params.i18n.extra_plugins[wc_setup_params.current_step][t.join(",")]),r("span.plugin-install-info").toggle(0<s.children().length)}r(".button-next").on("click",function(){var e=r(this).parents("form").get(0);return"function"==typeof e.checkValidity&&!e.checkValidity()||t(),!0}),r("form.address-step").on("submit",function(e){var i=r(this);return"function"==typeof i.checkValidity&&!i.checkValidity()||t(),e.preventDefault(),r(".wc-setup-content").unblock(),r(this).WCBackboneModal({template:"wc-modal-tracking-setup"}),r(document.body).on("wc_backbone_modal_response",function(){i.off("submit").trigger("submit")}),r("#wc_tracker_checkbox_dialog").on("change",function(e){e=r(e.target);r("#wc_tracker_checkbox").prop("checked",e.prop("checked"))}),r("#wc_tracker_submit").on("click",function(){i.off("submit").trigger("submit")}),!0}),r("#store_country").on("change",function(){var e,i,t;null!==wc_setup_params.states&&(e=r(this).val(),i=r("#store_state"),r.isEmptyObject(wc_setup_params.states[e])?(r(".store-state-container").hide(),i.empty().val("").trigger("change").prop("required",!1)):(t=wc_setup_params.states[e],i.empty(),r.each(t,function(e){i.append(r('<option value="'+e+'">'+t[e]+"</option>"))}),r(".store-state-container").show(),i.selectWoo().val(wc_base_state).trigger("change").prop("required",!0)),r("#currency_code").val(wc_setup_currencies[e]).trigger("change"))}),r("#store_country").on("change",function(){var e,i;wc_setup_params.postcodes&&(i=r(this).val(),e=r("#store_postcode"),i=wc_setup_params.postcodes[i],r.isEmptyObject(i)||i.required?e.attr("required","true"):e.prop("required",!1))}),r("#store_country").trigger("change"),r(".wc-wizard-services").on("change",".wc-wizard-service-enable input",function(){r(this).is(":checked")?(r(this).closest(".wc-wizard-service-toggle").removeClass("disabled"),r(this).closest(".wc-wizard-service-item").addClass("checked"),r(this).closest(".wc-wizard-service-item").find(".wc-wizard-service-settings").removeClass("hide")):(r(this).closest(".wc-wizard-service-toggle").addClass("disabled"),r(this).closest(".wc-wizard-service-item").removeClass("checked"),r(this).closest(".wc-wizard-service-item").find(".wc-wizard-service-settings").addClass("hide"))}),r(".wc-wizard-services").on("keyup",function(e){var i=e.keyCode||e.which,e=r(document.activeElement);!e.is(".wc-wizard-service-toggle, .wc-wizard-service-enable")||13!==i&&32!==i||e.find(":input").trigger("click")}),r(".wc-wizard-services").on("click",".wc-wizard-service-enable",function(e){r(e.target).is("input")?e.stopPropagation():(e=r(this).find('input[type="checkbox"]')).prop("checked",!e.prop("checked")).trigger("change")}),r(".wc-wizard-services-list-toggle").on("click",function(){var e=r(this).closest(".wc-wizard-services-list-toggle");e.hasClass("closed")?e.removeClass("closed"):e.addClass("closed"),r(this).closest(".wc-wizard-services").find(".wc-wizard-service-item").slideToggle().css("display","flex")}),r(".wc-wizard-services").on("change",".wc-wizard-shipping-method-select .method",function(e){var i=r(this).closest(".wc-wizard-service-description"),t=e.target.value,e=i.find(".shipping-method-descriptions");e.find(".shipping-method-description").addClass("hide"),e.find("."+t).removeClass("hide");e=i.parent().find('input[type="checkbox"]'),i=i.find(".shipping-method-settings");i.find(".shipping-method-setting").addClass("hide").find(".shipping-method-required-field").prop("required",!1),i.find("."+t).removeClass("hide").find(".shipping-method-required-field").prop("required",e.prop("checked"))}).find(".wc-wizard-shipping-method-select .method").trigger("change"),r(".wc-wizard-services").on("change",".wc-wizard-shipping-method-enable",function(){var e=r(this).is(":checked"),i=r(this).closest(".wc-wizard-service-item").find(".wc-wizard-shipping-method-select .method").val();r(this).closest(".wc-wizard-service-item").find("."+i).find(".shipping-method-required-field").prop("required",e)}),r(".activate-jetpack").on("click",".button-primary",function(e){return t(),"no"===wc_setup_params.pending_jetpack_install||(e.preventDefault(),void s())}),r(".activate-new-onboarding").on("click",".button-primary",function(){t()}),r(".wc-wizard-services").on("change","input#stripe_create_account, input#ppec_paypal_reroute_requests",function(){r(this).is(":checked")?r(this).closest(".wc-wizard-service-settings").find("input.payment-email-input").attr("type","email").prop("disabled",!1).prop("required",!0):r(this).closest(".wc-wizard-service-settings").find("input.payment-email-input").attr("type",null).prop("disabled",!0).prop("required",!1)}).find("input#stripe_create_account, input#ppec_paypal_reroute_requests").trigger("change"),e(),r(".wc-setup-content").on("change","[data-plugins]",e),r(document.body).on("init_tooltips",function(){r(".help_tip").tipTip({attribute:"data-tip",fadeIn:50,fadeOut:50,delay:200,defaultPosition:"top"})}).trigger("init_tooltips")});