woocommerce/assets/js/admin/woocommerce_admin.min.js

1 line
7.9 KiB
JavaScript

jQuery(function(e){if("undefined"!=typeof woocommerce_admin){var t=e(".edit-php.post-type-product"),o=t.find(".page-title-action:first");0===t.find(".woocommerce-BlankState").length?(woocommerce_admin.urls.export_products&&o.after('<a href="'+woocommerce_admin.urls.export_products+'" class="page-title-action">'+woocommerce_admin.strings.export_products+"</a>"),woocommerce_admin.urls.import_products&&o.after('<a href="'+woocommerce_admin.urls.import_products+'" class="page-title-action">'+woocommerce_admin.strings.import_products+"</a>")):o.hide(),e(".woocommerce-progress-form-wrapper .button-next").on("click",function(){return e(".wc-progress-form-content").block({message:null,overlayCSS:{background:"#fff",opacity:.6}}),!0}),e(document.body).on("wc_add_error_tip",function(t,o,i){var n=o.position();0===o.parent().find(".wc_error_tip").length&&(o.after('<div class="wc_error_tip '+i+'">'+woocommerce_admin[i]+"</div>"),o.parent().find(".wc_error_tip").css("left",n.left+o.width()-o.width()/2-e(".wc_error_tip").width()/2).css("top",n.top+o.height()).fadeIn("100"))}).on("wc_remove_error_tip",function(t,o,i){o.parent().find(".wc_error_tip."+i).fadeOut("100",function(){e(this).remove()})}).on("click",function(){e(".wc_error_tip").fadeOut("100",function(){e(this).remove()})}).on("blur",".wc_input_decimal[type=text], .wc_input_price[type=text], .wc_input_country_iso[type=text]",function(){e(".wc_error_tip").fadeOut("100",function(){e(this).remove()})}).on("change",".wc_input_price[type=text], .wc_input_decimal[type=text], .wc-order-totals #refund_amount[type=text]",function(){var t;t=e(this).is(".wc_input_price")||e(this).is("#refund_amount")?new RegExp("[^-0-9%\\"+woocommerce_admin.mon_decimal_point+"]+","gi"):new RegExp("[^-0-9%\\"+woocommerce_admin.decimal_point+"]+","gi");var o=e(this).val(),i=o.replace(t,"");o!==i&&e(this).val(i)}).on("keyup",".wc_input_price[type=text], .wc_input_decimal[type=text], .wc_input_country_iso[type=text], .wc-order-totals #refund_amount[type=text]",function(){var t,o;e(this).is(".wc_input_price")||e(this).is("#refund_amount")?(t=new RegExp("[^-0-9%\\"+woocommerce_admin.mon_decimal_point+"]+","gi"),o="i18n_mon_decimal_error"):e(this).is(".wc_input_country_iso")?(t=new RegExp("([^A-Z])+|(.){3,}","im"),o="i18n_country_iso_error"):(t=new RegExp("[^-0-9%\\"+woocommerce_admin.decimal_point+"]+","gi"),o="i18n_decimal_error");var i=e(this).val();i!==i.replace(t,"")?e(document.body).triggerHandler("wc_add_error_tip",[e(this),o]):e(document.body).triggerHandler("wc_remove_error_tip",[e(this),o])}).on("change","#_sale_price.wc_input_price[type=text], .wc_input_price[name^=variable_sale_price]",function(){var t,o=e(this);t=-1!==o.attr("name").indexOf("variable")?o.parents(".variable_pricing").find(".wc_input_price[name^=variable_regular_price]"):e("#_regular_price"),parseFloat(window.accounting.unformat(o.val(),woocommerce_admin.mon_decimal_point))>=parseFloat(window.accounting.unformat(t.val(),woocommerce_admin.mon_decimal_point))&&e(this).val("")}).on("keyup","#_sale_price.wc_input_price[type=text], .wc_input_price[name^=variable_sale_price]",function(){var t,o=e(this);t=-1!==o.attr("name").indexOf("variable")?o.parents(".variable_pricing").find(".wc_input_price[name^=variable_regular_price]"):e("#_regular_price"),parseFloat(window.accounting.unformat(o.val(),woocommerce_admin.mon_decimal_point))>=parseFloat(window.accounting.unformat(t.val(),woocommerce_admin.mon_decimal_point))?e(document.body).triggerHandler("wc_add_error_tip",[e(this),"i18_sale_less_than_regular_error"]):e(document.body).triggerHandler("wc_remove_error_tip",[e(this),"i18_sale_less_than_regular_error"])}).on("init_tooltips",function(){e(".tips, .help_tip, .woocommerce-help-tip").tipTip({attribute:"data-tip",fadeIn:50,fadeOut:50,delay:200}),e(".column-wc_actions .wc-action-button").tipTip({fadeIn:50,fadeOut:50,delay:200}),e(".parent-tips").each(function(){e(this).closest("a, th").attr("data-tip",e(this).data("tip")).tipTip({attribute:"data-tip",fadeIn:50,fadeOut:50,delay:200}).css("cursor","help")})}),e(document.body).trigger("init_tooltips"),e(".wc_input_table.sortable tbody").sortable({items:"tr",cursor:"move",axis:"y",scrollSensitivity:40,forcePlaceholderSize:!0,helper:"clone",opacity:.65,placeholder:"wc-metabox-sortable-placeholder",start:function(e,t){t.item.css("background-color","#f6f6f6")},stop:function(e,t){t.item.removeAttr("style")}}),e(".wc_input_table.sortable tbody input").on("click",function(){e(this).focus()}),e(".wc_input_table .remove_rows").click(function(){var t=e(this).closest(".wc_input_table").find("tbody");return t.find("tr.current").length>0&&t.find("tr.current").each(function(){e(this).remove()}),!1});var i=!1,n=!1,c=!1;e(document.body).bind("keyup keydown",function(e){n=e.shiftKey,i=e.ctrlKey||e.metaKey}),e(".wc_input_table").on("focus click","input",function(t){var o=e(this).closest("table, tbody"),r=e(this).closest("tr");("focus"===t.type&&c!==r.index()||"click"===t.type&&e(this).is(":focus"))&&(c=r.index(),n||i?n?(e("tr",o).removeClass("current"),r.addClass("selected_now").addClass("current"),e("tr.last_selected",o).length>0&&(r.index()>e("tr.last_selected",o).index()?e("tr",o).slice(e("tr.last_selected",o).index(),r.index()).addClass("current"):e("tr",o).slice(r.index(),e("tr.last_selected",o).index()+1).addClass("current")),e("tr",o).removeClass("last_selected"),r.addClass("last_selected")):(e("tr",o).removeClass("last_selected"),i&&e(this).closest("tr").is(".current")?r.removeClass("current"):r.addClass("current").addClass("last_selected")):(e("tr",o).removeClass("current").removeClass("last_selected"),r.addClass("current").addClass("last_selected")),e("tr",o).removeClass("selected_now"))}).on("blur","input",function(){c=!1}),e(".woocommerce_page_wc-settings .shippingrows tbody tr:even, table.attributes-table tbody tr:nth-child(odd)").addClass("alternate"),e(document.body).on("click",".show_order_items",function(){return e(this).closest("td").find("table").toggle(),!1}),e("select.availability").change(function(){"all"===e(this).val()?e(this).closest("tr").next("tr").hide():e(this).closest("tr").next("tr").show()}).change(),e(".hide_options_if_checked").each(function(){e(this).find("input:eq(0)").change(function(){e(this).is(":checked")?e(this).closest("fieldset, tr").nextUntil(".hide_options_if_checked, .show_options_if_checked",".hidden_option").hide():e(this).closest("fieldset, tr").nextUntil(".hide_options_if_checked, .show_options_if_checked",".hidden_option").show()}).change()}),e(".show_options_if_checked").each(function(){e(this).find("input:eq(0)").change(function(){e(this).is(":checked")?e(this).closest("fieldset, tr").nextUntil(".hide_options_if_checked, .show_options_if_checked",".hidden_option").show():e(this).closest("fieldset, tr").nextUntil(".hide_options_if_checked, .show_options_if_checked",".hidden_option").hide()}).change()}),e("input#woocommerce_enable_reviews").change(function(){e(this).is(":checked")?e("#woocommerce_enable_review_rating").closest("tr").show():e("#woocommerce_enable_review_rating").closest("tr").hide()}).change(),e("table.attributes-table tbody tr:nth-child(odd)").addClass("alternate"),e(".wc_gateways").on("click",".wc-payment-gateway-method-toggle-enabled",function(){var t=e(this),o=t.closest("tr"),i=t.find(".woocommerce-input-toggle"),n={action:"woocommerce_toggle_gateway_enabled",security:woocommerce_admin.nonces.gateway_toggle,gateway_id:o.data("gateway_id")};return i.addClass("woocommerce-input-toggle--loading"),e.ajax({url:woocommerce_admin.ajax_url,data:n,dataType:"json",type:"POST",success:function(e){!0===e.data?(i.removeClass("woocommerce-input-toggle--enabled, woocommerce-input-toggle--disabled"),i.addClass("woocommerce-input-toggle--enabled"),i.removeClass("woocommerce-input-toggle--loading")):!1===e.data?(i.removeClass("woocommerce-input-toggle--enabled, woocommerce-input-toggle--disabled"),i.addClass("woocommerce-input-toggle--disabled"),i.removeClass("woocommerce-input-toggle--loading")):"needs_setup"===e.data&&(window.location.href=t.attr("href"))}}),!1})}});