diff --git a/assets/js/admin/woocommerce_admin.js b/assets/js/admin/woocommerce_admin.js index ffff9a96e16..85760039a5f 100644 --- a/assets/js/admin/woocommerce_admin.js +++ b/assets/js/admin/woocommerce_admin.js @@ -31,8 +31,8 @@ jQuery( function ( $ ) { }); $('body').on('keyup change', '.wc_input_decimal[type=text]', function(){ - var value = $(this).val(); - var regex = new RegExp( "[^\-0-9\%.\\" + woocommerce_admin.decimal_point + "]+", "gi" ); + var value = $(this).val(); + var regex = new RegExp( "[^\-0-9\%.\\" + woocommerce_admin.decimal_point + "]+", "gi" ); var newvalue = value.replace( regex, '' ); if ( value !== newvalue ) { @@ -49,18 +49,19 @@ jQuery( function ( $ ) { return this; }); - $('body').on('keyup change', '#_sale_price.wc_input_price[type=text], .wc_input_price[name^=variable_sale_price]', function(){ - var sale_price_field = $(this); - var sale_price = parseInt( sale_price_field.val() ); + $('body').on( 'keyup', '#_sale_price.wc_input_price[type=text], .wc_input_price[name^=variable_sale_price]', function(){ + var sale_price_field = $(this); if( sale_price_field.attr('name').indexOf('variable') !== -1 ) { - var regular_price = parseInt(sale_price_field.parents('.variable_pricing').find('.wc_input_price[name^=variable_regular_price]').val()); + var regular_price_field = sale_price_field.parents('.variable_pricing').find('.wc_input_price[name^=variable_regular_price]'); } else { - var regular_price = parseInt($('#_regular_price').val()); + var regular_price_field = $('#_regular_price'); } + var sale_price = parseFloat( accounting.unformat( sale_price_field.val(), woocommerce_admin.mon_decimal_point ) ); + var regular_price = parseFloat( accounting.unformat( regular_price_field.val(), woocommerce_admin.mon_decimal_point ) ); + if( sale_price >= regular_price ) { - $(this).val( regular_price ); if ( $(this).parent().find('.wc_error_tip').size() === 0 ) { var offset = $(this).position(); $(this).after( '
' + woocommerce_admin.i18_sale_less_than_regular_error + '
' ); @@ -69,6 +70,27 @@ jQuery( function ( $ ) { .css('top', offset.top + $(this).height() ) .fadeIn('100'); } + } else { + $('.wc_error_tip').fadeOut('100', function(){ $(this).remove(); } ); + } + return this; + }); + $('body').on( 'change', '#_sale_price.wc_input_price[type=text], .wc_input_price[name^=variable_sale_price]', function(){ + var sale_price_field = $(this); + + if( sale_price_field.attr('name').indexOf('variable') !== -1 ) { + var regular_price_field = sale_price_field.parents('.variable_pricing').find('.wc_input_price[name^=variable_regular_price]'); + } else { + var regular_price_field = $('#_regular_price'); + } + + var sale_price = parseFloat( accounting.unformat( sale_price_field.val(), woocommerce_admin.mon_decimal_point ) ); + var regular_price = parseFloat( accounting.unformat( regular_price_field.val(), woocommerce_admin.mon_decimal_point ) ); + + if( sale_price >= regular_price ) { + sale_price_field.val( regular_price_field.val() ); + } else { + $('.wc_error_tip').fadeOut('100', function(){ $(this).remove(); } ); } return this; }); diff --git a/assets/js/admin/woocommerce_admin.min.js b/assets/js/admin/woocommerce_admin.min.js index 4dc841e11a5..ae1cc7f9ddb 100644 --- a/assets/js/admin/woocommerce_admin.min.js +++ b/assets/js/admin/woocommerce_admin.min.js @@ -1 +1 @@ -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('
'+woocommerce_admin.i18n_mon_decimal_error+"
"),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('
'+woocommerce_admin.i18n_decimal_error+"
"),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","#_sale_price.wc_input_price[type=text], .wc_input_price[name^=variable_sale_price]",function(){var b=a(this),c=parseInt(b.val());if(-1!==b.attr("name").indexOf("variable"))var d=parseInt(b.parents(".variable_pricing").find(".wc_input_price[name^=variable_regular_price]").val());else var d=parseInt(a("#_regular_price").val());if(c>=d&&(a(this).val(d),0===a(this).parent().find(".wc_error_tip").size())){var e=a(this).position();a(this).after('
'+woocommerce_admin.i18_sale_less_than_regular_error+"
"),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_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('
'+woocommerce_admin.i18n_country_iso_error+"
"),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")}); \ No newline at end of file +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('
'+woocommerce_admin.i18n_mon_decimal_error+"
"),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('
'+woocommerce_admin.i18n_decimal_error+"
"),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('
'+woocommerce_admin.i18_sale_less_than_regular_error+"
"),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('
'+woocommerce_admin.i18n_country_iso_error+"
"),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")}); \ No newline at end of file