관리-도구
편집 파일: meta-boxes-product.min.js
jQuery(function(t){function e(){var e=t("select#product-type").val(),i=t("input#_virtual:checked").length,a=t("input#_downloadable:checked").length,o=".hide_if_downloadable, .hide_if_virtual",r=".show_if_downloadable, .show_if_virtual";t.each(kkart_admin_meta_boxes.product_types,function(t,e){o=o+", .hide_if_"+e,r=r+", .show_if_"+e}),t(o).show(),t(r).hide(),a&&t(".show_if_downloadable").show(),i&&t(".show_if_virtual").show(),t(".show_if_"+e).show(),a&&t(".hide_if_downloadable").hide(),i&&t(".hide_if_virtual").hide(),t(".hide_if_"+e).hide(),t("input#_manage_stock").change(),t(".kkart_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",a="minDate"===i?t(e).next():t(e).prev(),o=t(e).datepicker("getDate");t(a).datepicker("option",i,o),t(e).change()}t(function(){var e=t("#postdivrich");e.prepend('<ul class="product-descriptions"><li class="desc-active" data-desc="prod-description">Description</li><li data-desc="prod-short-description">Short description</li></ul>'),t("#wp-excerpt-wrap").appendTo("#postdivrich");var i=t("#postdivrich .product-descriptions li");i.on("click",function(){var t=jQuery(this);i.removeClass("desc-active"),t.addClass("desc-active"),"prod-short-description"==t.data("desc")?e.addClass("prod-short-description"):e.removeClass("prod-short-description")}),t(".wp-editor-wrap .wp-switch-editor").addClass("button");var a=t("#wp-content-media-buttons").add("#wp-excerpt-media-buttons");a.find(".insert-media").contents().filter(function(){return 3===this.nodeType}).remove(),a.find(".insert-media").removeClass("button");var o=[];a.each(function(t){let e=jQuery(this);o[t]=setInterval(function(){let i=e.closest(".wp-editor-wrap").find(".mce-i-link").closest(".mce-btn");!(i.length<1)&&(clearInterval(o[t]),e.addClass("mce-btn"),e.insertAfter(i))},1e3)})}),t(function(){t('[id$="-all"] > ul.categorychecklist').each(function(){var e=t(this),i=e.find(":checked").first();if(i.length){var a=e.find("input").position().top,o=i.position().top;e.closest(".tabs-panel").scrollTop(o-a+5)}})}),t("#upsell_product_data").bind("keypress",function(t){if(13===t.keyCode)return!1}),t("body").hasClass("kkart-wp-version-gte-55")?t(".type_box").appendTo("#kkart-product-data .hndle"):t(".type_box").appendTo("#kkart-product-data .hndle span"),t(function(){t("#kkart-product-data").find(".hndle").unbind("click.postboxes"),t("#kkart-product-data").on("click",".hndle",function(e){!t(e.target).filter("input, option, label, select").length&&t("#kkart-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+", "+kkart_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 a=t("input[name=_visibility]:checked").attr("data-label");return"yes"===i?(a=a+", "+kkart_admin_meta_boxes.featured_label,t("input[name=_featured]").attr("checked","checked")):t("input[name=_featured]").removeAttr("checked"),t("#catalog-visibility-display").text(a),!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.kkart-tabs li:visible").eq(0).find("a").click(),t(document.body).trigger("kkart-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,a=e.closest("div, table");e.find("input").each(function(){""!==t(this).val()&&(i=!0)}),i?(a.find(".sale_schedule").hide(),a.find(".sale_price_dates_fields").show()):(a.find(".sale_schedule").show(),a.find(".sale_price_dates_fields").hide())}),t("#kkart-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("#kkart-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("#kkart-product-data").on("click",".downloadable_files a.insert",function(){return t(this).closest(".downloadable_files").find("tbody").append(t(this).data("row")),!1}),t("#kkart-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()}t("input.variable_manage_stock").change()}).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,o,r,n=t(".product_attributes").find(".kkart_attribute").get();function c(){t(".product_attributes .kkart_attribute").each(function(e,i){t(".attribute_position",i).val(parseInt(t(i).index(".product_attributes .kkart_attribute"),10))})}n.sort(function(e,i){var a=parseInt(t(e).attr("rel"),10),o=parseInt(t(i).attr("rel"),10);return a<o?-1:a>o?1:0}),t(n).each(function(e,i){t(".product_attributes").append(i)}),t(".product_attributes .kkart_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 .kkart_attribute").length,i=t("select.attribute_taxonomy").val(),a=t(this).closest("#product_attributes"),o=a.find(".product_attributes"),r=t("select#product-type").val(),n={action:"kkart_add_attribute",taxonomy:i,i:e,security:kkart_admin_meta_boxes.add_attribute_nonce};return a.block({message:null,overlayCSS:{background:"#fff",opacity:.6}}),t.post(kkart_admin_meta_boxes.ajax_url,n,function(e){o.append(e),"variable"!==r&&o.find(".enable_variation").hide(),t(document.body).trigger("kkart-enhanced-select-init"),c(),o.find(".kkart_attribute").last().find("h3").click(),a.unblock(),t(document.body).trigger("kkart_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(".kkart_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(kkart_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(),c())}return!1}),t(".product_attributes").sortable({items:".kkart_attribute",cursor:"move",axis:"y",handle:"h3",scrollSensitivity:40,forcePlaceholderSize:!0,helper:"clone",opacity:.65,placeholder:"kkart-metabox-sortable-placeholder",start:function(t,e){e.item.css("background-color","#f6f6f6")},stop:function(t,e){e.item.removeAttr("style"),c()}}),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(".kkart_attribute"),i=e.data("taxonomy"),a=window.prompt(kkart_admin_meta_boxes.new_attribute_prompt);if(a){var o={action:"kkart_add_new_attribute",taxonomy:i,term:a,security:kkart_admin_meta_boxes.add_attribute_nonce};t.post(kkart_admin_meta_boxes.ajax_url,o,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(".product_attributes").block({message:null,overlayCSS:{background:"#fff",opacity:.6}});var i=t(".product_attributes").find("input, select, textarea"),a={post_id:kkart_admin_meta_boxes.post_id,product_type:t("#product-type").val(),data:i.serialize(),action:"kkart_save_attributes",security:kkart_admin_meta_boxes.save_attributes_nonce};t.post(kkart_admin_meta_boxes.ajax_url,a,function(i){if(i.error)window.alert(i.error);else if(i.data){t(".product_attributes").html(i.data.html),t(".product_attributes").unblock(),e(),t("select.attribute_taxonomy").find("option").prop("disabled",!1),t(".product_attributes .kkart_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")+'"]').prop("disabled",!0)});var a=window.location.toString();a=a.replace("post-new.php?","post.php?post="+kkart_admin_meta_boxes.post_id+"&action=edit&"),t("#variable_product_options").load(a+" #variable_product_options_inner",function(){t("#variable_product_options").trigger("reload")})}})}),t(document.body).on("click",".upload_file_button",function(e){var i=t(this);if(o=i.closest("tr").find("td.file_url input"),e.preventDefault(),a){a.open();return}var r=[new wp.media.controller.Library({library:wp.media.query(),multiple:!0,title:i.data("choose"),priority:20,filterable:"uploaded"})];(a=wp.media.frames.downloadable_file=wp.media({title:i.data("choose"),library:{type:""},button:{text:i.data("update")},multiple:!0,states:r})).on("select",function(){var t="";a.state().get("selection").map(function(e){(e=e.toJSON()).url&&(t=e.url)}),o.val(t).change()}),a.on("ready",function(){a.uploader.options.uploader.params={type:"downloadable_product"}}),a.open()}),t(".downloadable_files tbody").sortable({items:"tr",cursor:"move",axis:"y",handle:"td.sort",scrollSensitivity:40,forcePlaceholderSize:!0,helper:"clone",opacity:.65});var 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);if(e.preventDefault(),r){r.open();return}(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 a=t.sizes&&t.sizes.thumbnail?t.sizes.thumbnail.url:t.url;i.closest(".add_product_images").before('<li class="image" data-attachment_id="'+t.id+'"><img src="'+a+'" /><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:"kkart-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(){e=e+t(this).attr("data-attachment_id")+","}),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(){e=e+t(this).attr("data-attachment_id")+","}),l.val(e),t("#tiptip_holder").removeAttr("style"),t("#tiptip_arrow").removeAttr("style"),!1})});