2014-02-14 20:49:36 +00:00
|
|
|
/* global wp, woocommerce_admin_meta_boxes_variations */
|
|
|
|
jQuery( function ( $ ) {
|
2013-08-06 10:41:20 +00:00
|
|
|
|
|
|
|
var variation_sortable_options = {
|
2014-02-14 20:49:36 +00:00
|
|
|
items: '.woocommerce_variation',
|
|
|
|
cursor: 'move',
|
|
|
|
axis: 'y',
|
2013-08-06 10:41:20 +00:00
|
|
|
handle: 'h3',
|
2014-02-14 20:49:36 +00:00
|
|
|
scrollSensitivity: 40,
|
2013-08-06 10:41:20 +00:00
|
|
|
forcePlaceholderSize: true,
|
|
|
|
helper: 'clone',
|
|
|
|
opacity: 0.65,
|
|
|
|
placeholder: 'wc-metabox-sortable-placeholder',
|
2014-02-14 20:49:36 +00:00
|
|
|
start: function( event, ui ) {
|
|
|
|
ui.item.css( 'background-color', '#f6f6f6' );
|
2013-08-06 10:41:20 +00:00
|
|
|
},
|
2014-02-14 20:49:36 +00:00
|
|
|
stop: function ( event, ui ) {
|
|
|
|
ui.item.removeAttr( 'style' );
|
2013-08-06 10:41:20 +00:00
|
|
|
variation_row_indexes();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
// Add a variation
|
2014-02-14 20:49:36 +00:00
|
|
|
$( '#variable_product_options' ).on( 'click', 'button.add_variation', function () {
|
2013-08-06 10:41:20 +00:00
|
|
|
|
2014-02-14 20:49:36 +00:00
|
|
|
$('.woocommerce_variations').block({
|
|
|
|
message: null,
|
|
|
|
overlayCSS: {
|
|
|
|
background: '#fff url(' + woocommerce_admin_meta_boxes_variations.plugin_url + '/assets/images/ajax-loader.gif) no-repeat center',
|
|
|
|
opacity: 0.6
|
|
|
|
}
|
|
|
|
});
|
2013-08-06 10:41:20 +00:00
|
|
|
|
2014-02-14 20:49:36 +00:00
|
|
|
var loop = $('.woocommerce_variation').size();
|
2013-08-06 10:41:20 +00:00
|
|
|
|
|
|
|
var data = {
|
|
|
|
action: 'woocommerce_add_variation',
|
|
|
|
post_id: woocommerce_admin_meta_boxes_variations.post_id,
|
|
|
|
loop: loop,
|
|
|
|
security: woocommerce_admin_meta_boxes_variations.add_variation_nonce
|
|
|
|
};
|
|
|
|
|
2014-02-14 20:49:36 +00:00
|
|
|
$.post( woocommerce_admin_meta_boxes_variations.ajax_url, data, function ( response ) {
|
2013-08-06 10:41:20 +00:00
|
|
|
|
2014-02-14 20:49:36 +00:00
|
|
|
$( '.woocommerce_variations' ).append( response );
|
2013-08-06 10:41:20 +00:00
|
|
|
|
2014-02-14 20:49:36 +00:00
|
|
|
$( '.tips' ).tipTip({
|
|
|
|
'attribute': 'data-tip',
|
|
|
|
'fadeIn': 50,
|
|
|
|
'fadeOut': 50
|
2014-02-14 20:28:23 +00:00
|
|
|
});
|
2013-08-06 10:41:20 +00:00
|
|
|
|
2014-06-19 15:17:43 +00:00
|
|
|
$( 'input.variable_is_downloadable, input.variable_is_virtual, input.variable_manage_stock' ).change();
|
2013-08-06 10:41:20 +00:00
|
|
|
|
2014-02-14 20:49:36 +00:00
|
|
|
$( '.woocommerce_variations' ).unblock();
|
|
|
|
$( '#variable_product_options' ).trigger( 'woocommerce_variations_added' );
|
2013-08-06 10:41:20 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
});
|
|
|
|
|
2014-02-14 20:49:36 +00:00
|
|
|
$( '#variable_product_options').on( 'click', 'button.link_all_variations', function () {
|
2013-08-06 10:41:20 +00:00
|
|
|
|
2014-02-14 20:49:36 +00:00
|
|
|
var answer = window.confirm( woocommerce_admin_meta_boxes_variations.i18n_link_all_variations );
|
2013-08-06 10:41:20 +00:00
|
|
|
|
2014-02-14 20:49:36 +00:00
|
|
|
if ( answer ) {
|
2013-08-06 10:41:20 +00:00
|
|
|
|
2014-02-14 20:49:36 +00:00
|
|
|
$( '#variable_product_options' ).block({
|
|
|
|
message: null,
|
|
|
|
overlayCSS: {
|
|
|
|
background: '#fff url(' + woocommerce_admin_meta_boxes_variations.plugin_url + '/assets/images/ajax-loader.gif) no-repeat center',
|
|
|
|
opacity: 0.6
|
|
|
|
}
|
|
|
|
});
|
2013-08-06 10:41:20 +00:00
|
|
|
|
|
|
|
var data = {
|
|
|
|
action: 'woocommerce_link_all_variations',
|
|
|
|
post_id: woocommerce_admin_meta_boxes_variations.post_id,
|
|
|
|
security: woocommerce_admin_meta_boxes_variations.link_variation_nonce
|
|
|
|
};
|
|
|
|
|
2014-02-14 20:49:36 +00:00
|
|
|
$.post( woocommerce_admin_meta_boxes_variations.ajax_url, data, function ( response ) {
|
2013-08-06 10:41:20 +00:00
|
|
|
|
2014-02-14 20:49:36 +00:00
|
|
|
var count = parseInt( response, 10 );
|
2013-08-06 10:41:20 +00:00
|
|
|
|
2014-02-14 20:49:36 +00:00
|
|
|
if ( 1 === count ) {
|
|
|
|
window.alert( count + ' ' + woocommerce_admin_meta_boxes_variations.i18n_variation_added );
|
|
|
|
} else if ( 0 === count || count > 1 ) {
|
|
|
|
window.alert( count + ' ' + woocommerce_admin_meta_boxes_variations.i18n_variations_added );
|
2013-08-06 10:41:20 +00:00
|
|
|
} else {
|
2014-02-14 20:49:36 +00:00
|
|
|
window.alert( woocommerce_admin_meta_boxes_variations.i18n_no_variations_added );
|
2013-08-06 10:41:20 +00:00
|
|
|
}
|
|
|
|
|
2014-02-14 20:49:36 +00:00
|
|
|
if ( count > 0 ) {
|
2013-08-06 10:41:20 +00:00
|
|
|
var this_page = window.location.toString();
|
|
|
|
|
|
|
|
this_page = this_page.replace( 'post-new.php?', 'post.php?post=' + woocommerce_admin_meta_boxes_variations.post_id + '&action=edit&' );
|
|
|
|
|
2014-02-14 20:49:36 +00:00
|
|
|
$( '#variable_product_options' ).load( this_page + ' #variable_product_options_inner', function () {
|
|
|
|
$( '#variable_product_options' ).unblock();
|
|
|
|
$( '#variable_product_options' ).trigger( 'woocommerce_variations_added' );
|
2014-02-14 20:24:48 +00:00
|
|
|
|
2014-02-14 20:49:36 +00:00
|
|
|
$( '.tips' ).tipTip({
|
|
|
|
'attribute': 'data-tip',
|
|
|
|
'fadeIn': 50,
|
|
|
|
'fadeOut': 50
|
2014-02-14 20:28:23 +00:00
|
|
|
});
|
2013-08-06 10:41:20 +00:00
|
|
|
} );
|
|
|
|
} else {
|
2014-02-14 20:49:36 +00:00
|
|
|
$( '#variable_product_options' ).unblock();
|
2013-08-06 10:41:20 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
});
|
|
|
|
|
2014-02-14 20:49:36 +00:00
|
|
|
$( '#variable_product_options' ).on( 'click', 'button.remove_variation', function ( e ) {
|
2013-08-06 10:41:20 +00:00
|
|
|
e.preventDefault();
|
2014-02-14 20:49:36 +00:00
|
|
|
var answer = window.confirm( woocommerce_admin_meta_boxes_variations.i18n_remove_variation );
|
|
|
|
if ( answer ) {
|
2013-08-06 10:41:20 +00:00
|
|
|
|
2014-02-14 20:49:36 +00:00
|
|
|
var el = $( this ).parent().parent();
|
2013-08-06 10:41:20 +00:00
|
|
|
|
2014-02-14 20:49:36 +00:00
|
|
|
var variation = $( this ).attr( 'rel' );
|
2013-08-06 10:41:20 +00:00
|
|
|
|
2014-02-14 20:49:36 +00:00
|
|
|
if ( variation > 0 ) {
|
2013-08-06 10:41:20 +00:00
|
|
|
|
2014-02-14 20:49:36 +00:00
|
|
|
$( el ).block({
|
|
|
|
message: null,
|
|
|
|
overlayCSS: {
|
|
|
|
background: '#fff url(' + woocommerce_admin_meta_boxes_variations.plugin_url + '/assets/images/ajax-loader.gif) no-repeat center',
|
|
|
|
opacity: 0.6
|
|
|
|
}
|
|
|
|
});
|
2013-08-06 10:41:20 +00:00
|
|
|
|
|
|
|
var data = {
|
|
|
|
action: 'woocommerce_remove_variation',
|
|
|
|
variation_id: variation,
|
|
|
|
security: woocommerce_admin_meta_boxes_variations.delete_variation_nonce
|
|
|
|
};
|
|
|
|
|
2014-02-14 20:49:36 +00:00
|
|
|
$.post( woocommerce_admin_meta_boxes_variations.ajax_url, data, function ( response ) {
|
2013-08-06 10:41:20 +00:00
|
|
|
// Success
|
2014-02-14 20:49:36 +00:00
|
|
|
$( el ).fadeOut( '300', function () {
|
|
|
|
$( el ).remove();
|
2013-08-06 10:41:20 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
} else {
|
2014-02-14 20:49:36 +00:00
|
|
|
$( el ).fadeOut( '300', function () {
|
|
|
|
$( el ).remove();
|
2013-08-06 10:41:20 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
});
|
|
|
|
|
2014-02-14 20:49:36 +00:00
|
|
|
$( '.wc-metaboxes-wrapper' ).on( 'click', 'a.bulk_edit', function ( event ) {
|
|
|
|
var bulk_edit = $( 'select#field_to_edit' ).val(),
|
|
|
|
checkbox,
|
|
|
|
answer,
|
|
|
|
value;
|
2013-08-06 10:41:20 +00:00
|
|
|
|
2014-02-14 20:49:36 +00:00
|
|
|
switch ( bulk_edit ) {
|
|
|
|
case 'toggle_enabled' :
|
|
|
|
checkbox = $( 'input[name^="variable_enabled"]' );
|
|
|
|
checkbox.attr('checked', ! checkbox.attr( 'checked' ) );
|
2013-09-03 16:35:20 +00:00
|
|
|
break;
|
2014-02-14 20:49:36 +00:00
|
|
|
case 'toggle_downloadable' :
|
|
|
|
checkbox = $( 'input[name^="variable_is_downloadable"]' );
|
|
|
|
checkbox.attr( 'checked', ! checkbox.attr( 'checked' ) );
|
|
|
|
$('input.variable_is_downloadable').change();
|
2013-09-03 16:35:20 +00:00
|
|
|
break;
|
2014-02-14 20:49:36 +00:00
|
|
|
case 'toggle_virtual' :
|
|
|
|
checkbox = $('input[name^="variable_is_virtual"]');
|
|
|
|
checkbox.attr( 'checked', ! checkbox.attr( 'checked' ) );
|
|
|
|
$( 'input.variable_is_virtual' ).change();
|
2013-09-03 16:35:20 +00:00
|
|
|
break;
|
2014-06-19 15:17:43 +00:00
|
|
|
case 'toggle_manage_stock' :
|
|
|
|
checkbox = $('input[name^="variable_manage_stock"]');
|
|
|
|
checkbox.attr( 'checked', ! checkbox.attr( 'checked' ) );
|
|
|
|
$( 'input.variable_manage_stock' ).change();
|
|
|
|
break;
|
2014-02-14 20:49:36 +00:00
|
|
|
case 'delete_all' :
|
|
|
|
answer = window.confirm( woocommerce_admin_meta_boxes_variations.i18n_delete_all_variations );
|
2013-09-03 16:35:20 +00:00
|
|
|
|
2014-02-14 20:49:36 +00:00
|
|
|
if ( answer ) {
|
2013-08-06 10:41:20 +00:00
|
|
|
|
2014-02-14 20:49:36 +00:00
|
|
|
answer = window.confirm( woocommerce_admin_meta_boxes_variations.i18n_last_warning );
|
2013-08-06 10:41:20 +00:00
|
|
|
|
2014-02-14 20:49:36 +00:00
|
|
|
if ( answer ) {
|
2013-08-06 10:41:20 +00:00
|
|
|
|
|
|
|
var variation_ids = [];
|
|
|
|
|
2014-02-14 20:49:36 +00:00
|
|
|
$( '.woocommerce_variations .woocommerce_variation' ).block({
|
|
|
|
message: null,
|
|
|
|
overlayCSS: {
|
|
|
|
background: '#fff url(' + woocommerce_admin_meta_boxes_variations.plugin_url + '/assets/images/ajax-loader.gif) no-repeat center',
|
|
|
|
opacity: 0.6
|
|
|
|
}
|
|
|
|
});
|
2013-08-06 10:41:20 +00:00
|
|
|
|
2014-02-14 20:49:36 +00:00
|
|
|
$( '.woocommerce_variations .woocommerce_variation .remove_variation' ).each( function () {
|
2013-08-06 10:41:20 +00:00
|
|
|
|
2014-02-14 20:49:36 +00:00
|
|
|
var variation = $( this ).attr( 'rel' );
|
|
|
|
if ( variation > 0 ) {
|
|
|
|
variation_ids.push( variation );
|
2013-08-06 10:41:20 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
var data = {
|
|
|
|
action: 'woocommerce_remove_variations',
|
|
|
|
variation_ids: variation_ids,
|
|
|
|
security: woocommerce_admin_meta_boxes_variations.delete_variations_nonce
|
|
|
|
};
|
|
|
|
|
2014-02-14 20:49:36 +00:00
|
|
|
$.post( woocommerce_admin_meta_boxes_variations.ajax_url, data, function( response ) {
|
|
|
|
$( '.woocommerce_variations .woocommerce_variation' ).fadeOut( '300', function () {
|
|
|
|
$( '.woocommerce_variations .woocommerce_variation' ).remove();
|
2013-08-06 10:41:20 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
2013-09-03 16:35:20 +00:00
|
|
|
break;
|
2013-08-06 10:41:20 +00:00
|
|
|
case 'variable_regular_price_increase':
|
|
|
|
case 'variable_regular_price_decrease':
|
|
|
|
case 'variable_sale_price_increase':
|
2013-09-03 16:35:20 +00:00
|
|
|
case 'variable_sale_price_decrease':
|
2014-02-14 20:49:36 +00:00
|
|
|
var edit_field;
|
|
|
|
if ( bulk_edit.lastIndexOf( 'variable_regular_price', 0 ) === 0 ) {
|
|
|
|
edit_field = 'variable_regular_price';
|
|
|
|
} else {
|
|
|
|
edit_field = 'variable_sale_price';
|
|
|
|
}
|
2013-08-06 10:41:20 +00:00
|
|
|
|
2014-03-06 13:03:12 +00:00
|
|
|
value = window.prompt( woocommerce_admin_meta_boxes_variations.i18n_enter_a_value_fixed_or_percent ).toString();
|
2013-08-06 10:41:20 +00:00
|
|
|
|
2014-03-06 13:03:12 +00:00
|
|
|
$( ':input[name^="' + edit_field + '"]' ).each( function() {
|
|
|
|
var current_value = Number( $( this ).val() ), new_value;
|
2013-08-06 10:41:20 +00:00
|
|
|
|
2014-03-06 13:03:12 +00:00
|
|
|
if ( value.indexOf( '%' ) >= 0 ) {
|
|
|
|
var mod_value = Number( ( Number( current_value ) / 100 ) * Number( value.replace(/\%/, '' ) ) );
|
2014-02-14 20:49:36 +00:00
|
|
|
} else {
|
2014-03-06 13:03:12 +00:00
|
|
|
var mod_value = Number( value );
|
2014-02-14 20:49:36 +00:00
|
|
|
}
|
2013-09-03 16:35:20 +00:00
|
|
|
|
2014-02-14 20:49:36 +00:00
|
|
|
if ( bulk_edit.indexOf( 'increase' ) !== -1 ) {
|
2014-03-06 13:03:12 +00:00
|
|
|
new_value = current_value + mod_value;
|
2014-02-14 20:49:36 +00:00
|
|
|
} else {
|
2014-03-06 13:03:12 +00:00
|
|
|
new_value = current_value - mod_value;
|
2014-02-14 20:49:36 +00:00
|
|
|
}
|
2013-08-06 10:41:20 +00:00
|
|
|
|
2014-02-14 20:49:36 +00:00
|
|
|
$( this ).val( new_value ).change();
|
2013-08-06 10:41:20 +00:00
|
|
|
});
|
2013-09-03 16:35:20 +00:00
|
|
|
break;
|
2013-08-06 10:41:20 +00:00
|
|
|
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' :
|
2014-02-14 20:49:36 +00:00
|
|
|
value = window.prompt( woocommerce_admin_meta_boxes_variations.i18n_enter_a_value );
|
2013-08-06 10:41:20 +00:00
|
|
|
|
2014-03-18 12:51:10 +00:00
|
|
|
$( ':input[name^="' + bulk_edit + '"]').not('[name*="dates"]').val( value ).change();
|
2013-09-03 16:35:20 +00:00
|
|
|
break;
|
2013-11-03 17:50:24 +00:00
|
|
|
default:
|
2014-02-14 20:49:36 +00:00
|
|
|
$( 'select#field_to_edit' ).trigger( bulk_edit );
|
2013-11-03 17:50:24 +00:00
|
|
|
break;
|
|
|
|
|
2013-09-03 16:35:20 +00:00
|
|
|
}
|
2013-08-06 10:41:20 +00:00
|
|
|
});
|
|
|
|
|
2014-02-14 20:49:36 +00:00
|
|
|
$( '#variable_product_options' ).on( 'change', 'input.variable_is_downloadable', function () {
|
|
|
|
$( this ).closest( '.woocommerce_variation' ).find( '.show_if_variation_downloadable' ).hide();
|
2013-08-06 10:41:20 +00:00
|
|
|
|
2014-02-14 20:49:36 +00:00
|
|
|
if ( $( this ).is( ':checked' ) ) {
|
|
|
|
$( this ).closest( '.woocommerce_variation' ).find( '.show_if_variation_downloadable' ).show();
|
2013-08-06 10:41:20 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2014-02-14 20:49:36 +00:00
|
|
|
$( '#variable_product_options' ).on( 'change', 'input.variable_is_virtual', function () {
|
|
|
|
$( this ).closest( '.woocommerce_variation' ).find( '.hide_if_variation_virtual' ).show();
|
2013-08-06 10:41:20 +00:00
|
|
|
|
2014-02-14 20:49:36 +00:00
|
|
|
if ( $( this ).is( ':checked' ) ) {
|
|
|
|
$( this ).closest( '.woocommerce_variation' ).find( '.hide_if_variation_virtual' ).hide();
|
2013-08-06 10:41:20 +00:00
|
|
|
}
|
2014-06-19 15:17:43 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
$( '#variable_product_options' ).on( 'change', 'input.variable_manage_stock', function () {
|
|
|
|
$( this ).closest( '.woocommerce_variation' ).find( '.show_if_variation_manage_stock' ).hide();
|
2013-08-06 10:41:20 +00:00
|
|
|
|
2014-06-19 15:17:43 +00:00
|
|
|
if ( $( this ).is( ':checked' ) ) {
|
|
|
|
$( this ).closest( '.woocommerce_variation' ).find( '.show_if_variation_manage_stock' ).show();
|
|
|
|
}
|
2013-08-06 10:41:20 +00:00
|
|
|
});
|
|
|
|
|
2014-06-19 15:17:43 +00:00
|
|
|
$( 'input.variable_is_downloadable, input.variable_is_virtual, input.variable_manage_stock' ).change();
|
2013-08-06 10:41:20 +00:00
|
|
|
|
|
|
|
// Ordering
|
2014-02-14 20:49:36 +00:00
|
|
|
$( '#variable_product_options' ).on( 'woocommerce_variations_added', function () {
|
|
|
|
$( '.woocommerce_variations' ).sortable( variation_sortable_options );
|
2013-08-06 10:41:20 +00:00
|
|
|
} );
|
|
|
|
|
2014-02-14 20:49:36 +00:00
|
|
|
$( '.woocommerce_variations' ).sortable( variation_sortable_options );
|
2013-08-06 10:41:20 +00:00
|
|
|
|
|
|
|
function variation_row_indexes() {
|
2014-02-14 20:49:36 +00:00
|
|
|
$( '.woocommerce_variations .woocommerce_variation' ).each( function ( index, el ) {
|
|
|
|
$( '.variation_menu_order', el ).val( parseInt( $( el ).index( '.woocommerce_variations .woocommerce_variation' ), 10 ) );
|
2013-08-06 10:41:20 +00:00
|
|
|
});
|
2014-02-14 20:49:36 +00:00
|
|
|
}
|
2013-08-06 10:41:20 +00:00
|
|
|
|
|
|
|
// 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;
|
|
|
|
|
2014-02-14 20:49:36 +00:00
|
|
|
$( '#variable_product_options' ).on( 'click', '.upload_image_button', function ( event ) {
|
2013-08-06 10:41:20 +00:00
|
|
|
|
2014-02-14 20:49:36 +00:00
|
|
|
var $button = $( this );
|
|
|
|
var post_id = $button.attr( 'rel' );
|
|
|
|
var $parent = $button.closest( '.upload_image' );
|
2013-08-06 10:41:20 +00:00
|
|
|
setting_variation_image = $parent;
|
|
|
|
setting_variation_image_id = post_id;
|
|
|
|
|
|
|
|
event.preventDefault();
|
|
|
|
|
2014-02-14 20:49:36 +00:00
|
|
|
if ( $button.is( '.remove' ) ) {
|
2013-08-06 10:41:20 +00:00
|
|
|
|
|
|
|
setting_variation_image.find( '.upload_image_id' ).val( '' );
|
2014-05-23 03:46:42 +00:00
|
|
|
setting_variation_image.find( 'img' ).eq( 0 ).attr( 'src', woocommerce_admin_meta_boxes_variations.woocommerce_placeholder_img_src );
|
2013-08-06 10:41:20 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
// 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
|
2014-01-08 00:38:54 +00:00
|
|
|
},
|
|
|
|
states : [
|
|
|
|
new wp.media.controller.Library({
|
|
|
|
title: woocommerce_admin_meta_boxes_variations.i18n_choose_image,
|
|
|
|
filterable : 'all'
|
|
|
|
})
|
|
|
|
]
|
2013-08-06 10:41:20 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
// When an image is selected, run a callback.
|
2014-02-14 20:49:36 +00:00
|
|
|
variable_image_frame.on( 'select', function () {
|
2013-08-06 10:41:20 +00:00
|
|
|
|
2014-05-23 14:29:08 +00:00
|
|
|
var attachment = variable_image_frame.state().get( 'selection' ).first().toJSON(),
|
|
|
|
url = attachment.sizes.thumbnail ? attachment.sizes.thumbnail.url : attachment.url;
|
2013-08-06 10:41:20 +00:00
|
|
|
|
|
|
|
setting_variation_image.find( '.upload_image_id' ).val( attachment.id );
|
|
|
|
setting_variation_image.find( '.upload_image_button' ).addClass( 'remove' );
|
2014-05-23 14:29:08 +00:00
|
|
|
setting_variation_image.find( 'img' ).eq( 0 ).attr( 'src', url );
|
2013-08-06 10:41:20 +00:00
|
|
|
|
|
|
|
wp.media.model.settings.post.id = wp_media_post_id;
|
|
|
|
});
|
|
|
|
|
|
|
|
// Finally, open the modal.
|
|
|
|
variable_image_frame.open();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
// Restore ID
|
2014-02-14 20:49:36 +00:00
|
|
|
$( 'a.add_media' ).on(' click', function () {
|
2013-08-06 10:41:20 +00:00
|
|
|
wp.media.model.settings.post.id = wp_media_post_id;
|
2014-02-14 20:49:36 +00:00
|
|
|
});
|
2013-08-06 10:41:20 +00:00
|
|
|
|
2014-02-14 20:24:48 +00:00
|
|
|
});
|