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

1 line
6.3 KiB
JavaScript

jQuery(function(a){a(document.body).on("wc_add_error_tip",function(b,c,d){var e=c.position();0===c.parent().find(".wc_error_tip").length&&(c.after('<div class="wc_error_tip '+d+'">'+woocommerce_admin[d]+"</div>"),c.parent().find(".wc_error_tip").css("left",e.left+c.width()-c.width()/2-a(".wc_error_tip").width()/2).css("top",e.top+c.height()).fadeIn("100"))}).on("wc_remove_error_tip",function(b,c,d){c.parent().find(".wc_error_tip."+d).fadeOut("100",function(){a(this).remove()})}).on("click",function(){a(".wc_error_tip").fadeOut("100",function(){a(this).remove()})}).on("blur",".wc_input_decimal[type=text], .wc_input_price[type=text], .wc_input_country_iso[type=text]",function(){a(".wc_error_tip").fadeOut("100",function(){a(this).remove()})}).on("change",".wc_input_price[type=text], .wc_input_decimal[type=text], .wc-order-totals #refund_amount[type=text]",function(){var b;b=a(this).is(".wc_input_price")||a(this).is("#refund_amount")?new RegExp("[^-0-9%\\"+woocommerce_admin.mon_decimal_point+"]+","gi"):new RegExp("[^-0-9%\\"+woocommerce_admin.decimal_point+"]+","gi");var c=a(this).val(),d=c.replace(b,"");c!==d&&a(this).val(d)}).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 b,c;a(this).is(".wc_input_price")||a(this).is("#refund_amount")?(b=new RegExp("[^-0-9%\\"+woocommerce_admin.mon_decimal_point+"]+","gi"),c="i18n_mon_decimal_error"):a(this).is(".wc_input_country_iso")?(b=new RegExp("([^A-Z])+|(.){3,}","im"),c="i18n_country_iso_error"):(b=new RegExp("[^-0-9%\\"+woocommerce_admin.decimal_point+"]+","gi"),c="i18n_decimal_error");var d=a(this).val(),e=d.replace(b,"");d!==e?a(document.body).triggerHandler("wc_add_error_tip",[a(this),c]):a(document.body).triggerHandler("wc_remove_error_tip",[a(this),c])}).on("change","#_sale_price.wc_input_price[type=text], .wc_input_price[name^=variable_sale_price]",function(){var b,c=a(this);b=c.attr("name").indexOf("variable")!==-1?c.parents(".variable_pricing").find(".wc_input_price[name^=variable_regular_price]"):a("#_regular_price");var d=parseFloat(window.accounting.unformat(c.val(),woocommerce_admin.mon_decimal_point)),e=parseFloat(window.accounting.unformat(b.val(),woocommerce_admin.mon_decimal_point));d>=e&&a(this).val("")}).on("keyup","#_sale_price.wc_input_price[type=text], .wc_input_price[name^=variable_sale_price]",function(){var b,c=a(this);b=c.attr("name").indexOf("variable")!==-1?c.parents(".variable_pricing").find(".wc_input_price[name^=variable_regular_price]"):a("#_regular_price");var d=parseFloat(window.accounting.unformat(c.val(),woocommerce_admin.mon_decimal_point)),e=parseFloat(window.accounting.unformat(b.val(),woocommerce_admin.mon_decimal_point));d>=e?a(document.body).triggerHandler("wc_add_error_tip",[a(this),"i18_sale_less_than_regular_error"]):a(document.body).triggerHandler("wc_remove_error_tip",[a(this),"i18_sale_less_than_regular_error"])}).on("init_tooltips",function(){var b={attribute:"data-tip",fadeIn:50,fadeOut:50,delay:200};a(".tips, .help_tip, .woocommerce-help-tip").tipTip(b),a(".parent-tips").each(function(){a(this).closest("a, th").attr("data-tip",a(this).data("tip")).tipTip(b).css("cursor","help")})}),a(document.body).trigger("init_tooltips"),a(".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(a,b){b.item.css("background-color","#f6f6f6")},stop:function(a,b){b.item.removeAttr("style")}}),a(".wc_input_table .remove_rows").click(function(){var b=a(this).closest(".wc_input_table").find("tbody");if(b.find("tr.current").length>0){var c=b.find("tr.current");c.each(function(){a(this).remove()})}return!1});var b=!1,c=!1,d=!1;a(document.body).bind("keyup keydown",function(a){c=a.shiftKey,b=a.ctrlKey||a.metaKey}),a(".wc_input_table").on("focus click","input",function(e){var f=a(this).closest("table, tbody"),g=a(this).closest("tr");("focus"===e.type&&d!==g.index()||"click"===e.type&&a(this).is(":focus"))&&(d=g.index(),c||b?c?(a("tr",f).removeClass("current"),g.addClass("selected_now").addClass("current"),a("tr.last_selected",f).length>0&&(g.index()>a("tr.last_selected",f).index()?a("tr",f).slice(a("tr.last_selected",f).index(),g.index()).addClass("current"):a("tr",f).slice(g.index(),a("tr.last_selected",f).index()+1).addClass("current")),a("tr",f).removeClass("last_selected"),g.addClass("last_selected")):(a("tr",f).removeClass("last_selected"),b&&a(this).closest("tr").is(".current")?g.removeClass("current"):g.addClass("current").addClass("last_selected")):(a("tr",f).removeClass("current").removeClass("last_selected"),g.addClass("current").addClass("last_selected")),a("tr",f).removeClass("selected_now"))}).on("blur","input",function(){d=!1}),a(".woocommerce_page_wc-settings .shippingrows tbody tr:even, table.attributes-table tbody tr:nth-child(odd)").addClass("alternate"),a(document.body).on("click",".show_order_items",function(){return a(this).closest("td").find("table").toggle(),!1}),a("select.availability").change(function(){"all"===a(this).val()?a(this).closest("tr").next("tr").hide():a(this).closest("tr").next("tr").show()}).change(),a(".hide_options_if_checked").each(function(){a(this).find("input:eq(0)").change(function(){a(this).is(":checked")?a(this).closest("fieldset, tr").nextUntil(".hide_options_if_checked, .show_options_if_checked",".hidden_option").hide():a(this).closest("fieldset, tr").nextUntil(".hide_options_if_checked, .show_options_if_checked",".hidden_option").show()}).change()}),a(".show_options_if_checked").each(function(){a(this).find("input:eq(0)").change(function(){a(this).is(":checked")?a(this).closest("fieldset, tr").nextUntil(".hide_options_if_checked, .show_options_if_checked",".hidden_option").show():a(this).closest("fieldset, tr").nextUntil(".hide_options_if_checked, .show_options_if_checked",".hidden_option").hide()}).change()}),a("input#woocommerce_demo_store").change(function(){a(this).is(":checked")?a("#woocommerce_demo_store_notice").closest("tr").show():a("#woocommerce_demo_store_notice").closest("tr").hide()}).change(),a("table.attributes-table tbody tr:nth-child(odd)").addClass("alternate"),a("#contextual-help-link").on("click",function(){var b=a("#tab-panel-woocommerce_101_tab iframe");b.attr("src",b.data("src"))})});