More UI / Split up meta box scripts

This commit is contained in:
Mike Jolley 2014-07-08 14:14:29 +01:00
parent 5c0ea16a39
commit 2282d76efb
13 changed files with 720 additions and 870 deletions

File diff suppressed because one or more lines are too long

View File

@ -660,7 +660,7 @@ ul.wc_coupon_list_block {
display: inline-block;
vertical-align: top;
}
input, .total {
input.text, .total, .checkbox {
font-size: 1em !important;
width: 10em;
display: inline-block;

View File

@ -0,0 +1,17 @@
jQuery( function($){
// Coupon type options
$('select#discount_type').change(function(){
// Get value
var select_val = $(this).val();
if ( select_val == 'fixed_product' || select_val == 'percent_product' ) {
$('.limit_usage_to_x_items_field').show();
} else {
$('.limit_usage_to_x_items_field').hide();
}
}).change();
});

View File

@ -0,0 +1 @@
jQuery(function(a){a("select#discount_type").change(function(){var b=a(this).val();"fixed_product"==b||"percent_product"==b?a(".limit_usage_to_x_items_field").show():a(".limit_usage_to_x_items_field").hide()}).change()});

View File

@ -1,89 +1,4 @@
jQuery( function($){
// run tip tip
function runTipTip() {
// remove any lingering tooltips
$( '#tiptip_holder' ).removeAttr( 'style' );
$( '#tiptip_arrow' ).removeAttr( 'style' );
// init tiptip
$( '.tips' ).tipTip({
'attribute': 'data-tip',
'fadeIn': 50,
'fadeOut': 50,
'delay': 200
});
}
runTipTip();
// Allow tabbing
$('#titlediv #title').keyup(function( event ) {
var code = event.keyCode || event.which;
if ( code == '9' && $('#woocommerce-coupon-description').size() > 0 ) {
event.stopPropagation();
$('#woocommerce-coupon-description').focus();
return false;
}
});
// Coupon type options
$('select#discount_type').change(function(){
// Get value
var select_val = $(this).val();
if ( select_val == 'fixed_product' || select_val == 'percent_product' ) {
$('.limit_usage_to_x_items_field').show();
} else {
$('.limit_usage_to_x_items_field').hide();
}
}).change();
// Scroll to first checked category - https://github.com/scribu/wp-category-checklist-tree/blob/d1c3c1f449e1144542efa17dde84a9f52ade1739/category-checklist-tree.php
$(function(){
$('[id$="-all"] > ul.categorychecklist').each(function() {
var $list = $(this);
var $firstChecked = $list.find(':checked').first();
if ( !$firstChecked.length )
return;
var pos_first = $list.find('input').position().top;
var pos_checked = $firstChecked.position().top;
$list.closest('.tabs-panel').scrollTop(pos_checked - pos_first + 5);
});
});
// Prevent enter submitting post form
$("#upsell_product_data").bind("keypress", function(e) {
if (e.keyCode == 13) return false;
});
// Type box
$('.type_box').appendTo( '#woocommerce-product-data h3.hndle span' );
$(function(){
// Prevent inputs in meta box headings opening/closing contents
$('#woocommerce-product-data h3.hndle').unbind('click.postboxes');
jQuery('#woocommerce-product-data').on('click', 'h3.hndle', function(event){
// If the user clicks on some form input inside the h3 the box should not be toggled
if ( $(event.target).filter('input, option, label, select').length )
return;
$('#woocommerce-product-data').toggleClass('closed');
});
});
$(function(){
jQuery('.wc-metabox > h3').click( function(event){
$( this ).parent( '.wc-metabox' ).toggleClass( 'closed' ).toggleClass( 'open' );
});
});
// Order emails
$('#order-emails a.show-order-emails').click(function () {
@ -104,134 +19,6 @@ jQuery( function($){
return false;
});
// Catalog Visibility
$('#catalog-visibility .edit-catalog-visibility').click(function () {
if ($('#catalog-visibility-select').is(":hidden")) {
$('#catalog-visibility-select').slideDown('fast');
$(this).hide();
}
return false;
});
$('#catalog-visibility .save-post-visibility').click(function () {
$('#catalog-visibility-select').slideUp('fast');
$('#catalog-visibility .edit-catalog-visibility').show();
var value = $('input[name=_visibility]:checked').val();
var label = $('input[name=_visibility]:checked').attr('data-label');
if ( $('input[name=_featured]').is(':checked') ) {
label = label + ', ' + woocommerce_admin_meta_boxes.featured_label
$('input[name=_featured]').attr('checked', 'checked');
}
$('#catalog-visibility-display').text( label );
return false;
});
$('#catalog-visibility .cancel-post-visibility').click(function () {
$('#catalog-visibility-select').slideUp('fast');
$('#catalog-visibility .edit-catalog-visibility').show();
var current_visibility = $('#current_visibility').val();
var current_featured = $('#current_featured').val();
$('input[name=_visibility]').removeAttr('checked');
$('input[name=_visibility][value=' + current_visibility + ']').attr('checked', 'checked');
var label = $('input[name=_visibility]:checked').attr('data-label');
if ( current_featured == 'yes' ) {
label = label + ', ' + woocommerce_admin_meta_boxes.featured_label
$('input[name=_featured]').attr('checked', 'checked');
} else {
$('input[name=_featured]').removeAttr('checked');
}
$('#catalog-visibility-display').text( label );
return false;
});
// TABS
$('ul.wc-tabs').show();
$('div.panel-wrap').each(function(){
$(this).find('div.panel:not(:first)').hide();
});
$('ul.wc-tabs a').click(function(){
var panel_wrap = $(this).closest('div.panel-wrap');
$('ul.wc-tabs li', panel_wrap).removeClass('active');
$(this).parent().addClass('active');
$('div.panel', panel_wrap).hide();
$( $(this).attr('href') ).show();
return false;
});
// Chosen selects
jQuery("select.chosen_select").chosen();
jQuery("select.chosen_select_nostd").chosen({
allow_single_deselect: 'true'
});
// Ajax Chosen Product Selectors
jQuery("select.ajax_chosen_select_products").ajaxChosen({
method: 'GET',
url: woocommerce_admin_meta_boxes.ajax_url,
dataType: 'json',
afterTypeDelay: 100,
data: {
action: 'woocommerce_json_search_products',
security: woocommerce_admin_meta_boxes.search_products_nonce
}
}, function (data) {
var terms = {};
$.each(data, function (i, val) {
terms[i] = val;
});
return terms;
});
jQuery("select.ajax_chosen_select_products_and_variations").ajaxChosen({
method: 'GET',
url: woocommerce_admin_meta_boxes.ajax_url,
dataType: 'json',
afterTypeDelay: 100,
data: {
action: 'woocommerce_json_search_products_and_variations',
security: woocommerce_admin_meta_boxes.search_products_nonce
}
}, function (data) {
var terms = {};
$.each(data, function (i, val) {
terms[i] = val;
});
return terms;
});
jQuery("select.ajax_chosen_select_downloadable_products_and_variations").ajaxChosen({
method: 'GET',
url: woocommerce_admin_meta_boxes.ajax_url,
dataType: 'json',
afterTypeDelay: 100,
data: {
action: 'woocommerce_json_search_downloadable_products_and_variations',
security: woocommerce_admin_meta_boxes.search_products_nonce
}
}, function (data) {
var terms = {};
$.each(data, function (i, val) {
terms[i] = val;
});
return terms;
});
// ORDERS
jQuery('#woocommerce-order-actions input, #woocommerce-order-actions a').click(function(){
window.onbeforeunload = '';
@ -1095,607 +882,5 @@ jQuery( function($){
});
return false;
});
// PRODUCT TYPE SPECIFIC OPTIONS
$('select#product-type').change(function(){
// Get value
var select_val = $(this).val();
if (select_val=='variable') {
$('input#_manage_stock').change();
$('input#_downloadable').prop('checked', false);
$('input#_virtual').removeAttr('checked');
}
else if (select_val=='grouped') {
$('input#_downloadable').prop('checked', false);
$('input#_virtual').removeAttr('checked');
}
else if (select_val=='external') {
$('input#_downloadable').prop('checked', false);
$('input#_virtual').removeAttr('checked');
}
show_and_hide_panels();
$('ul.wc-tabs li:visible').eq(0).find('a').click();
$('body').trigger('woocommerce-product-type-change', select_val, $(this) );
}).change();
$('ul.wc-tabs li:visible').eq(0).find('a').click();
$('input#_downloadable, input#_virtual').change(function(){
show_and_hide_panels();
});
function show_and_hide_panels() {
var product_type = $('select#product-type').val();
var is_virtual = $('input#_virtual:checked').size();
var is_downloadable = $('input#_downloadable:checked').size();
// Hide/Show all with rules
var hide_classes = '.hide_if_downloadable, .hide_if_virtual';
var show_classes = '.show_if_downloadable, .show_if_virtual, .show_if_external';
$.each( woocommerce_admin_meta_boxes.product_types, function( index, value ) {
hide_classes = hide_classes + ', .hide_if_' + value;
show_classes = show_classes + ', .show_if_' + value;
} );
$( hide_classes ).show();
$( show_classes ).hide();
// Shows rules
if ( is_downloadable ) {
$('.show_if_downloadable').show();
}
if ( is_virtual ) {
$('.show_if_virtual').show();
}
$('.show_if_' + product_type).show();
// Hide rules
if ( is_downloadable ) {
$('.hide_if_downloadable').hide();
}
if ( is_virtual ) {
$('.hide_if_virtual').hide();
}
$('.hide_if_' + product_type).hide();
$('input#_manage_stock').change();
}
// Sale price schedule
$('.sale_price_dates_fields').each(function() {
var $these_sale_dates = $(this);
var sale_schedule_set = false;
var $wrap = $these_sale_dates.closest( 'div, table' );
$these_sale_dates.find('input').each(function(){
if ( $(this).val() != '' )
sale_schedule_set = true;
});
if ( sale_schedule_set ) {
$wrap.find('.sale_schedule').hide();
$wrap.find('.sale_price_dates_fields').show();
} else {
$wrap.find('.sale_schedule').show();
$wrap.find('.sale_price_dates_fields').hide();
}
});
$('#woocommerce-product-data').on( 'click', '.sale_schedule', function() {
var $wrap = $(this).closest( 'div, table' );
$(this).hide();
$wrap.find('.cancel_sale_schedule').show();
$wrap.find('.sale_price_dates_fields').show();
return false;
});
$('#woocommerce-product-data').on( 'click', '.cancel_sale_schedule', function() {
var $wrap = $(this).closest( 'div, table' );
$(this).hide();
$wrap.find('.sale_schedule').show();
$wrap.find('.sale_price_dates_fields').hide();
$wrap.find('.sale_price_dates_fields').find('input').val('');
return false;
});
// File inputs
$('#woocommerce-product-data').on('click','.downloadable_files a.insert',function(){
$(this).closest('.downloadable_files').find('tbody').append( $(this).data( 'row' ) );
return false;
});
$('#woocommerce-product-data').on('click','.downloadable_files a.delete',function(){
$(this).closest('tr').remove();
return false;
});
// STOCK OPTIONS
$('input#_manage_stock').change(function(){
if ( $(this).is(':checked') ) {
$('div.stock_fields').show();
} else {
$('div.stock_fields').hide();
}
}).change();
// DATE PICKER FIELDS
var dates = $( ".sale_price_dates_fields input" ).datepicker({
defaultDate: "",
dateFormat: "yy-mm-dd",
numberOfMonths: 1,
showButtonPanel: true,
showOn: "button",
buttonImage: woocommerce_admin_meta_boxes.calendar_image,
buttonImageOnly: true,
onSelect: function( selectedDate ) {
var option = $(this).is('#_sale_price_dates_from, .sale_price_dates_from') ? "minDate" : "maxDate";
var instance = $( this ).data( "datepicker" ),
date = $.datepicker.parseDate(
instance.settings.dateFormat ||
$.datepicker._defaults.dateFormat,
selectedDate, instance.settings );
dates.not( this ).datepicker( "option", option, date );
}
});
$( ".date-picker" ).datepicker({
dateFormat: "yy-mm-dd",
numberOfMonths: 1,
showButtonPanel: true,
showOn: "button",
buttonImage: woocommerce_admin_meta_boxes.calendar_image,
buttonImageOnly: true
});
$( ".date-picker-field" ).datepicker({
dateFormat: "yy-mm-dd",
numberOfMonths: 1,
showButtonPanel: true,
});
// META BOXES
// Open/close
jQuery('.wc-metaboxes-wrapper').on('click', '.wc-metabox h3', function(event){
// If the user clicks on some form input inside the h3, like a select list (for variations), the box should not be toggled
if ($(event.target).filter(':input, option').length) return;
jQuery(this).next('.wc-metabox-content').toggle();
})
.on('click', '.expand_all', function(event){
jQuery(this).closest('.wc-metaboxes-wrapper').find('.wc-metabox > table').show();
return false;
})
.on('click', '.close_all', function(event){
jQuery(this).closest('.wc-metaboxes-wrapper').find('.wc-metabox > table').hide();
return false;
});
jQuery('.wc-metabox.closed').each(function(){
jQuery(this).find('.wc-metabox-content').hide();
});
// ATTRIBUTE TABLES
// Multiselect attributes
$(".product_attributes select.multiselect").chosen();
// Initial order
var woocommerce_attribute_items = $('.product_attributes').find('.woocommerce_attribute').get();
woocommerce_attribute_items.sort(function(a, b) {
var compA = parseInt($(a).attr('rel'));
var compB = parseInt($(b).attr('rel'));
return (compA < compB) ? -1 : (compA > compB) ? 1 : 0;
})
$(woocommerce_attribute_items).each( function(idx, itm) { $('.product_attributes').append(itm); } );
function attribute_row_indexes() {
$('.product_attributes .woocommerce_attribute').each(function(index, el){
$('.attribute_position', el).val( parseInt( $(el).index('.product_attributes .woocommerce_attribute') ) );
});
};
// Add rows
$('button.add_attribute').on('click', function(){
var size = $('.product_attributes .woocommerce_attribute').size();
var attribute_type = $('select.attribute_taxonomy').val();
if (!attribute_type) {
var product_type = $('select#product-type').val();
if (product_type!='variable') enable_variation = 'style="display:none;"'; else enable_variation = '';
// Add custom attribute row
$('.product_attributes').append('<div class="woocommerce_attribute wc-metabox">\
<h3>\
<button type="button" class="remove_row button">' + woocommerce_admin_meta_boxes.remove_label + '</button>\
<div class="handlediv" title="' + woocommerce_admin_meta_boxes.click_to_toggle + '"></div>\
<strong class="attribute_name"></strong>\
</h3>\
<table cellpadding="0" cellspacing="0" class="woocommerce_attribute_data">\
<tbody>\
<tr>\
<td class="attribute_name">\
<label>' + woocommerce_admin_meta_boxes.name_label + ':</label>\
<input type="text" class="attribute_name" name="attribute_names[' + size + ']" />\
<input type="hidden" name="attribute_is_taxonomy[' + size + ']" value="0" />\
<input type="hidden" name="attribute_position[' + size + ']" class="attribute_position" value="' + size + '" />\
</td>\
<td rowspan="3">\
<label>' + woocommerce_admin_meta_boxes.values_label + ':</label>\
<textarea name="attribute_values[' + size + ']" cols="5" rows="5" placeholder="' + woocommerce_admin_meta_boxes.text_attribute_tip + '"></textarea>\
</td>\
</tr>\
<tr>\
<td>\
<label><input type="checkbox" class="checkbox" ' + ( woocommerce_admin_meta_boxes.default_attribute_visibility ? 'checked="checked"' : '' ) + ' name="attribute_visibility[' + size + ']" value="1" /> ' + woocommerce_admin_meta_boxes.visible_label + '</label>\
</td>\
</tr>\
<tr>\
<td>\
<div class="enable_variation show_if_variable" ' + enable_variation + '>\
<label><input type="checkbox" class="checkbox" ' + ( woocommerce_admin_meta_boxes.default_attribute_variation ? 'checked="checked"' : '' ) + ' name="attribute_variation[' + size + ']" value="1" /> ' + woocommerce_admin_meta_boxes.used_for_variations_label + '</label>\
</div>\
</td>\
</tr>\
</tbody>\
</table>\
</div>');
} else {
// Reveal taxonomy row
var thisrow = $('.product_attributes .woocommerce_attribute.' + attribute_type);
$('.product_attributes').append( $(thisrow) );
$(thisrow).show().find('.woocommerce_attribute_data').show();
attribute_row_indexes();
}
$('select.attribute_taxonomy').val('');
});
$('.product_attributes').on('blur', 'input.attribute_name', function(){
$(this).closest('.woocommerce_attribute').find('strong.attribute_name').text( $(this).val() );
});
$('.product_attributes').on('click', 'button.select_all_attributes', function(){
$(this).closest('td').find('select option').attr("selected","selected");
$(this).closest('td').find('select').trigger("chosen:updated");
return false;
});
$('.product_attributes').on('click', 'button.select_no_attributes', function(){
$(this).closest('td').find('select option').removeAttr("selected");
$(this).closest('td').find('select').trigger("chosen:updated");
return false;
});
$('.product_attributes').on('click', 'button.remove_row', function() {
var answer = confirm(woocommerce_admin_meta_boxes.remove_attribute);
if (answer){
var $parent = $(this).parent().parent();
if ($parent.is('.taxonomy')) {
$parent.find('select, input[type=text]').val('');
$parent.hide();
} else {
$parent.find('select, input[type=text]').val('');
$parent.hide();
attribute_row_indexes();
}
}
return false;
});
// Attribute ordering
$('.product_attributes').sortable({
items:'.woocommerce_attribute',
cursor:'move',
axis:'y',
handle: 'h3',
scrollSensitivity:40,
forcePlaceholderSize: true,
helper: 'clone',
opacity: 0.65,
placeholder: 'wc-metabox-sortable-placeholder',
start:function(event,ui){
ui.item.css('background-color','#f6f6f6');
},
stop:function(event,ui){
ui.item.removeAttr('style');
attribute_row_indexes();
}
});
// Add a new attribute (via ajax)
$('.product_attributes').on('click', 'button.add_new_attribute', function() {
$('.product_attributes').block({ message: null, overlayCSS: { background: '#fff url(' + woocommerce_admin_meta_boxes.plugin_url + '/assets/images/ajax-loader.gif) no-repeat center', opacity: 0.6 } });
var attribute = $(this).attr('data-attribute');
var $wrapper = $(this).closest('.woocommerce_attribute_data');
var new_attribute_name = prompt( woocommerce_admin_meta_boxes.new_attribute_prompt );
if ( new_attribute_name ) {
var data = {
action: 'woocommerce_add_new_attribute',
taxonomy: attribute,
term: new_attribute_name,
security: woocommerce_admin_meta_boxes.add_attribute_nonce
};
$.post( woocommerce_admin_meta_boxes.ajax_url, data, function( response ) {
if ( response.error ) {
// Error
alert( response.error );
} else if ( response.slug ) {
// Success
$wrapper.find('select.attribute_values').append('<option value="' + response.slug + '" selected="selected">' + response.name + '</option>');
$wrapper.find('select.attribute_values').trigger("chosen:updated");
}
$('.product_attributes').unblock();
});
} else {
$('.product_attributes').unblock();
}
return false;
});
// Save attributes and update variations
$('.save_attributes').on('click', function(){
$('.product_attributes').block({ message: null, overlayCSS: { background: '#fff url(' + woocommerce_admin_meta_boxes.plugin_url + '/assets/images/ajax-loader.gif) no-repeat center', opacity: 0.6 } });
var data = {
post_id: woocommerce_admin_meta_boxes.post_id,
data: $('.product_attributes').find('input, select, textarea').serialize(),
action: 'woocommerce_save_attributes',
security: woocommerce_admin_meta_boxes.save_attributes_nonce
};
$.post( woocommerce_admin_meta_boxes.ajax_url, data, function( response ) {
var this_page = window.location.toString();
this_page = this_page.replace( 'post-new.php?', 'post.php?post=' + woocommerce_admin_meta_boxes.post_id + '&action=edit&' );
// Load variations panel
$('#variable_product_options').block({ message: null, overlayCSS: { background: '#fff url(' + woocommerce_admin_meta_boxes.plugin_url + '/assets/images/ajax-loader.gif) no-repeat center', opacity: 0.6 } });
$('#variable_product_options').load( this_page + ' #variable_product_options_inner', function() {
$('#variable_product_options').unblock();
} );
$('.product_attributes').unblock();
});
});
// Uploading files
var downloadable_file_frame;
var file_path_field;
jQuery(document).on( 'click', '.upload_file_button', function( event ){
var $el = $(this);
file_path_field = $el.closest('tr').find('td.file_url input');
event.preventDefault();
// If the media frame already exists, reopen it.
if ( downloadable_file_frame ) {
downloadable_file_frame.open();
return;
}
var downloadable_file_states = [
// Main states.
new wp.media.controller.Library({
library: wp.media.query(),
multiple: true,
title: $el.data('choose'),
priority: 20,
filterable: 'uploaded',
})
];
// Create the media frame.
downloadable_file_frame = wp.media.frames.downloadable_file = wp.media({
// Set the title of the modal.
title: $el.data('choose'),
library: {
type: ''
},
button: {
text: $el.data('update'),
},
multiple: true,
states: downloadable_file_states,
});
// When an image is selected, run a callback.
downloadable_file_frame.on( 'select', function() {
var file_path = '';
var selection = downloadable_file_frame.state().get('selection');
selection.map( function( attachment ) {
attachment = attachment.toJSON();
if ( attachment.url )
file_path = attachment.url
} );
file_path_field.val( file_path );
});
// Set post to 0 and set our custom type
downloadable_file_frame.on( 'ready', function() {
downloadable_file_frame.uploader.options.uploader.params = {
type: 'downloadable_product'
};
});
// Finally, open the modal.
downloadable_file_frame.open();
});
// Download ordering
jQuery('.downloadable_files tbody').sortable({
items:'tr',
cursor:'move',
axis:'y',
handle: 'td.sort',
scrollSensitivity:40,
forcePlaceholderSize: true,
helper: 'clone',
opacity: 0.65,
});
// Product gallery file uploads
var product_gallery_frame;
var $image_gallery_ids = $('#product_image_gallery');
var $product_images = $('#product_images_container ul.product_images');
jQuery('.add_product_images').on( 'click', 'a', function( event ) {
var $el = $(this);
var attachment_ids = $image_gallery_ids.val();
event.preventDefault();
// If the media frame already exists, reopen it.
if ( product_gallery_frame ) {
product_gallery_frame.open();
return;
}
// Create the media frame.
product_gallery_frame = wp.media.frames.product_gallery = wp.media({
// Set the title of the modal.
title: $el.data('choose'),
button: {
text: $el.data('update'),
},
states : [
new wp.media.controller.Library({
title: $el.data('choose'),
filterable : 'all',
multiple: true,
})
]
});
// When an image is selected, run a callback.
product_gallery_frame.on( 'select', function() {
var selection = product_gallery_frame.state().get('selection');
selection.map( function( attachment ) {
attachment = attachment.toJSON();
if ( attachment.id ) {
attachment_ids = attachment_ids ? attachment_ids + "," + attachment.id : attachment.id;
$product_images.append('\
<li class="image" data-attachment_id="' + attachment.id + '">\
<img src="' + attachment.url + '" />\
<ul class="actions">\
<li><a href="#" class="delete" title="' + $el.data('delete') + '">' + $el.data('text') + '</a></li>\
</ul>\
</li>');
}
});
$image_gallery_ids.val( attachment_ids );
});
// Finally, open the modal.
product_gallery_frame.open();
});
// Image ordering
$product_images.sortable({
items: 'li.image',
cursor: 'move',
scrollSensitivity:40,
forcePlaceholderSize: true,
forceHelperSize: false,
helper: 'clone',
opacity: 0.65,
placeholder: 'wc-metabox-sortable-placeholder',
start:function(event,ui){
ui.item.css('background-color','#f6f6f6');
},
stop:function(event,ui){
ui.item.removeAttr('style');
},
update: function(event, ui) {
var attachment_ids = '';
$('#product_images_container ul li.image').css('cursor','default').each(function() {
var attachment_id = jQuery(this).attr( 'data-attachment_id' );
attachment_ids = attachment_ids + attachment_id + ',';
});
$image_gallery_ids.val( attachment_ids );
}
});
// Remove images
$('#product_images_container').on( 'click', 'a.delete', function() {
$(this).closest('li.image').remove();
var attachment_ids = '';
$('#product_images_container ul li.image').css('cursor','default').each(function() {
var attachment_id = jQuery(this).attr( 'data-attachment_id' );
attachment_ids = attachment_ids + attachment_id + ',';
});
$image_gallery_ids.val( attachment_ids );
runTipTip();
return false;
});
});
});
});

File diff suppressed because one or more lines are too long

View File

@ -0,0 +1,649 @@
jQuery( function($){
// Scroll to first checked category - https://github.com/scribu/wp-category-checklist-tree/blob/d1c3c1f449e1144542efa17dde84a9f52ade1739/category-checklist-tree.php
$(function(){
$('[id$="-all"] > ul.categorychecklist').each(function() {
var $list = $(this);
var $firstChecked = $list.find(':checked').first();
if ( !$firstChecked.length )
return;
var pos_first = $list.find('input').position().top;
var pos_checked = $firstChecked.position().top;
$list.closest('.tabs-panel').scrollTop(pos_checked - pos_first + 5);
});
});
// Prevent enter submitting post form
$("#upsell_product_data").bind("keypress", function(e) {
if (e.keyCode == 13) return false;
});
// Type box
$('.type_box').appendTo( '#woocommerce-product-data h3.hndle span' );
$(function(){
// Prevent inputs in meta box headings opening/closing contents
$('#woocommerce-product-data h3.hndle').unbind('click.postboxes');
jQuery('#woocommerce-product-data').on('click', 'h3.hndle', function(event){
// If the user clicks on some form input inside the h3 the box should not be toggled
if ( $(event.target).filter('input, option, label, select').length )
return;
$('#woocommerce-product-data').toggleClass('closed');
});
});
// Catalog Visibility
$('#catalog-visibility .edit-catalog-visibility').click(function () {
if ($('#catalog-visibility-select').is(":hidden")) {
$('#catalog-visibility-select').slideDown('fast');
$(this).hide();
}
return false;
});
$('#catalog-visibility .save-post-visibility').click(function () {
$('#catalog-visibility-select').slideUp('fast');
$('#catalog-visibility .edit-catalog-visibility').show();
var value = $('input[name=_visibility]:checked').val();
var label = $('input[name=_visibility]:checked').attr('data-label');
if ( $('input[name=_featured]').is(':checked') ) {
label = label + ', ' + woocommerce_admin_meta_boxes.featured_label
$('input[name=_featured]').attr('checked', 'checked');
}
$('#catalog-visibility-display').text( label );
return false;
});
$('#catalog-visibility .cancel-post-visibility').click(function () {
$('#catalog-visibility-select').slideUp('fast');
$('#catalog-visibility .edit-catalog-visibility').show();
var current_visibility = $('#current_visibility').val();
var current_featured = $('#current_featured').val();
$('input[name=_visibility]').removeAttr('checked');
$('input[name=_visibility][value=' + current_visibility + ']').attr('checked', 'checked');
var label = $('input[name=_visibility]:checked').attr('data-label');
if ( current_featured == 'yes' ) {
label = label + ', ' + woocommerce_admin_meta_boxes.featured_label
$('input[name=_featured]').attr('checked', 'checked');
} else {
$('input[name=_featured]').removeAttr('checked');
}
$('#catalog-visibility-display').text( label );
return false;
});
// PRODUCT TYPE SPECIFIC OPTIONS
$('select#product-type').change(function(){
// Get value
var select_val = $(this).val();
if (select_val=='variable') {
$('input#_manage_stock').change();
$('input#_downloadable').prop('checked', false);
$('input#_virtual').removeAttr('checked');
}
else if (select_val=='grouped') {
$('input#_downloadable').prop('checked', false);
$('input#_virtual').removeAttr('checked');
}
else if (select_val=='external') {
$('input#_downloadable').prop('checked', false);
$('input#_virtual').removeAttr('checked');
}
show_and_hide_panels();
$('ul.wc-tabs li:visible').eq(0).find('a').click();
$('body').trigger('woocommerce-product-type-change', select_val, $(this) );
}).change();
$('input#_downloadable, input#_virtual').change(function(){
show_and_hide_panels();
});
function show_and_hide_panels() {
var product_type = $('select#product-type').val();
var is_virtual = $('input#_virtual:checked').size();
var is_downloadable = $('input#_downloadable:checked').size();
// Hide/Show all with rules
var hide_classes = '.hide_if_downloadable, .hide_if_virtual';
var show_classes = '.show_if_downloadable, .show_if_virtual, .show_if_external';
$.each( woocommerce_admin_meta_boxes.product_types, function( index, value ) {
hide_classes = hide_classes + ', .hide_if_' + value;
show_classes = show_classes + ', .show_if_' + value;
} );
$( hide_classes ).show();
$( show_classes ).hide();
// Shows rules
if ( is_downloadable ) {
$('.show_if_downloadable').show();
}
if ( is_virtual ) {
$('.show_if_virtual').show();
}
$('.show_if_' + product_type).show();
// Hide rules
if ( is_downloadable ) {
$('.hide_if_downloadable').hide();
}
if ( is_virtual ) {
$('.hide_if_virtual').hide();
}
$('.hide_if_' + product_type).hide();
$('input#_manage_stock').change();
}
// Sale price schedule
$('.sale_price_dates_fields').each(function() {
var $these_sale_dates = $(this);
var sale_schedule_set = false;
var $wrap = $these_sale_dates.closest( 'div, table' );
$these_sale_dates.find('input').each(function(){
if ( $(this).val() != '' )
sale_schedule_set = true;
});
if ( sale_schedule_set ) {
$wrap.find('.sale_schedule').hide();
$wrap.find('.sale_price_dates_fields').show();
} else {
$wrap.find('.sale_schedule').show();
$wrap.find('.sale_price_dates_fields').hide();
}
});
$('#woocommerce-product-data').on( 'click', '.sale_schedule', function() {
var $wrap = $(this).closest( 'div, table' );
$(this).hide();
$wrap.find('.cancel_sale_schedule').show();
$wrap.find('.sale_price_dates_fields').show();
return false;
});
$('#woocommerce-product-data').on( 'click', '.cancel_sale_schedule', function() {
var $wrap = $(this).closest( 'div, table' );
$(this).hide();
$wrap.find('.sale_schedule').show();
$wrap.find('.sale_price_dates_fields').hide();
$wrap.find('.sale_price_dates_fields').find('input').val('');
return false;
});
// File inputs
$('#woocommerce-product-data').on('click','.downloadable_files a.insert',function(){
$(this).closest('.downloadable_files').find('tbody').append( $(this).data( 'row' ) );
return false;
});
$('#woocommerce-product-data').on('click','.downloadable_files a.delete',function(){
$(this).closest('tr').remove();
return false;
});
// STOCK OPTIONS
$('input#_manage_stock').change(function(){
if ( $(this).is(':checked') ) {
$('div.stock_fields').show();
} else {
$('div.stock_fields').hide();
}
}).change();
// DATE PICKER FIELDS
var dates = $( ".sale_price_dates_fields input" ).datepicker({
defaultDate: "",
dateFormat: "yy-mm-dd",
numberOfMonths: 1,
showButtonPanel: true,
showOn: "button",
buttonImage: woocommerce_admin_meta_boxes.calendar_image,
buttonImageOnly: true,
onSelect: function( selectedDate ) {
var option = $(this).is('#_sale_price_dates_from, .sale_price_dates_from') ? "minDate" : "maxDate";
var instance = $( this ).data( "datepicker" ),
date = $.datepicker.parseDate(
instance.settings.dateFormat ||
$.datepicker._defaults.dateFormat,
selectedDate, instance.settings );
dates.not( this ).datepicker( "option", option, date );
}
});
// ATTRIBUTE TABLES
// Multiselect attributes
$(".product_attributes select.multiselect").chosen();
// Initial order
var woocommerce_attribute_items = $('.product_attributes').find('.woocommerce_attribute').get();
woocommerce_attribute_items.sort(function(a, b) {
var compA = parseInt($(a).attr('rel'));
var compB = parseInt($(b).attr('rel'));
return (compA < compB) ? -1 : (compA > compB) ? 1 : 0;
})
$(woocommerce_attribute_items).each( function(idx, itm) { $('.product_attributes').append(itm); } );
function attribute_row_indexes() {
$('.product_attributes .woocommerce_attribute').each(function(index, el){
$('.attribute_position', el).val( parseInt( $(el).index('.product_attributes .woocommerce_attribute') ) );
});
};
// Add rows
$('button.add_attribute').on('click', function(){
var size = $('.product_attributes .woocommerce_attribute').size();
var attribute_type = $('select.attribute_taxonomy').val();
if (!attribute_type) {
var product_type = $('select#product-type').val();
if (product_type!='variable') enable_variation = 'style="display:none;"'; else enable_variation = '';
// Add custom attribute row
$('.product_attributes').append('<div class="woocommerce_attribute wc-metabox">\
<h3>\
<button type="button" class="remove_row button">' + woocommerce_admin_meta_boxes.remove_label + '</button>\
<div class="handlediv" title="' + woocommerce_admin_meta_boxes.click_to_toggle + '"></div>\
<strong class="attribute_name"></strong>\
</h3>\
<table cellpadding="0" cellspacing="0" class="woocommerce_attribute_data">\
<tbody>\
<tr>\
<td class="attribute_name">\
<label>' + woocommerce_admin_meta_boxes.name_label + ':</label>\
<input type="text" class="attribute_name" name="attribute_names[' + size + ']" />\
<input type="hidden" name="attribute_is_taxonomy[' + size + ']" value="0" />\
<input type="hidden" name="attribute_position[' + size + ']" class="attribute_position" value="' + size + '" />\
</td>\
<td rowspan="3">\
<label>' + woocommerce_admin_meta_boxes.values_label + ':</label>\
<textarea name="attribute_values[' + size + ']" cols="5" rows="5" placeholder="' + woocommerce_admin_meta_boxes.text_attribute_tip + '"></textarea>\
</td>\
</tr>\
<tr>\
<td>\
<label><input type="checkbox" class="checkbox" ' + ( woocommerce_admin_meta_boxes.default_attribute_visibility ? 'checked="checked"' : '' ) + ' name="attribute_visibility[' + size + ']" value="1" /> ' + woocommerce_admin_meta_boxes.visible_label + '</label>\
</td>\
</tr>\
<tr>\
<td>\
<div class="enable_variation show_if_variable" ' + enable_variation + '>\
<label><input type="checkbox" class="checkbox" ' + ( woocommerce_admin_meta_boxes.default_attribute_variation ? 'checked="checked"' : '' ) + ' name="attribute_variation[' + size + ']" value="1" /> ' + woocommerce_admin_meta_boxes.used_for_variations_label + '</label>\
</div>\
</td>\
</tr>\
</tbody>\
</table>\
</div>');
} else {
// Reveal taxonomy row
var thisrow = $('.product_attributes .woocommerce_attribute.' + attribute_type);
$('.product_attributes').append( $(thisrow) );
$(thisrow).show().find('.woocommerce_attribute_data').show();
attribute_row_indexes();
}
$('select.attribute_taxonomy').val('');
});
$('.product_attributes').on('blur', 'input.attribute_name', function(){
$(this).closest('.woocommerce_attribute').find('strong.attribute_name').text( $(this).val() );
});
$('.product_attributes').on('click', 'button.select_all_attributes', function(){
$(this).closest('td').find('select option').attr("selected","selected");
$(this).closest('td').find('select').trigger("chosen:updated");
return false;
});
$('.product_attributes').on('click', 'button.select_no_attributes', function(){
$(this).closest('td').find('select option').removeAttr("selected");
$(this).closest('td').find('select').trigger("chosen:updated");
return false;
});
$('.product_attributes').on('click', 'button.remove_row', function() {
var answer = confirm(woocommerce_admin_meta_boxes.remove_attribute);
if (answer){
var $parent = $(this).parent().parent();
if ($parent.is('.taxonomy')) {
$parent.find('select, input[type=text]').val('');
$parent.hide();
} else {
$parent.find('select, input[type=text]').val('');
$parent.hide();
attribute_row_indexes();
}
}
return false;
});
// Attribute ordering
$('.product_attributes').sortable({
items:'.woocommerce_attribute',
cursor:'move',
axis:'y',
handle: 'h3',
scrollSensitivity:40,
forcePlaceholderSize: true,
helper: 'clone',
opacity: 0.65,
placeholder: 'wc-metabox-sortable-placeholder',
start:function(event,ui){
ui.item.css('background-color','#f6f6f6');
},
stop:function(event,ui){
ui.item.removeAttr('style');
attribute_row_indexes();
}
});
// Add a new attribute (via ajax)
$('.product_attributes').on('click', 'button.add_new_attribute', function() {
$('.product_attributes').block({ message: null, overlayCSS: { background: '#fff url(' + woocommerce_admin_meta_boxes.plugin_url + '/assets/images/ajax-loader.gif) no-repeat center', opacity: 0.6 } });
var attribute = $(this).attr('data-attribute');
var $wrapper = $(this).closest('.woocommerce_attribute_data');
var new_attribute_name = prompt( woocommerce_admin_meta_boxes.new_attribute_prompt );
if ( new_attribute_name ) {
var data = {
action: 'woocommerce_add_new_attribute',
taxonomy: attribute,
term: new_attribute_name,
security: woocommerce_admin_meta_boxes.add_attribute_nonce
};
$.post( woocommerce_admin_meta_boxes.ajax_url, data, function( response ) {
if ( response.error ) {
// Error
alert( response.error );
} else if ( response.slug ) {
// Success
$wrapper.find('select.attribute_values').append('<option value="' + response.slug + '" selected="selected">' + response.name + '</option>');
$wrapper.find('select.attribute_values').trigger("chosen:updated");
}
$('.product_attributes').unblock();
});
} else {
$('.product_attributes').unblock();
}
return false;
});
// Save attributes and update variations
$('.save_attributes').on('click', function(){
$('.product_attributes').block({ message: null, overlayCSS: { background: '#fff url(' + woocommerce_admin_meta_boxes.plugin_url + '/assets/images/ajax-loader.gif) no-repeat center', opacity: 0.6 } });
var data = {
post_id: woocommerce_admin_meta_boxes.post_id,
data: $('.product_attributes').find('input, select, textarea').serialize(),
action: 'woocommerce_save_attributes',
security: woocommerce_admin_meta_boxes.save_attributes_nonce
};
$.post( woocommerce_admin_meta_boxes.ajax_url, data, function( response ) {
var this_page = window.location.toString();
this_page = this_page.replace( 'post-new.php?', 'post.php?post=' + woocommerce_admin_meta_boxes.post_id + '&action=edit&' );
// Load variations panel
$('#variable_product_options').block({ message: null, overlayCSS: { background: '#fff url(' + woocommerce_admin_meta_boxes.plugin_url + '/assets/images/ajax-loader.gif) no-repeat center', opacity: 0.6 } });
$('#variable_product_options').load( this_page + ' #variable_product_options_inner', function() {
$('#variable_product_options').unblock();
} );
$('.product_attributes').unblock();
});
});
// Uploading files
var downloadable_file_frame;
var file_path_field;
jQuery(document).on( 'click', '.upload_file_button', function( event ){
var $el = $(this);
file_path_field = $el.closest('tr').find('td.file_url input');
event.preventDefault();
// If the media frame already exists, reopen it.
if ( downloadable_file_frame ) {
downloadable_file_frame.open();
return;
}
var downloadable_file_states = [
// Main states.
new wp.media.controller.Library({
library: wp.media.query(),
multiple: true,
title: $el.data('choose'),
priority: 20,
filterable: 'uploaded',
})
];
// Create the media frame.
downloadable_file_frame = wp.media.frames.downloadable_file = wp.media({
// Set the title of the modal.
title: $el.data('choose'),
library: {
type: ''
},
button: {
text: $el.data('update'),
},
multiple: true,
states: downloadable_file_states,
});
// When an image is selected, run a callback.
downloadable_file_frame.on( 'select', function() {
var file_path = '';
var selection = downloadable_file_frame.state().get('selection');
selection.map( function( attachment ) {
attachment = attachment.toJSON();
if ( attachment.url )
file_path = attachment.url
} );
file_path_field.val( file_path );
});
// Set post to 0 and set our custom type
downloadable_file_frame.on( 'ready', function() {
downloadable_file_frame.uploader.options.uploader.params = {
type: 'downloadable_product'
};
});
// Finally, open the modal.
downloadable_file_frame.open();
});
// Download ordering
jQuery('.downloadable_files tbody').sortable({
items:'tr',
cursor:'move',
axis:'y',
handle: 'td.sort',
scrollSensitivity:40,
forcePlaceholderSize: true,
helper: 'clone',
opacity: 0.65,
});
// Product gallery file uploads
var product_gallery_frame;
var $image_gallery_ids = $('#product_image_gallery');
var $product_images = $('#product_images_container ul.product_images');
jQuery('.add_product_images').on( 'click', 'a', function( event ) {
var $el = $(this);
var attachment_ids = $image_gallery_ids.val();
event.preventDefault();
// If the media frame already exists, reopen it.
if ( product_gallery_frame ) {
product_gallery_frame.open();
return;
}
// Create the media frame.
product_gallery_frame = wp.media.frames.product_gallery = wp.media({
// Set the title of the modal.
title: $el.data('choose'),
button: {
text: $el.data('update'),
},
states : [
new wp.media.controller.Library({
title: $el.data('choose'),
filterable : 'all',
multiple: true,
})
]
});
// When an image is selected, run a callback.
product_gallery_frame.on( 'select', function() {
var selection = product_gallery_frame.state().get('selection');
selection.map( function( attachment ) {
attachment = attachment.toJSON();
if ( attachment.id ) {
attachment_ids = attachment_ids ? attachment_ids + "," + attachment.id : attachment.id;
$product_images.append('\
<li class="image" data-attachment_id="' + attachment.id + '">\
<img src="' + attachment.url + '" />\
<ul class="actions">\
<li><a href="#" class="delete" title="' + $el.data('delete') + '">' + $el.data('text') + '</a></li>\
</ul>\
</li>');
}
});
$image_gallery_ids.val( attachment_ids );
});
// Finally, open the modal.
product_gallery_frame.open();
});
// Image ordering
$product_images.sortable({
items: 'li.image',
cursor: 'move',
scrollSensitivity:40,
forcePlaceholderSize: true,
forceHelperSize: false,
helper: 'clone',
opacity: 0.65,
placeholder: 'wc-metabox-sortable-placeholder',
start:function(event,ui){
ui.item.css('background-color','#f6f6f6');
},
stop:function(event,ui){
ui.item.removeAttr('style');
},
update: function(event, ui) {
var attachment_ids = '';
$('#product_images_container ul li.image').css('cursor','default').each(function() {
var attachment_id = jQuery(this).attr( 'data-attachment_id' );
attachment_ids = attachment_ids + attachment_id + ',';
});
$image_gallery_ids.val( attachment_ids );
}
});
// Remove images
$('#product_images_container').on( 'click', 'a.delete', function() {
$(this).closest('li.image').remove();
var attachment_ids = '';
$('#product_images_container ul li.image').css('cursor','default').each(function() {
var attachment_id = jQuery(this).attr( 'data-attachment_id' );
attachment_ids = attachment_ids + attachment_id + ',';
});
$image_gallery_ids.val( attachment_ids );
runTipTip();
return false;
});
});

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -76,9 +76,7 @@ class WC_Admin_Assets {
wp_register_script( 'round', WC()->plugin_url() . '/assets/js/admin/round' . $suffix . '.js', array( 'jquery' ), WC_VERSION );
wp_register_script( 'woocommerce_admin_meta_boxes', WC()->plugin_url() . '/assets/js/admin/meta-boxes' . $suffix . '.js', array( 'jquery', 'jquery-ui-datepicker', 'jquery-ui-sortable', 'accounting', 'round' ), WC_VERSION );
wp_register_script( 'woocommerce_admin_meta_boxes_variations', WC()->plugin_url() . '/assets/js/admin/meta-boxes-variations' . $suffix . '.js', array( 'jquery', 'jquery-ui-sortable' ), WC_VERSION );
wp_register_script( 'wc-admin-meta-boxes', WC()->plugin_url() . '/assets/js/admin/meta-boxes' . $suffix . '.js', array( 'jquery', 'jquery-ui-datepicker', 'jquery-ui-sortable', 'accounting', 'round', 'ajax-chosen', 'chosen', 'plupload-all' ), WC_VERSION );
wp_register_script( 'ajax-chosen', WC()->plugin_url() . '/assets/js/chosen/ajax-chosen.jquery' . $suffix . '.js', array('jquery', 'chosen'), WC_VERSION );
@ -116,23 +114,52 @@ class WC_Admin_Assets {
}
// Edit product category pages
if ( in_array( $screen->id, array( 'edit-product_cat' ) ) )
if ( in_array( $screen->id, array( 'edit-product_cat' ) ) ) {
wp_enqueue_media();
}
// Products
if ( in_array( $screen->id, array( 'edit-product' ) ) )
if ( in_array( $screen->id, array( 'edit-product' ) ) ) {
wp_enqueue_script( 'woocommerce_quick-edit', WC()->plugin_url() . '/assets/js/admin/quick-edit' . $suffix . '.js', array('jquery'), WC_VERSION );
}
// Product/Coupon/Orders
if ( in_array( $screen->id, array( 'shop_coupon', 'shop_order', 'product', 'edit-shop_coupon', 'edit-shop_order', 'edit-product' ) ) ) {
wp_enqueue_script( 'woocommerce_admin_meta_boxes' );
wp_enqueue_script( 'jquery-ui-datepicker' );
// Meta boxes
if ( in_array( $screen->id, array( 'product', 'edit-product' ) ) ) {
wp_enqueue_media();
wp_enqueue_script( 'ajax-chosen' );
wp_enqueue_script( 'chosen' );
wp_enqueue_script( 'plupload-all' );
wp_enqueue_script( 'wc-admin-product-meta-boxes', WC()->plugin_url() . '/assets/js/admin/meta-boxes-product' . $suffix . '.js', array( 'wc-admin-meta-boxes' ), WC_VERSION );
wp_enqueue_script( 'wc-admin-variation-meta-boxes', WC()->plugin_url() . '/assets/js/admin/meta-boxes-product-variation' . $suffix . '.js', array( 'wc-admin-meta-boxes' ), WC_VERSION );
$params = array(
'post_id' => isset( $post->ID ) ? $post->ID : '',
'plugin_url' => WC()->plugin_url(),
'ajax_url' => admin_url('admin-ajax.php'),
'woocommerce_placeholder_img_src' => wc_placeholder_img_src(),
'add_variation_nonce' => wp_create_nonce("add-variation"),
'link_variation_nonce' => wp_create_nonce("link-variations"),
'delete_variation_nonce' => wp_create_nonce("delete-variation"),
'delete_variations_nonce' => wp_create_nonce("delete-variations"),
'i18n_link_all_variations' => esc_js( __( 'Are you sure you want to link all variations? This will create a new variation for each and every possible combination of variation attributes (max 50 per run).', 'woocommerce' ) ),
'i18n_enter_a_value' => esc_js( __( 'Enter a value', 'woocommerce' ) ),
'i18n_enter_a_value_fixed_or_percent' => esc_js( __( 'Enter a value (fixed or %)', 'woocommerce' ) ),
'i18n_delete_all_variations' => esc_js( __( 'Are you sure you want to delete all variations? This cannot be undone.', 'woocommerce' ) ),
'i18n_last_warning' => esc_js( __( 'Last warning, are you sure?', 'woocommerce' ) ),
'i18n_choose_image' => esc_js( __( 'Choose an image', 'woocommerce' ) ),
'i18n_set_image' => esc_js( __( 'Set variation image', 'woocommerce' ) ),
'i18n_variation_added' => esc_js( __( "variation added", 'woocommerce' ) ),
'i18n_variations_added' => esc_js( __( "variations added", 'woocommerce' ) ),
'i18n_no_variations_added' => esc_js( __( "No variations added", 'woocommerce' ) ),
'i18n_remove_variation' => esc_js( __( 'Are you sure you want to remove this variation?', 'woocommerce' ) )
);
wp_localize_script( 'wc-admin-variation-meta-boxes', 'woocommerce_admin_meta_boxes_variations', $params );
}
if ( in_array( $screen->id, array( 'shop_order', 'edit-shop_order' ) ) ) {
wp_enqueue_script( 'wc-admin-order-meta-boxes', WC()->plugin_url() . '/assets/js/admin/meta-boxes-order' . $suffix . '.js', array( 'wc-admin-meta-boxes' ), WC_VERSION );
}
if ( in_array( $screen->id, array( 'shop_coupon', 'edit-shop_coupon' ) ) ) {
wp_enqueue_script( 'wc-admin-coupon-meta-boxes', WC()->plugin_url() . '/assets/js/admin/meta-boxes-coupon' . $suffix . '.js', array( 'wc-admin-meta-boxes' ), WC_VERSION );
}
if ( in_array( $screen->id, array( 'shop_coupon', 'shop_order', 'product', 'edit-shop_coupon', 'edit-shop_order', 'edit-product' ) ) ) {
$params = array(
'remove_item_notice' => __( 'Are you sure you want to remove the selected items? If you have previously reduced this item\'s stock, or this order was submitted by a customer, you will need to manually restore the item\'s stock.', 'woocommerce' ),
'i18n_select_items' => __( 'Please select some items.', 'woocommerce' ),
@ -184,37 +211,7 @@ class WC_Admin_Assets {
'i18n_permission_revoke' => __( 'Are you sure you want to revoke access to this download?', 'woocommerce' ),
);
wp_localize_script( 'woocommerce_admin_meta_boxes', 'woocommerce_admin_meta_boxes', $params );
}
// Product specific
if ( in_array( $screen->id, array( 'product', 'edit-product' ) ) ) {
wp_enqueue_script( 'woocommerce_admin_meta_boxes_variations' );
$params = array(
'post_id' => isset( $post->ID ) ? $post->ID : '',
'plugin_url' => WC()->plugin_url(),
'ajax_url' => admin_url('admin-ajax.php'),
'woocommerce_placeholder_img_src' => wc_placeholder_img_src(),
'add_variation_nonce' => wp_create_nonce("add-variation"),
'link_variation_nonce' => wp_create_nonce("link-variations"),
'delete_variation_nonce' => wp_create_nonce("delete-variation"),
'delete_variations_nonce' => wp_create_nonce("delete-variations"),
'i18n_link_all_variations' => esc_js( __( 'Are you sure you want to link all variations? This will create a new variation for each and every possible combination of variation attributes (max 50 per run).', 'woocommerce' ) ),
'i18n_enter_a_value' => esc_js( __( 'Enter a value', 'woocommerce' ) ),
'i18n_enter_a_value_fixed_or_percent' => esc_js( __( 'Enter a value (fixed or %)', 'woocommerce' ) ),
'i18n_delete_all_variations' => esc_js( __( 'Are you sure you want to delete all variations? This cannot be undone.', 'woocommerce' ) ),
'i18n_last_warning' => esc_js( __( 'Last warning, are you sure?', 'woocommerce' ) ),
'i18n_choose_image' => esc_js( __( 'Choose an image', 'woocommerce' ) ),
'i18n_set_image' => esc_js( __( 'Set variation image', 'woocommerce' ) ),
'i18n_variation_added' => esc_js( __( "variation added", 'woocommerce' ) ),
'i18n_variations_added' => esc_js( __( "variations added", 'woocommerce' ) ),
'i18n_no_variations_added' => esc_js( __( "No variations added", 'woocommerce' ) ),
'i18n_remove_variation' => esc_js( __( 'Are you sure you want to remove this variation?', 'woocommerce' ) )
);
wp_localize_script( 'woocommerce_admin_meta_boxes_variations', 'woocommerce_admin_meta_boxes_variations', $params );
wp_localize_script( 'wc-admin-meta-boxes', 'woocommerce_admin_meta_boxes', $params );
}
// Term ordering - only when sorting by term_order

View File

@ -106,8 +106,8 @@ class WC_Meta_Box_Order_Items {
<div class="wc-order-data-row wc-order-refund-items" style="display:none;">
<ul>
<li>
<label><?php _e( 'Order total', 'woocommerce' ); ?>:</label>
<span class="total"><?php echo wc_price( $order->get_total() ); ?></span>
<label for="restock_refunded_items"><?php _e( 'Restock refunded items', 'woocommerce' ); ?>:</label>
<span class="checkbox"><input type="checkbox" id="restock_refunded_items" name="restock_refunded_items" checked="checked" /></span>
</li>
<li>
<label><?php _e( 'Amount already refunded', 'woocommerce' ); ?>:</label>
@ -119,15 +119,15 @@ class WC_Meta_Box_Order_Items {
</li>
<li>
<label for="refund_amount"><?php _e( 'Refund amount', 'woocommerce' ); ?>:</label>
<input type="text" id="refund_amount" name="refund_amount" class="wc_input_price" />
<input type="text" class="text" id="refund_amount" name="refund_amount" class="wc_input_price" />
</li>
<li>
<label for="refund_reason"><?php _e( 'Reason for refund (optional)', 'woocommerce' ); ?>:</label>
<input type="text" id="refund_reason" name="refund_reason" />
<input type="text" class="text" id="refund_reason" name="refund_reason" />
</li>
</ul>
<button type="button" class="button button-primary"><?php printf( _x( 'Refund %s', 'Refund $amount', 'woocommerce' ), '<span class="wc-order-refund-amount">' . wc_price( 0 ) . '</span>' ); ?></button>
<button type="button" class="button button-primary"><?php _e( 'Refund offline', 'woocommerce' ); ?></button>
<button type="button" class="button button-primary"><?php _e( 'Refund manually', 'woocommerce' ); ?></button>
<button type="button" class="button cancel-action"><?php _e( 'Cancel', 'woocommerce' ); ?></button>
</div>
<?php