From b819326b2aa7026b042aca1478a7bb36eff0e87b Mon Sep 17 00:00:00 2001 From: Claudio Sanches Date: Mon, 6 Jul 2015 20:05:09 -0300 Subject: [PATCH] Created new js classes for variations media and actions --- .../js/admin/meta-boxes-product-variation.js | 242 ++++++++++++------ .../admin/meta-boxes-product-variation.min.js | 2 +- 2 files changed, 158 insertions(+), 86 deletions(-) diff --git a/assets/js/admin/meta-boxes-product-variation.js b/assets/js/admin/meta-boxes-product-variation.js index 389f8eeab84..779f11a5398 100644 --- a/assets/js/admin/meta-boxes-product-variation.js +++ b/assets/js/admin/meta-boxes-product-variation.js @@ -1,6 +1,6 @@ /* global wp, woocommerce_admin_meta_boxes_variations, woocommerce_admin, woocommerce_admin_meta_boxes, accounting */ /*jshint devel: true */ -jQuery( function ( $ ) { +jQuery( function( $ ) { $( '.wc-metaboxes-wrapper' ).on( 'click', 'a.bulk_edit', function () { var bulk_edit = $( 'select#field_to_edit' ).val(), @@ -154,102 +154,172 @@ jQuery( function ( $ ) { } }); - $( '#variable_product_options' ).on( 'change', 'input.variable_is_downloadable', function () { - $( this ).closest( '.woocommerce_variation' ).find( '.show_if_variation_downloadable' ).hide(); + /** + * Variations actions + */ + var wc_meta_boxes_product_variations_actions = { - if ( $( this ).is( ':checked' ) ) { - $( this ).closest( '.woocommerce_variation' ).find( '.show_if_variation_downloadable' ).show(); - } - }); + /** + * Initialize variations actions + */ + init: function() { + $( '#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 ); - $( '#variable_product_options' ).on( 'change', 'input.variable_is_virtual', function () { - $( this ).closest( '.woocommerce_variation' ).find( '.hide_if_variation_virtual' ).show(); + $( 'input.variable_is_downloadable, input.variable_is_virtual, input.variable_manage_stock' ).change(); - if ( $( this ).is( ':checked' ) ) { - $( this ).closest( '.woocommerce_variation' ).find( '.hide_if_variation_virtual' ).hide(); - } - }); + $( 'a.add_media' ).on( 'click', this.restore_media_post_id ); + }, - $( '#variable_product_options' ).on( 'change', 'input.variable_manage_stock', function () { - $( this ).closest( '.woocommerce_variation' ).find( '.show_if_variation_manage_stock' ).hide(); + /** + * Check if variation is downloadable and show/hide elements + */ + variable_is_downloadable: function() { + $( this ).closest( '.woocommerce_variation' ).find( '.show_if_variation_downloadable' ).hide(); - if ( $( this ).is( ':checked' ) ) { - $( this ).closest( '.woocommerce_variation' ).find( '.show_if_variation_manage_stock' ).show(); - } - }); - - $( 'input.variable_is_downloadable, input.variable_is_virtual, input.variable_manage_stock' ).change(); - - // Uploader - var variable_image_frame; - var setting_variation_image_id; - var setting_variation_image; - var wp_media_post_id = wp.media.model.settings.post.id; - - $( '#variable_product_options' ).on( 'click', '.upload_image_button', function ( event ) { - - var $button = $( this ); - var post_id = $button.attr( 'rel' ); - var $parent = $button.closest( '.upload_image' ); - setting_variation_image = $parent; - setting_variation_image_id = post_id; - - event.preventDefault(); - - if ( $button.is( '.remove' ) ) { - - setting_variation_image.find( '.upload_image_id' ).val( '' ); - setting_variation_image.find( 'img' ).eq( 0 ).attr( 'src', woocommerce_admin_meta_boxes_variations.woocommerce_placeholder_img_src ); - setting_variation_image.find( '.upload_image_button' ).removeClass( 'remove' ); - - } else { - - // If the media frame already exists, reopen it. - if ( variable_image_frame ) { - variable_image_frame.uploader.uploader.param( 'post_id', setting_variation_image_id ); - variable_image_frame.open(); - return; - } else { - wp.media.model.settings.post.id = setting_variation_image_id; + if ( $( this ).is( ':checked' ) ) { + $( this ).closest( '.woocommerce_variation' ).find( '.show_if_variation_downloadable' ).show(); } + }, - // Create the media frame. - variable_image_frame = wp.media.frames.variable_image = wp.media({ - // Set the title of the modal. - title: woocommerce_admin_meta_boxes_variations.i18n_choose_image, - button: { - text: woocommerce_admin_meta_boxes_variations.i18n_set_image - }, - states : [ - new wp.media.controller.Library({ - title: woocommerce_admin_meta_boxes_variations.i18n_choose_image, - filterable : 'all' - }) - ] - }); + /** + * Check if variation is virtual and show/hide elements + */ + variable_is_virtual: function() { + $( this ).closest( '.woocommerce_variation' ).find( '.hide_if_variation_virtual' ).show(); - // When an image is selected, run a callback. - variable_image_frame.on( 'select', function () { + if ( $( this ).is( ':checked' ) ) { + $( this ).closest( '.woocommerce_variation' ).find( '.hide_if_variation_virtual' ).hide(); + } + }, - var attachment = variable_image_frame.state().get( 'selection' ).first().toJSON(), - url = attachment.sizes.thumbnail ? attachment.sizes.thumbnail.url : attachment.url; + /** + * Check if variation manage stock and show/hide elements + */ + variable_manage_stock: function() { + $( this ).closest( '.woocommerce_variation' ).find( '.show_if_variation_manage_stock' ).hide(); - setting_variation_image.find( '.upload_image_id' ).val( attachment.id ); - setting_variation_image.find( '.upload_image_button' ).addClass( 'remove' ); - setting_variation_image.find( 'img' ).eq( 0 ).attr( 'src', url ); - - wp.media.model.settings.post.id = wp_media_post_id; - }); - - // Finally, open the modal. - variable_image_frame.open(); + if ( $( this ).is( ':checked' ) ) { + $( this ).closest( '.woocommerce_variation' ).find( '.show_if_variation_manage_stock' ).show(); + } } - }); + }; - // Restore ID - $( 'a.add_media' ).on( 'click', function() { - wp.media.model.settings.post.id = wp_media_post_id; - }); + /** + * Variations media actions + */ + var wc_meta_boxes_product_variations_media = { + + /** + * wp.media frame object + * + * @type {object} + */ + variable_image_frame: null, + + /** + * Variation image ID + * + * @type {int} + */ + setting_variation_image_id: null, + + /** + * Variation image object + * + * @type {object} + */ + setting_variation_image: null, + + /** + * wp.media post ID + * + * @type {int} + */ + wp_media_post_id: wp.media.model.settings.post.id, + + /** + * Initialize media actions + */ + init: function() { + $( '#variable_product_options' ).on( 'click', '.upload_image_button', this.add_image ); + $( 'a.add_media' ).on( 'click', this.restore_wp_media_post_id ); + }, + + /** + * Added new image + * + * @param {object} event + */ + add_image: function( event ) { + var $button = $( this ), + post_id = $button.attr( 'rel' ), + $parent = $button.closest( '.upload_image' ); + + wc_meta_boxes_product_variations_media.setting_variation_image = $parent; + wc_meta_boxes_product_variations_media.setting_variation_image_id = post_id; + + event.preventDefault(); + + if ( $button.is( '.remove' ) ) { + + $( '.upload_image_id', wc_meta_boxes_product_variations_media.setting_variation_image ).val( '' ).change(); + wc_meta_boxes_product_variations_media.setting_variation_image.find( 'img' ).eq( 0 ).attr( 'src', woocommerce_admin_meta_boxes_variations.woocommerce_placeholder_img_src ); + wc_meta_boxes_product_variations_media.setting_variation_image.find( '.upload_image_button' ).removeClass( 'remove' ); + + } else { + + // If the media frame already exists, reopen it. + if ( wc_meta_boxes_product_variations_media.variable_image_frame ) { + wc_meta_boxes_product_variations_media.variable_image_frame.uploader.uploader.param( 'post_id', wc_meta_boxes_product_variations_media.setting_variation_image_id ); + wc_meta_boxes_product_variations_media.variable_image_frame.open(); + return; + } else { + wp.media.model.settings.post.id = wc_meta_boxes_product_variations_media.setting_variation_image_id; + } + + // Create the media frame. + wc_meta_boxes_product_variations_media.variable_image_frame = wp.media.frames.variable_image = wp.media({ + // Set the title of the modal. + title: woocommerce_admin_meta_boxes_variations.i18n_choose_image, + button: { + text: woocommerce_admin_meta_boxes_variations.i18n_set_image + }, + states: [ + new wp.media.controller.Library({ + title: woocommerce_admin_meta_boxes_variations.i18n_choose_image, + filterable: 'all' + }) + ] + }); + + // When an image is selected, run a callback. + wc_meta_boxes_product_variations_media.variable_image_frame.on( 'select', function () { + + var attachment = wc_meta_boxes_product_variations_media.variable_image_frame.state().get( 'selection' ).first().toJSON(), + url = attachment.sizes.thumbnail ? attachment.sizes.thumbnail.url : attachment.url; + + $( '.upload_image_id', wc_meta_boxes_product_variations_media.setting_variation_image ).val( attachment.id ).change(); + wc_meta_boxes_product_variations_media.setting_variation_image.find( '.upload_image_button' ).addClass( 'remove' ); + wc_meta_boxes_product_variations_media.setting_variation_image.find( 'img' ).eq( 0 ).attr( 'src', url ); + + wp.media.model.settings.post.id = wc_meta_boxes_product_variations_media.wp_media_post_id; + }); + + // Finally, open the modal. + wc_meta_boxes_product_variations_media.variable_image_frame.open(); + } + }, + + /** + * Restore wp.media post ID. + */ + restore_wp_media_post_id: function() { + wp.media.model.settings.post.id = wc_meta_boxes_product_variations_media.wp_media_post_id; + } + }; /** * Product variations metabox ajax methods @@ -688,6 +758,8 @@ jQuery( function ( $ ) { } }; + wc_meta_boxes_product_variations_actions.init(); + wc_meta_boxes_product_variations_media.init(); wc_meta_boxes_product_variations_ajax.init(); wc_meta_boxes_product_variations_pagenav.init(); diff --git a/assets/js/admin/meta-boxes-product-variation.min.js b/assets/js/admin/meta-boxes-product-variation.min.js index e19ef311535..dafec21a7dd 100644 --- a/assets/js/admin/meta-boxes-product-variation.min.js +++ b/assets/js/admin/meta-boxes-product-variation.min.js @@ -1 +1 @@ -jQuery(function(a){a(".wc-metaboxes-wrapper").on("click","a.bulk_edit",function(){var b,c,d,e=a("select#field_to_edit").val();switch(e){case"toggle_enabled":b=a('input[name^="variable_enabled"]'),b.attr("checked",!b.attr("checked"));break;case"toggle_downloadable":b=a('input[name^="variable_is_downloadable"]'),b.attr("checked",!b.attr("checked")),a("input.variable_is_downloadable").change();break;case"toggle_virtual":b=a('input[name^="variable_is_virtual"]'),b.attr("checked",!b.attr("checked")),a("input.variable_is_virtual").change();break;case"toggle_manage_stock":b=a('input[name^="variable_manage_stock"]'),b.attr("checked",!b.attr("checked")),a("input.variable_manage_stock").change();break;case"delete_all":if(c=window.confirm(woocommerce_admin_meta_boxes_variations.i18n_delete_all_variations),c&&(c=window.confirm(woocommerce_admin_meta_boxes_variations.i18n_last_warning))){var f=[];a(".woocommerce_variations .woocommerce_variation").block({message:null,overlayCSS:{background:"#fff",opacity:.6}}),a(".woocommerce_variations .woocommerce_variation .remove_variation").each(function(){var b=a(this).attr("rel");b>0&&f.push(b)});var g={action:"woocommerce_remove_variations",variation_ids:f,security:woocommerce_admin_meta_boxes_variations.delete_variations_nonce};a.post(woocommerce_admin_meta_boxes_variations.ajax_url,g,function(){a(".woocommerce_variations .woocommerce_variation").fadeOut("300",function(){a(".woocommerce_variations .woocommerce_variation").remove()})})}break;case"variable_regular_price_increase":case"variable_regular_price_decrease":case"variable_sale_price_increase":case"variable_sale_price_decrease":var h;if(h=0===e.lastIndexOf("variable_regular_price",0)?"variable_regular_price":"variable_sale_price",d=window.prompt(woocommerce_admin_meta_boxes_variations.i18n_enter_a_value_fixed_or_percent),null==d)return;d=d.toString(),a(':input[name^="'+h+'"]').not('[name*="dates"]').each(function(){var b,c,f=accounting.unformat(a(this).val(),woocommerce_admin.mon_decimal_point);c=d.indexOf("%")>=0?f/100*accounting.unformat(d.replace(/\%/,""),woocommerce_admin.mon_decimal_point):accounting.unformat(d,woocommerce_admin.mon_decimal_point),b=-1!==e.indexOf("increase")?f+c:f-c,a(this).val(accounting.formatNumber(b,woocommerce_admin_meta_boxes.currency_format_num_decimals,woocommerce_admin_meta_boxes.currency_format_thousand_sep,woocommerce_admin_meta_boxes.currency_format_decimal_sep)).change()});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":d=window.prompt(woocommerce_admin_meta_boxes_variations.i18n_enter_a_value),null!=d&&a(':input[name^="'+e+'"]').not('[name*="dates"]').val(d).change();break;case"variable_sale_schedule":var i=window.prompt(woocommerce_admin_meta_boxes_variations.i18n_scheduled_sale_start),j=window.prompt(woocommerce_admin_meta_boxes_variations.i18n_scheduled_sale_end),k=!1;null!=i&&""!==i&&(a(".woocommerce_variable_attributes .sale_schedule").click(),a(':input[name^="variable_sale_price_dates_from"]').val(i).change(),k=!0),null!=j&&""!==j&&(a(".woocommerce_variable_attributes .sale_schedule").click(),a(':input[name^="variable_sale_price_dates_to"]').val(j).change(),k=!0),k||a(".woocommerce_variable_attributes .cancel_sale_schedule").click();break;default:a("select#field_to_edit").trigger(e)}}),a("#variable_product_options").on("change","input.variable_is_downloadable",function(){a(this).closest(".woocommerce_variation").find(".show_if_variation_downloadable").hide(),a(this).is(":checked")&&a(this).closest(".woocommerce_variation").find(".show_if_variation_downloadable").show()}),a("#variable_product_options").on("change","input.variable_is_virtual",function(){a(this).closest(".woocommerce_variation").find(".hide_if_variation_virtual").show(),a(this).is(":checked")&&a(this).closest(".woocommerce_variation").find(".hide_if_variation_virtual").hide()}),a("#variable_product_options").on("change","input.variable_manage_stock",function(){a(this).closest(".woocommerce_variation").find(".show_if_variation_manage_stock").hide(),a(this).is(":checked")&&a(this).closest(".woocommerce_variation").find(".show_if_variation_manage_stock").show()}),a("input.variable_is_downloadable, input.variable_is_virtual, input.variable_manage_stock").change();var b,c,d,e=wp.media.model.settings.post.id;a("#variable_product_options").on("click",".upload_image_button",function(f){var g=a(this),h=g.attr("rel"),i=g.closest(".upload_image");if(d=i,c=h,f.preventDefault(),g.is(".remove"))d.find(".upload_image_id").val(""),d.find("img").eq(0).attr("src",woocommerce_admin_meta_boxes_variations.woocommerce_placeholder_img_src),d.find(".upload_image_button").removeClass("remove");else{if(b)return b.uploader.uploader.param("post_id",c),void b.open();wp.media.model.settings.post.id=c,b=wp.media.frames.variable_image=wp.media({title:woocommerce_admin_meta_boxes_variations.i18n_choose_image,button:{text:woocommerce_admin_meta_boxes_variations.i18n_set_image},states:[new wp.media.controller.Library({title:woocommerce_admin_meta_boxes_variations.i18n_choose_image,filterable:"all"})]}),b.on("select",function(){var a=b.state().get("selection").first().toJSON(),c=a.sizes.thumbnail?a.sizes.thumbnail.url:a.url;d.find(".upload_image_id").val(a.id),d.find(".upload_image_button").addClass("remove"),d.find("img").eq(0).attr("src",c),wp.media.model.settings.post.id=e}),b.open()}}),a("a.add_media").on("click",function(){wp.media.model.settings.post.id=e});var f={init:function(){a("li.variations_tab a").on("click",this.initial_load),a("#variable_product_options").on("click","button.save-variation-changes",this.save_variations).on("click","button.add_variation",this.add_variation).on("click","button.remove_variation",this.remove_variation).on("click","button.link_all_variations",this.link_all_variations),a("body").on("change","#variable_product_options .woocommerce_variations :input",this.input_changed)},check_for_editions:function(){var b=a("#variable_product_options .woocommerce_variations .variation-needs-update");if(00?(c.push(b),d.variation_ids=c,d.security=woocommerce_admin_meta_boxes_variations.delete_variations_nonce,a.post(woocommerce_admin_meta_boxes_variations.ajax_url,d,function(){var b=parseInt(a("#variable_product_options .woocommerce_variations").attr("data-page"),10);g.set_paginav(-1),g.set_page(b)})):f.unblock()}return!1},link_all_variations:function(){if(!f.check_for_editions())return!1;if(window.confirm(woocommerce_admin_meta_boxes_variations.i18n_link_all_variations)){f.block();var b={action:"woocommerce_link_all_variations",post_id:woocommerce_admin_meta_boxes_variations.post_id,security:woocommerce_admin_meta_boxes_variations.link_variation_nonce};a.post(woocommerce_admin_meta_boxes_variations.ajax_url,b,function(b){var c=parseInt(b,10);window.alert(1===c?c+" "+woocommerce_admin_meta_boxes_variations.i18n_variation_added:0===c||c>1?c+" "+woocommerce_admin_meta_boxes_variations.i18n_variations_added:woocommerce_admin_meta_boxes_variations.i18n_no_variations_added),c>0?(g.set_paginav(c),g.set_page(1),a("#variable_product_options").trigger("woocommerce_variations_added")):f.unblock()})}return!1},input_changed:function(){a(this).closest(".woocommerce_variation").addClass("variation-needs-update"),a(".save-variation-changes").removeAttr("disabled")}},g={init:function(){a(".variations-pagenav").on("change",".page-selector",this.page_selector).on("click",".first-page",this.first_page).on("click",".prev-page",this.prev_page).on("click",".next-page",this.next_page).on("click",".last-page",this.last_page)},set_paginav:function(b){var c=a("#variable_product_options .woocommerce_variations"),d=parseInt(c.attr("data-total"),10),e=d+b,f=a(".variations-pagenav .displaying-num"),g=Math.ceil(e/woocommerce_admin_meta_boxes_variations.variations_per_page),h="";c.attr("data-total",e),f.text(1===e?woocommerce_admin_meta_boxes_variations.i18n_item.replace("%qty%",e):woocommerce_admin_meta_boxes_variations.i18n_items.replace("%qty%",e)),c.attr("data-total_pages",g),a(".variations-pagenav .total-pages").text(g);for(var i=1;g>=i;i++)h+='";a(".page-selector").empty().html(h)},check_is_enabled:function(b){return!a(b).hasClass("disabled")&&f.check_for_editions()},change_classes:function(b,c){var d=a(".variations-pagenav .first-page"),e=a(".variations-pagenav .prev-page"),f=a(".variations-pagenav .next-page"),g=a(".variations-pagenav .last-page");1===b?(d.addClass("disabled"),e.addClass("disabled")):(d.removeClass("disabled"),e.removeClass("disabled")),c===b?(f.addClass("disabled"),g.addClass("disabled")):(f.removeClass("disabled"),g.removeClass("disabled"))},set_page:function(b){a(".variations-pagenav .page-selector").val(b).change()},page_selector:function(){var b=parseInt(a(this).val(),10),c=a("#variable_product_options .woocommerce_variations");f.check_for_editions()?(g.change_classes(b,parseInt(c.attr("data-total_pages"),10)),f.load_variations(b)):a(this).val(parseInt(c.data("page"),10))},first_page:function(){return g.check_is_enabled(this)&&g.set_page(1),!1},prev_page:function(){if(g.check_is_enabled(this)){var b=a("#variable_product_options .woocommerce_variations"),c=parseInt(b.data("page"),10)-1,d=c>0?c:1;g.set_page(d)}return!1},next_page:function(){if(g.check_is_enabled(this)){var b=a("#variable_product_options .woocommerce_variations"),c=parseInt(b.data("total_pages"),10),d=parseInt(b.data("page"),10)+1,e=c>=d?d:c;g.set_page(e)}return!1},last_page:function(){if(g.check_is_enabled(this)){var b=a("#variable_product_options .woocommerce_variations").data("total_pages");g.set_page(b)}return!1}};f.init(),g.init()}); \ No newline at end of file +jQuery(function(a){a(".wc-metaboxes-wrapper").on("click","a.bulk_edit",function(){var b,c,d,e=a("select#field_to_edit").val();switch(e){case"toggle_enabled":b=a('input[name^="variable_enabled"]'),b.attr("checked",!b.attr("checked"));break;case"toggle_downloadable":b=a('input[name^="variable_is_downloadable"]'),b.attr("checked",!b.attr("checked")),a("input.variable_is_downloadable").change();break;case"toggle_virtual":b=a('input[name^="variable_is_virtual"]'),b.attr("checked",!b.attr("checked")),a("input.variable_is_virtual").change();break;case"toggle_manage_stock":b=a('input[name^="variable_manage_stock"]'),b.attr("checked",!b.attr("checked")),a("input.variable_manage_stock").change();break;case"delete_all":if(c=window.confirm(woocommerce_admin_meta_boxes_variations.i18n_delete_all_variations),c&&(c=window.confirm(woocommerce_admin_meta_boxes_variations.i18n_last_warning))){var f=[];a(".woocommerce_variations .woocommerce_variation").block({message:null,overlayCSS:{background:"#fff",opacity:.6}}),a(".woocommerce_variations .woocommerce_variation .remove_variation").each(function(){var b=a(this).attr("rel");b>0&&f.push(b)});var g={action:"woocommerce_remove_variations",variation_ids:f,security:woocommerce_admin_meta_boxes_variations.delete_variations_nonce};a.post(woocommerce_admin_meta_boxes_variations.ajax_url,g,function(){a(".woocommerce_variations .woocommerce_variation").fadeOut("300",function(){a(".woocommerce_variations .woocommerce_variation").remove()})})}break;case"variable_regular_price_increase":case"variable_regular_price_decrease":case"variable_sale_price_increase":case"variable_sale_price_decrease":var h;if(h=0===e.lastIndexOf("variable_regular_price",0)?"variable_regular_price":"variable_sale_price",d=window.prompt(woocommerce_admin_meta_boxes_variations.i18n_enter_a_value_fixed_or_percent),null==d)return;d=d.toString(),a(':input[name^="'+h+'"]').not('[name*="dates"]').each(function(){var b,c,f=accounting.unformat(a(this).val(),woocommerce_admin.mon_decimal_point);c=d.indexOf("%")>=0?f/100*accounting.unformat(d.replace(/\%/,""),woocommerce_admin.mon_decimal_point):accounting.unformat(d,woocommerce_admin.mon_decimal_point),b=-1!==e.indexOf("increase")?f+c:f-c,a(this).val(accounting.formatNumber(b,woocommerce_admin_meta_boxes.currency_format_num_decimals,woocommerce_admin_meta_boxes.currency_format_thousand_sep,woocommerce_admin_meta_boxes.currency_format_decimal_sep)).change()});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":d=window.prompt(woocommerce_admin_meta_boxes_variations.i18n_enter_a_value),null!=d&&a(':input[name^="'+e+'"]').not('[name*="dates"]').val(d).change();break;case"variable_sale_schedule":var i=window.prompt(woocommerce_admin_meta_boxes_variations.i18n_scheduled_sale_start),j=window.prompt(woocommerce_admin_meta_boxes_variations.i18n_scheduled_sale_end),k=!1;null!=i&&""!==i&&(a(".woocommerce_variable_attributes .sale_schedule").click(),a(':input[name^="variable_sale_price_dates_from"]').val(i).change(),k=!0),null!=j&&""!==j&&(a(".woocommerce_variable_attributes .sale_schedule").click(),a(':input[name^="variable_sale_price_dates_to"]').val(j).change(),k=!0),k||a(".woocommerce_variable_attributes .cancel_sale_schedule").click();break;default:a("select#field_to_edit").trigger(e)}});var b={init:function(){a("#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),a("input.variable_is_downloadable, input.variable_is_virtual, input.variable_manage_stock").change(),a("a.add_media").on("click",this.restore_media_post_id)},variable_is_downloadable:function(){a(this).closest(".woocommerce_variation").find(".show_if_variation_downloadable").hide(),a(this).is(":checked")&&a(this).closest(".woocommerce_variation").find(".show_if_variation_downloadable").show()},variable_is_virtual:function(){a(this).closest(".woocommerce_variation").find(".hide_if_variation_virtual").show(),a(this).is(":checked")&&a(this).closest(".woocommerce_variation").find(".hide_if_variation_virtual").hide()},variable_manage_stock:function(){a(this).closest(".woocommerce_variation").find(".show_if_variation_manage_stock").hide(),a(this).is(":checked")&&a(this).closest(".woocommerce_variation").find(".show_if_variation_manage_stock").show()}},c={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(){a("#variable_product_options").on("click",".upload_image_button",this.add_image),a("a.add_media").on("click",this.restore_wp_media_post_id)},add_image:function(b){var d=a(this),e=d.attr("rel"),f=d.closest(".upload_image");if(c.setting_variation_image=f,c.setting_variation_image_id=e,b.preventDefault(),d.is(".remove"))a(".upload_image_id",c.setting_variation_image).val("").change(),c.setting_variation_image.find("img").eq(0).attr("src",woocommerce_admin_meta_boxes_variations.woocommerce_placeholder_img_src),c.setting_variation_image.find(".upload_image_button").removeClass("remove");else{if(c.variable_image_frame)return c.variable_image_frame.uploader.uploader.param("post_id",c.setting_variation_image_id),void c.variable_image_frame.open();wp.media.model.settings.post.id=c.setting_variation_image_id,c.variable_image_frame=wp.media.frames.variable_image=wp.media({title:woocommerce_admin_meta_boxes_variations.i18n_choose_image,button:{text:woocommerce_admin_meta_boxes_variations.i18n_set_image},states:[new wp.media.controller.Library({title:woocommerce_admin_meta_boxes_variations.i18n_choose_image,filterable:"all"})]}),c.variable_image_frame.on("select",function(){var b=c.variable_image_frame.state().get("selection").first().toJSON(),d=b.sizes.thumbnail?b.sizes.thumbnail.url:b.url;a(".upload_image_id",c.setting_variation_image).val(b.id).change(),c.setting_variation_image.find(".upload_image_button").addClass("remove"),c.setting_variation_image.find("img").eq(0).attr("src",d),wp.media.model.settings.post.id=c.wp_media_post_id}),c.variable_image_frame.open()}},restore_wp_media_post_id:function(){wp.media.model.settings.post.id=c.wp_media_post_id}},d={init:function(){a("li.variations_tab a").on("click",this.initial_load),a("#variable_product_options").on("click","button.save-variation-changes",this.save_variations).on("click","button.add_variation",this.add_variation).on("click","button.remove_variation",this.remove_variation).on("click","button.link_all_variations",this.link_all_variations),a("body").on("change","#variable_product_options .woocommerce_variations :input",this.input_changed)},check_for_editions:function(){var b=a("#variable_product_options .woocommerce_variations .variation-needs-update");if(00?(c.push(b),f.variation_ids=c,f.security=woocommerce_admin_meta_boxes_variations.delete_variations_nonce,a.post(woocommerce_admin_meta_boxes_variations.ajax_url,f,function(){var b=parseInt(a("#variable_product_options .woocommerce_variations").attr("data-page"),10);e.set_paginav(-1),e.set_page(b)})):d.unblock()}return!1},link_all_variations:function(){if(!d.check_for_editions())return!1;if(window.confirm(woocommerce_admin_meta_boxes_variations.i18n_link_all_variations)){d.block();var b={action:"woocommerce_link_all_variations",post_id:woocommerce_admin_meta_boxes_variations.post_id,security:woocommerce_admin_meta_boxes_variations.link_variation_nonce};a.post(woocommerce_admin_meta_boxes_variations.ajax_url,b,function(b){var c=parseInt(b,10);window.alert(1===c?c+" "+woocommerce_admin_meta_boxes_variations.i18n_variation_added:0===c||c>1?c+" "+woocommerce_admin_meta_boxes_variations.i18n_variations_added:woocommerce_admin_meta_boxes_variations.i18n_no_variations_added),c>0?(e.set_paginav(c),e.set_page(1),a("#variable_product_options").trigger("woocommerce_variations_added")):d.unblock()})}return!1},input_changed:function(){a(this).closest(".woocommerce_variation").addClass("variation-needs-update"),a(".save-variation-changes").removeAttr("disabled")}},e={init:function(){a(".variations-pagenav").on("change",".page-selector",this.page_selector).on("click",".first-page",this.first_page).on("click",".prev-page",this.prev_page).on("click",".next-page",this.next_page).on("click",".last-page",this.last_page)},set_paginav:function(b){var c=a("#variable_product_options .woocommerce_variations"),d=parseInt(c.attr("data-total"),10),e=d+b,f=a(".variations-pagenav .displaying-num"),g=Math.ceil(e/woocommerce_admin_meta_boxes_variations.variations_per_page),h="";c.attr("data-total",e),f.text(1===e?woocommerce_admin_meta_boxes_variations.i18n_item.replace("%qty%",e):woocommerce_admin_meta_boxes_variations.i18n_items.replace("%qty%",e)),c.attr("data-total_pages",g),a(".variations-pagenav .total-pages").text(g);for(var i=1;g>=i;i++)h+='";a(".page-selector").empty().html(h)},check_is_enabled:function(b){return!a(b).hasClass("disabled")&&d.check_for_editions()},change_classes:function(b,c){var d=a(".variations-pagenav .first-page"),e=a(".variations-pagenav .prev-page"),f=a(".variations-pagenav .next-page"),g=a(".variations-pagenav .last-page");1===b?(d.addClass("disabled"),e.addClass("disabled")):(d.removeClass("disabled"),e.removeClass("disabled")),c===b?(f.addClass("disabled"),g.addClass("disabled")):(f.removeClass("disabled"),g.removeClass("disabled"))},set_page:function(b){a(".variations-pagenav .page-selector").val(b).change()},page_selector:function(){var b=parseInt(a(this).val(),10),c=a("#variable_product_options .woocommerce_variations");d.check_for_editions()?(e.change_classes(b,parseInt(c.attr("data-total_pages"),10)),d.load_variations(b)):a(this).val(parseInt(c.data("page"),10))},first_page:function(){return e.check_is_enabled(this)&&e.set_page(1),!1},prev_page:function(){if(e.check_is_enabled(this)){var b=a("#variable_product_options .woocommerce_variations"),c=parseInt(b.data("page"),10)-1,d=c>0?c:1;e.set_page(d)}return!1},next_page:function(){if(e.check_is_enabled(this)){var b=a("#variable_product_options .woocommerce_variations"),c=parseInt(b.data("total_pages"),10),d=parseInt(b.data("page"),10)+1,f=c>=d?d:c;e.set_page(f)}return!1},last_page:function(){if(e.check_is_enabled(this)){var b=a("#variable_product_options .woocommerce_variations").data("total_pages");e.set_page(b)}return!1}};b.init(),c.init(),d.init(),e.init()}); \ No newline at end of file