관리-도구
편집 파일: meta-boxes-product-variation.min.js
jQuery(function(c){"use strict";var o={init:function(){c("#variable_product_options").on("change","input.variable_is_downloadable",this.variable_is_downloadable).on("change","input.variable_is_virtual",this.variable_is_virtual).on("change","input.variable_manage_stock",this.variable_manage_stock).on("click","button.notice-dismiss",this.notice_dismiss).on("click","h3 .sort",this.set_menu_order).on("reload",this.reload),c("input.variable_is_downloadable, input.variable_is_virtual, input.variable_manage_stock").change(),c("#kkart-product-data").on("kkart_variations_loaded",this.variations_loaded),c(document.body).on("kkart_variations_added",this.variation_added)},reload:function(){n.load_variations(1),d.set_paginav(0)},variable_is_downloadable:function(){c(this).closest(".kkart_variation").find(".show_if_variation_downloadable").hide(),c(this).is(":checked")&&c(this).closest(".kkart_variation").find(".show_if_variation_downloadable").show()},variable_is_virtual:function(){c(this).closest(".kkart_variation").find(".hide_if_variation_virtual").show(),c(this).is(":checked")&&c(this).closest(".kkart_variation").find(".hide_if_variation_virtual").hide()},variable_manage_stock:function(){c(this).closest(".kkart_variation").find(".show_if_variation_manage_stock").hide(),c(this).closest(".kkart_variation").find(".variable_stock_status").show(),c(this).is(":checked")&&(c(this).closest(".kkart_variation").find(".show_if_variation_manage_stock").show(),c(this).closest(".kkart_variation").find(".variable_stock_status").hide()),c("input#_manage_stock:checked").length&&c(this).closest(".kkart_variation").find(".variable_stock_status").hide()},notice_dismiss:function(){c(this).closest("div.notice").remove()},variations_loaded:function(a,e){e=e||!1;var i=c("#kkart-product-data");e||(c("input.variable_is_downloadable, input.variable_is_virtual, input.variable_manage_stock",i).change(),c(".kkart_variation",i).each(function(a,e){var i=c(e),o=c(".sale_price_dates_from",i).val(),e=c(".sale_price_dates_to",i).val();""===o&&""===e||c("a.sale_schedule",i).click()}),c(".kkart_variations .variation-needs-update",i).removeClass("variation-needs-update"),c("button.cancel-variation-changes, button.save-variation-changes",i).attr("disabled","disabled")),c("#tiptip_holder").removeAttr("style"),c("#tiptip_arrow").removeAttr("style"),c(".kkart_variations .tips, .kkart_variations .help_tip, .kkart_variations .kkart-help-tip",i).tipTip({attribute:"data-tip",fadeIn:50,fadeOut:50,delay:200}),c(".sale_price_dates_fields",i).find("input").datepicker({defaultDate:"",dateFormat:"yy-mm-dd",numberOfMonths:1,showButtonPanel:!0,onSelect:function(){var a=c(this).is(".sale_price_dates_from")?"minDate":"maxDate",e=c(this).closest(".sale_price_dates_fields").find("input"),i=c(this).datepicker("getDate");e.not(this).datepicker("option",a,i),c(this).change()}}),c(".kkart_variations",i).sortable({items:".kkart_variation",cursor:"move",axis:"y",handle:".sort",scrollSensitivity:40,forcePlaceholderSize:!0,helper:"clone",opacity:.65,stop:function(){o.variation_row_indexes()}}),c(document.body).trigger("kkart-enhanced-select-init")},variation_added:function(a,e){1===e&&o.variations_loaded(null,!0)},set_menu_order:function(a){a.preventDefault();var e=c(this).closest(".kkart_variation").find(".variation_menu_order"),a=window.prompt(kkart_admin_meta_boxes_variations.i18n_enter_menu_order,e.val());null!=a&&(e.val(parseInt(a,10)).change(),n.save_variations())},variation_row_indexes:function(){var a=c("#variable_product_options").find(".kkart_variations"),a=parseInt(a.attr("data-page"),10),i=parseInt((a-1)*kkart_admin_meta_boxes_variations.variations_per_page,10);c(".kkart_variations .kkart_variation").each(function(a,e){c(".variation_menu_order",e).val(parseInt(c(e).index(".kkart_variations .kkart_variation"),10)+1+i).change()})}},t={variable_image_frame:null,setting_variation_image_id:null,setting_variation_image:null,wp_media_post_id:wp.media.model.settings.post.id,init:function(){c("#variable_product_options").on("click",".upload_image_button",this.add_image),c("a.add_media").on("click",this.restore_wp_media_post_id)},add_image:function(a){var e=c(this),i=e.attr("rel"),o=e.closest(".upload_image");if(t.setting_variation_image=o,t.setting_variation_image_id=i,a.preventDefault(),e.is(".remove"))c(".upload_image_id",t.setting_variation_image).val("").change(),t.setting_variation_image.find("img").eq(0).attr("src",kkart_admin_meta_boxes_variations.kkart_placeholder_img_src),t.setting_variation_image.find(".upload_image_button").removeClass("remove");else{if(t.variable_image_frame)return t.variable_image_frame.uploader.uploader.param("post_id",t.setting_variation_image_id),void t.variable_image_frame.open();wp.media.model.settings.post.id=t.setting_variation_image_id,t.variable_image_frame=wp.media.frames.variable_image=wp.media({title:kkart_admin_meta_boxes_variations.i18n_choose_image,button:{text:kkart_admin_meta_boxes_variations.i18n_set_image},states:[new wp.media.controller.Library({title:kkart_admin_meta_boxes_variations.i18n_choose_image,filterable:"all"})]}),t.variable_image_frame.on("select",function(){var a=t.variable_image_frame.state().get("selection").first().toJSON(),e=(a.sizes&&a.sizes.thumbnail?a.sizes.thumbnail:a).url;c(".upload_image_id",t.setting_variation_image).val(a.id).change(),t.setting_variation_image.find(".upload_image_button").addClass("remove"),t.setting_variation_image.find("img").eq(0).attr("src",e),wp.media.model.settings.post.id=t.wp_media_post_id}),t.variable_image_frame.open()}},restore_wp_media_post_id:function(){wp.media.model.settings.post.id=t.wp_media_post_id}},n={init:function(){c("li.variations_tab a").on("click",this.initial_load),c("#variable_product_options").on("click","button.save-variation-changes",this.save_variations).on("click","button.cancel-variation-changes",this.cancel_variations).on("click",".remove_variation",this.remove_variation).on("click",".downloadable_files a.delete",this.input_changed),c(document.body).on("change","#variable_product_options .kkart_variations :input",this.input_changed).on("change",".variations-defaults select",this.defaults_changed);var a=c("form#post");a.on("submit",this.save_on_submit),c("input:submit",a).bind("click keypress",function(){a.data("callerid",this.id)}),c(".kkart-metaboxes-wrapper").on("click","a.do_variation_action",this.do_variation_action)},check_for_changes:function(){var a=c("#variable_product_options").find(".kkart_variations .variation-needs-update");if(0<a.length){if(!window.confirm(kkart_admin_meta_boxes_variations.i18n_edited_variations))return a.removeClass("variation-needs-update"),!1;n.save_changes()}return!0},block:function(){c("#kkart-product-data").block({message:null,overlayCSS:{background:"#fff",opacity:.6}})},unblock:function(){c("#kkart-product-data").unblock()},initial_load:function(){0===c("#variable_product_options").find(".kkart_variations .kkart_variation").length&&d.go_to_page()},load_variations:function(e,a){e=e||1,a=a||kkart_admin_meta_boxes_variations.variations_per_page;var i=c("#variable_product_options").find(".kkart_variations");n.block(),c.ajax({url:kkart_admin_meta_boxes_variations.ajax_url,data:{action:"kkart_load_variations",security:kkart_admin_meta_boxes_variations.load_variations_nonce,product_id:kkart_admin_meta_boxes_variations.post_id,attributes:i.data("attributes"),page:e,per_page:a},type:"POST",success:function(a){i.empty().append(a).attr("data-page",e),c("#kkart-product-data").trigger("kkart_variations_loaded"),n.unblock()}})},get_variations_fields:function(a){var i=c(":input",a).serializeJSON();return c(".variations-defaults select").each(function(a,e){e=c(e);i[e.attr("name")]=e.val()}),i},save_changes:function(e){var a=c("#variable_product_options").find(".kkart_variations"),i=c(".variation-needs-update",a),a={};0<i.length&&(n.block(),(a=n.get_variations_fields(i)).action="kkart_save_variations",a.security=kkart_admin_meta_boxes_variations.save_variations_nonce,a.product_id=kkart_admin_meta_boxes_variations.post_id,a["product-type"]=c("#product-type").val(),c.ajax({url:kkart_admin_meta_boxes_variations.ajax_url,data:a,type:"POST",success:function(a){i.removeClass("variation-needs-update"),c("button.cancel-variation-changes, button.save-variation-changes").attr("disabled","disabled"),c("#kkart-product-data").trigger("kkart_variations_saved"),"function"==typeof e&&e(a),n.unblock()}}))},save_variations:function(){return c("#variable_product_options").trigger("kkart_variations_save_variations_button"),n.save_changes(function(a){var e=c("#variable_product_options").find(".kkart_variations"),i=e.attr("data-page");c("#variable_product_options").find("#kkart_errors").remove(),a&&e.before(a),c(".variations-defaults select").each(function(){c(this).attr("data-current",c(this).val())}),d.go_to_page(i)}),!1},save_on_submit:function(a){0<c("#variable_product_options").find(".kkart_variations .variation-needs-update").length&&(a.preventDefault(),c("#variable_product_options").trigger("kkart_variations_save_variations_on_submit"),n.save_changes(n.save_on_submit_done))},save_on_submit_done:function(){var a=c("form#post");("publish"===a.data("callerid")?a.append('<input type="hidden" name="publish" value="1" />'):a.append('<input type="hidden" name="save-post" value="1" />')).submit()},cancel_variations:function(){var a=parseInt(c("#variable_product_options").find(".kkart_variations").attr("data-page"),10);return c("#variable_product_options").find(".kkart_variations .variation-needs-update").removeClass("variation-needs-update"),c(".variations-defaults select").each(function(){c(this).val(c(this).attr("data-current"))}),d.go_to_page(a),!1},add_variation:function(){n.block();var a={action:"kkart_add_variation",post_id:kkart_admin_meta_boxes_variations.post_id,loop:c(".kkart_variation").length,security:kkart_admin_meta_boxes_variations.add_variation_nonce};return c.post(kkart_admin_meta_boxes_variations.ajax_url,a,function(a){a=c(a);a.addClass("variation-needs-update"),c(".kkart-notice-invalid-variation").remove(),c("#variable_product_options").find(".kkart_variations").prepend(a),c("button.cancel-variation-changes, button.save-variation-changes").removeAttr("disabled"),c("#variable_product_options").trigger("kkart_variations_added",1),n.unblock()}),!1},remove_variation:function(){var a,e,i;return n.check_for_changes(),window.confirm(kkart_admin_meta_boxes_variations.i18n_remove_variation)&&(a=c(this).attr("rel"),e=[],i={action:"kkart_remove_variations"},n.block(),0<a?(e.push(a),i.variation_ids=e,i.security=kkart_admin_meta_boxes_variations.delete_variations_nonce,c.post(kkart_admin_meta_boxes_variations.ajax_url,i,function(){var a=c("#variable_product_options").find(".kkart_variations"),e=parseInt(a.attr("data-page"),10),i=Math.ceil((parseInt(a.attr("data-total"),10)-1)/kkart_admin_meta_boxes_variations.variations_per_page),a=1;c("#kkart-product-data").trigger("kkart_variations_removed"),e===i||e<=i?a=e:i<e&&0!==i&&(a=i),d.go_to_page(a,-1)})):n.unblock()),!1},link_all_variations:function(){var a;return n.check_for_changes(),window.confirm(kkart_admin_meta_boxes_variations.i18n_link_all_variations)&&(n.block(),a={action:"kkart_link_all_variations",post_id:kkart_admin_meta_boxes_variations.post_id,security:kkart_admin_meta_boxes_variations.link_variation_nonce},c.post(kkart_admin_meta_boxes_variations.ajax_url,a,function(a){a=parseInt(a,10);1===a?window.alert(a+" "+kkart_admin_meta_boxes_variations.i18n_variation_added):0===a||1<a?window.alert(a+" "+kkart_admin_meta_boxes_variations.i18n_variations_added):window.alert(kkart_admin_meta_boxes_variations.i18n_no_variations_added),0<a?(d.go_to_page(1,a),c("#variable_product_options").trigger("kkart_variations_added",a)):n.unblock()})),!1},input_changed:function(){c(this).closest(".kkart_variation").addClass("variation-needs-update"),c("button.cancel-variation-changes, button.save-variation-changes").removeAttr("disabled"),c("#variable_product_options").trigger("kkart_variations_input_changed")},defaults_changed:function(){c(this).closest("#variable_product_options").find(".kkart_variation:first").addClass("variation-needs-update"),c("button.cancel-variation-changes, button.save-variation-changes").removeAttr("disabled"),c("#variable_product_options").trigger("kkart_variations_defaults_changed")},do_variation_action:function(){var a,e=c("select.variation_actions").val(),i={},o=0;switch(e){case"add_variation":return void n.add_variation();case"link_all_variations":return void n.link_all_variations();case"delete_all":window.confirm(kkart_admin_meta_boxes_variations.i18n_delete_all_variations)&&window.confirm(kkart_admin_meta_boxes_variations.i18n_last_warning)&&(i.allowed=!0,o=-1*parseInt(c("#variable_product_options").find(".kkart_variations").attr("data-total"),10));break;case"variable_regular_price_increase":case"variable_regular_price_decrease":case"variable_sale_price_increase":case"variable_sale_price_decrease":if(null==(a=window.prompt(kkart_admin_meta_boxes_variations.i18n_enter_a_value_fixed_or_percent)))return;0<=a.indexOf("%")?i.value=accounting.unformat(a.replace(/\%/,""),kkart_admin.mon_decimal_point)+"%":i.value=accounting.unformat(a,kkart_admin.mon_decimal_point);break;case"variable_regular_price":case"variable_sale_price":case"variable_stock":case"variable_weight":case"variable_length":case"variable_width":case"variable_height":case"variable_download_limit":case"variable_download_expiry":if(null==(a=window.prompt(kkart_admin_meta_boxes_variations.i18n_enter_a_value)))return;i.value=a;break;case"variable_sale_schedule":if(i.date_from=window.prompt(kkart_admin_meta_boxes_variations.i18n_scheduled_sale_start),i.date_to=window.prompt(kkart_admin_meta_boxes_variations.i18n_scheduled_sale_end),null===i.date_from&&(i.date_from=!1),null===i.date_to&&(i.date_to=!1),!1===i.date_to&&!1===i.date_from)return;break;default:c("select.variation_actions").trigger(e),i=c("select.variation_actions").triggerHandler(e+"_ajax_data",i)}"delete_all"===e&&i.allowed?c("#variable_product_options").find(".variation-needs-update").removeClass("variation-needs-update"):n.check_for_changes(),n.block(),c.ajax({url:kkart_admin_meta_boxes_variations.ajax_url,data:{action:"kkart_bulk_edit_variations",security:kkart_admin_meta_boxes_variations.bulk_edit_variations_nonce,product_id:kkart_admin_meta_boxes_variations.post_id,product_type:c("#product-type").val(),bulk_action:e,data:i},type:"POST",success:function(){d.go_to_page(1,o)}})}},d={init:function(){c(document.body).on("kkart_variations_added",this.update_single_quantity).on("change",".variations-pagenav .page-selector",this.page_selector).on("click",".variations-pagenav .first-page",this.first_page).on("click",".variations-pagenav .prev-page",this.prev_page).on("click",".variations-pagenav .next-page",this.next_page).on("click",".variations-pagenav .last-page",this.last_page)},update_variations_count:function(a){var e=c("#variable_product_options").find(".kkart_variations"),i=parseInt(e.attr("data-total"),10)+a,a=c(".variations-pagenav .displaying-num");return e.attr("data-total",i),1===i?a.text(kkart_admin_meta_boxes_variations.i18n_variation_count_single.replace("%qty%",i)):a.text(kkart_admin_meta_boxes_variations.i18n_variation_count_plural.replace("%qty%",i)),i},update_single_quantity:function(a,e){var i;1===e&&(i=c(".variations-pagenav"),d.update_variations_count(e),i.is(":hidden")&&(c("option, optgroup",".variation_actions").show(),c(".variation_actions").val("add_variation"),c("#variable_product_options").find(".toolbar").show(),i.show(),c(".pagination-links",i).hide()))},set_paginav:function(a){var e=c("#variable_product_options").find(".kkart_variations"),i=d.update_variations_count(a),o=c("#variable_product_options").find(".toolbar"),t=c(".variation_actions"),n=c(".variations-pagenav"),a=c(".pagination-links",n),r=Math.ceil(i/kkart_admin_meta_boxes_variations.variations_per_page),_="";e.attr("data-total_pages",r),c(".total-pages",n).text(r);for(var s=1;s<=r;s++)_+='<option value="'+s+'">'+s+"</option>";c(".page-selector",n).empty().html(_),0===i?(o.not(".toolbar-top, .toolbar-buttons").hide(),n.hide(),c("option, optgroup",t).hide(),c(".variation_actions").val("add_variation"),c('option[data-global="true"]',t).show()):(o.show(),n.show(),c("option, optgroup",t).show(),c(".variation_actions").val("add_variation"),1===r?a.hide():a.show())},check_is_enabled:function(a){return!c(a).hasClass("disabled")},change_classes:function(a,e){var i=c(".variations-pagenav .first-page"),o=c(".variations-pagenav .prev-page"),t=c(".variations-pagenav .next-page"),n=c(".variations-pagenav .last-page");1===a?(i.addClass("disabled"),o.addClass("disabled")):(i.removeClass("disabled"),o.removeClass("disabled")),e===a?(t.addClass("disabled"),n.addClass("disabled")):(t.removeClass("disabled"),n.removeClass("disabled"))},set_page:function(a){c(".variations-pagenav .page-selector").val(a).first().change()},go_to_page:function(a,e){a=a||1,e=e||0,d.set_paginav(e),d.set_page(a)},page_selector:function(){var a=parseInt(c(this).val(),10),e=c("#variable_product_options").find(".kkart_variations");c(".variations-pagenav .page-selector").val(a),n.check_for_changes(),d.change_classes(a,parseInt(e.attr("data-total_pages"),10)),n.load_variations(a)},first_page:function(){return d.check_is_enabled(this)&&d.set_page(1),!1},prev_page:function(){var a;return d.check_is_enabled(this)&&(a=c("#variable_product_options").find(".kkart_variations"),a=0<(a=parseInt(a.attr("data-page"),10)-1)?a:1,d.set_page(a)),!1},next_page:function(){var a,e;return d.check_is_enabled(this)&&(a=c("#variable_product_options").find(".kkart_variations"),e=parseInt(a.attr("data-total_pages"),10),e=(a=parseInt(a.attr("data-page"),10)+1)<=e?a:e,d.set_page(e)),!1},last_page:function(){var a;return d.check_is_enabled(this)&&(a=c("#variable_product_options").find(".kkart_variations").attr("data-total_pages"),d.set_page(a)),!1}};o.init(),t.init(),n.init(),d.init()});