1 line
6.5 KiB
JavaScript
1 line
6.5 KiB
JavaScript
jQuery(function(a){a("body").on("blur",".wc_input_decimal[type=text], .wc_input_price[type=text], .wc_input_country_iso[type=text]",function(){return a(".wc_error_tip").fadeOut("100",function(){a(this).remove()}),this}),a("body").on("keyup change",".wc_input_price[type=text]",function(){var b=a(this).val(),c=new RegExp("[^-0-9%.\\"+woocommerce_admin.mon_decimal_point+"]+","gi"),d=b.replace(c,"");if(b!==d&&(a(this).val(d),0==a(this).parent().find(".wc_error_tip").size())){var e=a(this).position();a(this).after('<div class="wc_error_tip">'+woocommerce_admin.i18n_mon_decimal_error+"</div>"),a(".wc_error_tip").css("left",e.left+a(this).width()-a(this).width()/2-a(".wc_error_tip").width()/2).css("top",e.top+a(this).height()).fadeIn("100")}return this}),a("body").on("keyup change",".wc_input_decimal[type=text]",function(){var b=a(this).val(),c=new RegExp("[^-0-9%.\\"+woocommerce_admin.decimal_point+"]+","gi"),d=b.replace(c,"");if(b!==d&&(a(this).val(d),0===a(this).parent().find(".wc_error_tip").size())){var e=a(this).position();a(this).after('<div class="wc_error_tip">'+woocommerce_admin.i18n_decimal_error+"</div>"),a(".wc_error_tip").css("left",e.left+a(this).width()-a(this).width()/2-a(".wc_error_tip").width()/2).css("top",e.top+a(this).height()).fadeIn("100")}return this}),a("body").on("keyup","#_sale_price.wc_input_price[type=text], .wc_input_price[name^=variable_sale_price]",function(){var b=a(this);if(-1!==b.attr("name").indexOf("variable"))var c=b.parents(".variable_pricing").find(".wc_input_price[name^=variable_regular_price]");else var c=a("#_regular_price");var d=parseFloat(accounting.unformat(b.val(),woocommerce_admin.mon_decimal_point)),e=parseFloat(accounting.unformat(c.val(),woocommerce_admin.mon_decimal_point));if(d>=e){if(0===a(this).parent().find(".wc_error_tip").size()){var f=a(this).position();a(this).after('<div class="wc_error_tip">'+woocommerce_admin.i18_sale_less_than_regular_error+"</div>"),a(".wc_error_tip").css("left",f.left+a(this).width()-a(this).width()/2-a(".wc_error_tip").width()/2).css("top",f.top+a(this).height()).fadeIn("100")}}else a(".wc_error_tip").fadeOut("100",function(){a(this).remove()});return this}),a("body").on("change","#_sale_price.wc_input_price[type=text], .wc_input_price[name^=variable_sale_price]",function(){var b=a(this);if(-1!==b.attr("name").indexOf("variable"))var c=b.parents(".variable_pricing").find(".wc_input_price[name^=variable_regular_price]");else var c=a("#_regular_price");var d=parseFloat(accounting.unformat(b.val(),woocommerce_admin.mon_decimal_point)),e=parseFloat(accounting.unformat(c.val(),woocommerce_admin.mon_decimal_point));return d>=e?b.val(c.val()):a(".wc_error_tip").fadeOut("100",function(){a(this).remove()}),this}),a("body").on("keyup change",".wc_input_country_iso[type=text]",function(){var b=a(this).val(),c=new RegExp("^([A-Z])?([A-Z])$");if(!c.test(b)&&(a(this).val(""),0===a(this).parent().find(".wc_error_tip").size())){var d=a(this).position();a(this).after('<div class="wc_error_tip">'+woocommerce_admin.i18n_country_iso_error+"</div>"),a(".wc_error_tip").css("left",d.left+a(this).width()-a(this).width()/2-a(".wc_error_tip").width()/2).css("top",d.top+a(this).height()).fadeIn("100")}return this}),a("body").click(function(){a(".wc_error_tip").fadeOut("100",function(){a(this).remove()})});var b={attribute:"data-tip",fadeIn:50,fadeOut:50,delay:200};a(".tips, .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(".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");return b.find("tr.current").size()>0&&($current=b.find("tr.current"),$current.each(function(){a(this).remove()})),!1});var c=!1,d=!1,e=!1;a(document).bind("keyup keydown",function(a){d=a.shiftKey,c=a.ctrlKey||a.metaKey}),a(".wc_input_table").on("focus click","input",function(b){$this_table=a(this).closest("table"),$this_row=a(this).closest("tr"),("focus"==b.type&&e!=$this_row.index()||"click"==b.type&&a(this).is(":focus"))&&(e=$this_row.index(),d||c?d?(a("tr",$this_table).removeClass("current"),$this_row.addClass("selected_now").addClass("current"),a("tr.last_selected",$this_table).size()>0&&($this_row.index()>a("tr.last_selected, $this_table").index()?a("tr",$this_table).slice(a("tr.last_selected",$this_table).index(),$this_row.index()).addClass("current"):a("tr",$this_table).slice($this_row.index(),a("tr.last_selected",$this_table).index()+1).addClass("current")),a("tr",$this_table).removeClass("last_selected"),$this_row.addClass("last_selected")):(a("tr",$this_table).removeClass("last_selected"),c&&a(this).closest("tr").is(".current")?$this_row.removeClass("current"):$this_row.addClass("current").addClass("last_selected")):(a("tr",$this_table).removeClass("current").removeClass("last_selected"),$this_row.addClass("current").addClass("last_selected")),a("tr",$this_table).removeClass("selected_now"))}).on("blur","input",function(){e=!1}),a(".woocommerce_page_wc-settings .shippingrows tbody tr:even").addClass("alternate"),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("body").on("click",".show_order_items",function(){return a(this).closest("td").find("table").toggle(),!1}),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")}); |