1 line
12 KiB
JavaScript
1 line
12 KiB
JavaScript
jQuery(function(t){function e(){var e=t("select#product-type").val(),i=t("input#_virtual:checked").length,o=t("input#_downloadable:checked").length,a=".hide_if_downloadable, .hide_if_virtual",c=".show_if_downloadable, .show_if_virtual";t.each(woocommerce_admin_meta_boxes.product_types,function(t,e){a=a+", .hide_if_"+e,c=c+", .show_if_"+e}),t(a).show(),t(c).hide(),o&&t(".show_if_downloadable").show(),i&&t(".show_if_virtual").show(),t(".show_if_"+e).show(),o&&t(".hide_if_downloadable").hide(),i&&t(".hide_if_virtual").hide(),t(".hide_if_"+e).hide(),t("input#_manage_stock").change(),t(".woocommerce_options_panel").each(function(){var e=t(this).children(".options_group");if(0!==e.length&&e.filter(function(){return"none"===t(this).css("display")}).length===e.length){var i=t(this).prop("id");t(".product_data_tabs").find('li a[href="#'+i+'"]').parent().hide()}})}function i(e){var i=t(e).next().is(".hasDatepicker")?"minDate":"maxDate",o="minDate"===i?t(e).next():t(e).prev(),a=t(e).datepicker("getDate");t(o).datepicker("option",i,a),t(e).change()}function o(){t(".product_attributes .woocommerce_attribute").each(function(e,i){t(".attribute_position",i).val(parseInt(t(i).index(".product_attributes .woocommerce_attribute"),10))})}t(function(){t('[id$="-all"] > ul.categorychecklist').each(function(){var e=t(this),i=e.find(":checked").first();if(i.length){var o=e.find("input").position().top,a=i.position().top;e.closest(".tabs-panel").scrollTop(a-o+5)}})}),t("#upsell_product_data").bind("keypress",function(t){if(13===t.keyCode)return!1}),t(".type_box").appendTo("#woocommerce-product-data .hndle span"),t(function(){t("#woocommerce-product-data").find(".hndle").unbind("click.postboxes"),t("#woocommerce-product-data").on("click",".hndle",function(e){t(e.target).filter("input, option, label, select").length||t("#woocommerce-product-data").toggleClass("closed")})}),t("#catalog-visibility").find(".edit-catalog-visibility").click(function(){return t("#catalog-visibility-select").is(":hidden")&&(t("#catalog-visibility-select").slideDown("fast"),t(this).hide()),!1}),t("#catalog-visibility").find(".save-post-visibility").click(function(){t("#catalog-visibility-select").slideUp("fast"),t("#catalog-visibility").find(".edit-catalog-visibility").show();var e=t("input[name=_visibility]:checked").attr("data-label");return t("input[name=_featured]").is(":checked")&&(e=e+", "+woocommerce_admin_meta_boxes.featured_label,t("input[name=_featured]").attr("checked","checked")),t("#catalog-visibility-display").text(e),!1}),t("#catalog-visibility").find(".cancel-post-visibility").click(function(){t("#catalog-visibility-select").slideUp("fast"),t("#catalog-visibility").find(".edit-catalog-visibility").show();var e=t("#current_visibility").val(),i=t("#current_featured").val();t("input[name=_visibility]").removeAttr("checked"),t("input[name=_visibility][value="+e+"]").attr("checked","checked");var o=t("input[name=_visibility]:checked").attr("data-label");return"yes"===i?(o=o+", "+woocommerce_admin_meta_boxes.featured_label,t("input[name=_featured]").attr("checked","checked")):t("input[name=_featured]").removeAttr("checked"),t("#catalog-visibility-display").text(o),!1}),t("select#product-type").change(function(){var i=t(this).val();"variable"===i?(t("input#_manage_stock").change(),t("input#_downloadable").prop("checked",!1),t("input#_virtual").removeAttr("checked")):"grouped"===i?(t("input#_downloadable").prop("checked",!1),t("input#_virtual").removeAttr("checked")):"external"===i&&(t("input#_downloadable").prop("checked",!1),t("input#_virtual").removeAttr("checked")),e(),t("ul.wc-tabs li:visible").eq(0).find("a").click(),t(document.body).trigger("woocommerce-product-type-change",i,t(this))}).change(),t("input#_downloadable, input#_virtual").change(function(){e()}),t(".sale_price_dates_fields").each(function(){var e=t(this),i=!1,o=e.closest("div, table");e.find("input").each(function(){""!==t(this).val()&&(i=!0)}),i?(o.find(".sale_schedule").hide(),o.find(".sale_price_dates_fields").show()):(o.find(".sale_schedule").show(),o.find(".sale_price_dates_fields").hide())}),t("#woocommerce-product-data").on("click",".sale_schedule",function(){var e=t(this).closest("div, table");return t(this).hide(),e.find(".cancel_sale_schedule").show(),e.find(".sale_price_dates_fields").show(),!1}),t("#woocommerce-product-data").on("click",".cancel_sale_schedule",function(){var e=t(this).closest("div, table");return t(this).hide(),e.find(".sale_schedule").show(),e.find(".sale_price_dates_fields").hide(),e.find(".sale_price_dates_fields").find("input").val(""),!1}),t("#woocommerce-product-data").on("click",".downloadable_files a.insert",function(){return t(this).closest(".downloadable_files").find("tbody").append(t(this).data("row")),!1}),t("#woocommerce-product-data").on("click",".downloadable_files a.delete",function(){return t(this).closest("tr").remove(),!1}),t("input#_manage_stock").change(function(){if(t(this).is(":checked"))t("div.stock_fields").show(),t("p.stock_status_field").hide();else{var e=t("select#product-type").val();t("div.stock_fields").hide(),t("p.stock_status_field:not( .hide_if_"+e+" )").show()}}).change(),t(".sale_price_dates_fields").each(function(){t(this).find("input").datepicker({defaultDate:"",dateFormat:"yy-mm-dd",numberOfMonths:1,showButtonPanel:!0,onSelect:function(){i(t(this))}}),t(this).find("input").each(function(){i(t(this))})});var a=t(".product_attributes").find(".woocommerce_attribute").get();a.sort(function(e,i){var o=parseInt(t(e).attr("rel"),10),a=parseInt(t(i).attr("rel"),10);return o<a?-1:o>a?1:0}),t(a).each(function(e,i){t(".product_attributes").append(i)}),t(".product_attributes .woocommerce_attribute").each(function(e,i){"none"!==t(i).css("display")&&t(i).is(".taxonomy")&&t("select.attribute_taxonomy").find('option[value="'+t(i).data("taxonomy")+'"]').attr("disabled","disabled")}),t("button.add_attribute").on("click",function(){var e=t(".product_attributes .woocommerce_attribute").length,i=t("select.attribute_taxonomy").val(),a=t(this).closest("#product_attributes"),c=a.find(".product_attributes"),n=t("select#product-type").val(),r={action:"woocommerce_add_attribute",taxonomy:i,i:e,security:woocommerce_admin_meta_boxes.add_attribute_nonce};return a.block({message:null,overlayCSS:{background:"#fff",opacity:.6}}),t.post(woocommerce_admin_meta_boxes.ajax_url,r,function(e){c.append(e),"variable"!==n&&c.find(".enable_variation").hide(),t(document.body).trigger("wc-enhanced-select-init"),o(),a.unblock(),t(document.body).trigger("woocommerce_added_attribute")}),i&&(t("select.attribute_taxonomy").find('option[value="'+i+'"]').attr("disabled","disabled"),t("select.attribute_taxonomy").val("")),!1}),t(".product_attributes").on("blur","input.attribute_name",function(){t(this).closest(".woocommerce_attribute").find("strong.attribute_name").text(t(this).val())}),t(".product_attributes").on("click","button.select_all_attributes",function(){return t(this).closest("td").find("select option").attr("selected","selected"),t(this).closest("td").find("select").change(),!1}),t(".product_attributes").on("click","button.select_no_attributes",function(){return t(this).closest("td").find("select option").removeAttr("selected"),t(this).closest("td").find("select").change(),!1}),t(".product_attributes").on("click",".remove_row",function(){if(window.confirm(woocommerce_admin_meta_boxes.remove_attribute)){var e=t(this).parent().parent();e.is(".taxonomy")?(e.find("select, input[type=text]").val(""),e.hide(),t("select.attribute_taxonomy").find('option[value="'+e.data("taxonomy")+'"]').removeAttr("disabled")):(e.find("select, input[type=text]").val(""),e.hide(),o())}return!1}),t(".product_attributes").sortable({items:".woocommerce_attribute",cursor:"move",axis:"y",handle:"h3",scrollSensitivity:40,forcePlaceholderSize:!0,helper:"clone",opacity:.65,placeholder:"wc-metabox-sortable-placeholder",start:function(t,e){e.item.css("background-color","#f6f6f6")},stop:function(t,e){e.item.removeAttr("style"),o()}}),t(".product_attributes").on("click","button.add_new_attribute",function(){t(".product_attributes").block({message:null,overlayCSS:{background:"#fff",opacity:.6}});var e=t(this).closest(".woocommerce_attribute"),i=e.data("taxonomy"),o=window.prompt(woocommerce_admin_meta_boxes.new_attribute_prompt);if(o){var a={action:"woocommerce_add_new_attribute",taxonomy:i,term:o,security:woocommerce_admin_meta_boxes.add_attribute_nonce};t.post(woocommerce_admin_meta_boxes.ajax_url,a,function(i){i.error?window.alert(i.error):i.slug&&(e.find("select.attribute_values").append('<option value="'+i.term_id+'" selected="selected">'+i.name+"</option>"),e.find("select.attribute_values").change()),t(".product_attributes").unblock()})}else t(".product_attributes").unblock();return!1}),t(".save_attributes").on("click",function(){t("#woocommerce-product-data").block({message:null,overlayCSS:{background:"#fff",opacity:.6}});var e={post_id:woocommerce_admin_meta_boxes.post_id,product_type:t("#product-type").val(),data:t(".product_attributes").find("input, select, textarea").serialize(),action:"woocommerce_save_attributes",security:woocommerce_admin_meta_boxes.save_attributes_nonce};t.post(woocommerce_admin_meta_boxes.ajax_url,e,function(){var e=window.location.toString();e=e.replace("post-new.php?","post.php?post="+woocommerce_admin_meta_boxes.post_id+"&action=edit&"),t("#variable_product_options").load(e+" #variable_product_options_inner",function(){t("#variable_product_options").trigger("reload")})})});var c,n;t(document.body).on("click",".upload_file_button",function(e){var i=t(this);if(n=i.closest("tr").find("td.file_url input"),e.preventDefault(),c)c.open();else{var o=[new wp.media.controller.Library({library:wp.media.query(),multiple:!0,title:i.data("choose"),priority:20,filterable:"uploaded"})];(c=wp.media.frames.downloadable_file=wp.media({title:i.data("choose"),library:{type:""},button:{text:i.data("update")},multiple:!0,states:o})).on("select",function(){var t="";c.state().get("selection").map(function(e){(e=e.toJSON()).url&&(t=e.url)}),n.val(t).change()}),c.on("ready",function(){c.uploader.options.uploader.params={type:"downloadable_product"}}),c.open()}}),t(".downloadable_files tbody").sortable({items:"tr",cursor:"move",axis:"y",handle:"td.sort",scrollSensitivity:40,forcePlaceholderSize:!0,helper:"clone",opacity:.65});var r,l=t("#product_image_gallery"),s=t("#product_images_container").find("ul.product_images");t(".add_product_images").on("click","a",function(e){var i=t(this);e.preventDefault(),r?r.open():((r=wp.media.frames.product_gallery=wp.media({title:i.data("choose"),button:{text:i.data("update")},states:[new wp.media.controller.Library({title:i.data("choose"),filterable:"all",multiple:!0})]})).on("select",function(){var t=r.state().get("selection"),e=l.val();t.map(function(t){if((t=t.toJSON()).id){e=e?e+","+t.id:t.id;var o=t.sizes&&t.sizes.thumbnail?t.sizes.thumbnail.url:t.url;s.append('<li class="image" data-attachment_id="'+t.id+'"><img src="'+o+'" /><ul class="actions"><li><a href="#" class="delete" title="'+i.data("delete")+'">'+i.data("text")+"</a></li></ul></li>")}}),l.val(e)}),r.open())}),s.sortable({items:"li.image",cursor:"move",scrollSensitivity:40,forcePlaceholderSize:!0,forceHelperSize:!1,helper:"clone",opacity:.65,placeholder:"wc-metabox-sortable-placeholder",start:function(t,e){e.item.css("background-color","#f6f6f6")},stop:function(t,e){e.item.removeAttr("style")},update:function(){var e="";t("#product_images_container").find("ul li.image").css("cursor","default").each(function(){var i=t(this).attr("data-attachment_id");e=e+i+","}),l.val(e)}}),t("#product_images_container").on("click","a.delete",function(){t(this).closest("li.image").remove();var e="";return t("#product_images_container").find("ul li.image").css("cursor","default").each(function(){var i=t(this).attr("data-attachment_id");e=e+i+","}),l.val(e),t("#tiptip_holder").removeAttr("style"),t("#tiptip_arrow").removeAttr("style"),!1})}); |