2014-05-27 22:02:27 +00:00
|
|
|
/* global woocommerce_admin */
|
|
|
|
|
2011-11-28 15:50:19 +00:00
|
|
|
/**
|
|
|
|
* WooCommerce Admin JS
|
|
|
|
*/
|
2014-08-08 09:24:38 +00:00
|
|
|
jQuery( function ( $ ) {
|
2011-11-28 15:50:19 +00:00
|
|
|
|
2013-11-12 17:43:30 +00:00
|
|
|
// Price input validation
|
2014-08-08 09:24:38 +00:00
|
|
|
$('body').on( 'blur', '.wc_input_decimal[type=text], .wc_input_price[type=text], .wc_input_country_iso[type=text]', function() {
|
|
|
|
$('.wc_error_tip').fadeOut('100', function(){ $(this).remove(); } );
|
2014-05-27 22:02:27 +00:00
|
|
|
return this;
|
|
|
|
});
|
2013-11-12 17:43:30 +00:00
|
|
|
|
2014-08-08 09:24:38 +00:00
|
|
|
$('body').on('keyup change', '.wc_input_price[type=text]', function(){
|
|
|
|
var value = $(this).val();
|
2014-04-17 10:51:02 +00:00
|
|
|
var regex = new RegExp( "[^\-0-9\%.\\" + woocommerce_admin.mon_decimal_point + "]+", "gi" );
|
2014-04-17 10:50:43 +00:00
|
|
|
var newvalue = value.replace( regex, '' );
|
|
|
|
|
2014-04-25 07:04:28 +00:00
|
|
|
if ( value !== newvalue ) {
|
2014-08-08 09:24:38 +00:00
|
|
|
$(this).val( newvalue );
|
|
|
|
if ( $(this).parent().find('.wc_error_tip').size() == 0 ) {
|
|
|
|
var offset = $(this).position();
|
|
|
|
$(this).after( '<div class="wc_error_tip">' + woocommerce_admin.i18n_mon_decimal_error + '</div>' );
|
|
|
|
$('.wc_error_tip')
|
|
|
|
.css('left', offset.left + $(this).width() - ( $(this).width() / 2 ) - ( $('.wc_error_tip').width() / 2 ) )
|
|
|
|
.css('top', offset.top + $(this).height() )
|
2014-04-25 07:04:28 +00:00
|
|
|
.fadeIn('100');
|
2014-04-17 10:50:43 +00:00
|
|
|
}
|
2014-04-25 07:04:28 +00:00
|
|
|
}
|
|
|
|
return this;
|
|
|
|
});
|
2013-11-12 17:43:30 +00:00
|
|
|
|
2014-08-08 09:24:38 +00:00
|
|
|
$('body').on('keyup change', '.wc_input_decimal[type=text]', function(){
|
2014-10-02 16:18:36 +00:00
|
|
|
var value = $(this).val();
|
|
|
|
var regex = new RegExp( "[^\-0-9\%.\\" + woocommerce_admin.decimal_point + "]+", "gi" );
|
2014-04-17 10:50:43 +00:00
|
|
|
var newvalue = value.replace( regex, '' );
|
|
|
|
|
2014-04-25 07:04:28 +00:00
|
|
|
if ( value !== newvalue ) {
|
2014-08-08 09:24:38 +00:00
|
|
|
$(this).val( newvalue );
|
|
|
|
if ( $(this).parent().find('.wc_error_tip').size() === 0 ) {
|
|
|
|
var offset = $(this).position();
|
|
|
|
$(this).after( '<div class="wc_error_tip">' + woocommerce_admin.i18n_decimal_error + '</div>' );
|
|
|
|
$('.wc_error_tip')
|
|
|
|
.css('left', offset.left + $(this).width() - ( $(this).width() / 2 ) - ( $('.wc_error_tip').width() / 2 ) )
|
|
|
|
.css('top', offset.top + $(this).height() )
|
2014-04-25 07:04:28 +00:00
|
|
|
.fadeIn('100');
|
2014-04-17 10:50:43 +00:00
|
|
|
}
|
2014-04-25 07:04:28 +00:00
|
|
|
}
|
|
|
|
return this;
|
|
|
|
});
|
2013-09-27 19:28:42 +00:00
|
|
|
|
2014-10-02 16:18:36 +00:00
|
|
|
$('body').on( 'keyup', '#_sale_price.wc_input_price[type=text], .wc_input_price[name^=variable_sale_price]', function(){
|
|
|
|
var sale_price_field = $(this);
|
2014-08-04 15:28:20 +00:00
|
|
|
|
2014-08-04 15:53:17 +00:00
|
|
|
if( sale_price_field.attr('name').indexOf('variable') !== -1 ) {
|
2014-10-02 16:18:36 +00:00
|
|
|
var regular_price_field = sale_price_field.parents('.variable_pricing').find('.wc_input_price[name^=variable_regular_price]');
|
2014-08-04 15:28:20 +00:00
|
|
|
} else {
|
2014-10-02 16:18:36 +00:00
|
|
|
var regular_price_field = $('#_regular_price');
|
2014-08-04 15:28:20 +00:00
|
|
|
}
|
|
|
|
|
2014-10-02 16:18:36 +00:00
|
|
|
var sale_price = parseFloat( accounting.unformat( sale_price_field.val(), woocommerce_admin.mon_decimal_point ) );
|
|
|
|
var regular_price = parseFloat( accounting.unformat( regular_price_field.val(), woocommerce_admin.mon_decimal_point ) );
|
|
|
|
|
2014-08-04 15:28:20 +00:00
|
|
|
if( sale_price >= regular_price ) {
|
2014-08-08 09:24:38 +00:00
|
|
|
if ( $(this).parent().find('.wc_error_tip').size() === 0 ) {
|
|
|
|
var offset = $(this).position();
|
|
|
|
$(this).after( '<div class="wc_error_tip">' + woocommerce_admin.i18_sale_less_than_regular_error + '</div>' );
|
|
|
|
$('.wc_error_tip')
|
|
|
|
.css('left', offset.left + $(this).width() - ( $(this).width() / 2 ) - ( $('.wc_error_tip').width() / 2 ) )
|
|
|
|
.css('top', offset.top + $(this).height() )
|
2014-08-04 15:28:20 +00:00
|
|
|
.fadeIn('100');
|
|
|
|
}
|
2014-10-02 16:18:36 +00:00
|
|
|
} else {
|
|
|
|
$('.wc_error_tip').fadeOut('100', function(){ $(this).remove(); } );
|
|
|
|
}
|
|
|
|
return this;
|
|
|
|
});
|
|
|
|
$('body').on( 'change', '#_sale_price.wc_input_price[type=text], .wc_input_price[name^=variable_sale_price]', function(){
|
|
|
|
var sale_price_field = $(this);
|
|
|
|
|
|
|
|
if( sale_price_field.attr('name').indexOf('variable') !== -1 ) {
|
|
|
|
var regular_price_field = sale_price_field.parents('.variable_pricing').find('.wc_input_price[name^=variable_regular_price]');
|
|
|
|
} else {
|
|
|
|
var regular_price_field = $('#_regular_price');
|
|
|
|
}
|
|
|
|
|
|
|
|
var sale_price = parseFloat( accounting.unformat( sale_price_field.val(), woocommerce_admin.mon_decimal_point ) );
|
|
|
|
var regular_price = parseFloat( accounting.unformat( regular_price_field.val(), woocommerce_admin.mon_decimal_point ) );
|
|
|
|
|
|
|
|
if( sale_price >= regular_price ) {
|
|
|
|
sale_price_field.val( regular_price_field.val() );
|
|
|
|
} else {
|
|
|
|
$('.wc_error_tip').fadeOut('100', function(){ $(this).remove(); } );
|
2014-08-04 15:28:20 +00:00
|
|
|
}
|
|
|
|
return this;
|
|
|
|
});
|
|
|
|
|
2014-08-08 09:24:38 +00:00
|
|
|
$('body').on('keyup change', '.wc_input_country_iso[type=text]', function(){
|
|
|
|
var value = $(this).val();
|
2014-05-27 22:02:27 +00:00
|
|
|
var regex = new RegExp( '^([A-Z])?([A-Z])$' );
|
|
|
|
|
|
|
|
if ( ! regex.test( value ) ) {
|
2014-08-08 09:24:38 +00:00
|
|
|
$(this).val( '' );
|
|
|
|
if ( $(this).parent().find('.wc_error_tip').size() === 0 ) {
|
|
|
|
var offset = $(this).position();
|
|
|
|
$(this).after( '<div class="wc_error_tip">' + woocommerce_admin.i18n_country_iso_error + '</div>' );
|
|
|
|
$('.wc_error_tip')
|
|
|
|
.css('left', offset.left + $(this).width() - ( $(this).width() / 2 ) - ( $('.wc_error_tip').width() / 2 ) )
|
|
|
|
.css('top', offset.top + $(this).height() )
|
2014-05-27 22:02:27 +00:00
|
|
|
.fadeIn('100');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return this;
|
|
|
|
});
|
|
|
|
|
2014-08-08 09:24:38 +00:00
|
|
|
$("body").click(function(){
|
|
|
|
$('.wc_error_tip').fadeOut('100', function(){ $(this).remove(); } );
|
2013-09-27 19:28:42 +00:00
|
|
|
});
|
|
|
|
|
2012-03-05 17:19:00 +00:00
|
|
|
// Tooltips
|
2014-08-08 09:24:38 +00:00
|
|
|
var tiptip_args = {
|
2014-04-25 07:04:28 +00:00
|
|
|
'attribute' : 'data-tip',
|
|
|
|
'fadeIn' : 50,
|
|
|
|
'fadeOut' : 50,
|
|
|
|
'delay' : 200
|
2014-08-08 09:24:38 +00:00
|
|
|
};
|
|
|
|
$(".tips, .help_tip").tipTip( tiptip_args );
|
|
|
|
|
|
|
|
// Add tiptip to parent element for widefat tables
|
|
|
|
$(".parent-tips").each(function(){
|
|
|
|
$(this).closest( 'a, th' ).attr( 'data-tip', $(this).data( 'tip' ) ).tipTip( tiptip_args ).css( 'cursor', 'help' );
|
2014-04-25 07:04:28 +00:00
|
|
|
});
|
2012-08-10 09:35:25 +00:00
|
|
|
|
2013-08-05 15:34:48 +00:00
|
|
|
// wc_input_table tables
|
2014-08-08 09:24:38 +00:00
|
|
|
$('.wc_input_table.sortable tbody').sortable({
|
2013-08-05 15:34:48 +00:00
|
|
|
items:'tr',
|
|
|
|
cursor:'move',
|
|
|
|
axis:'y',
|
|
|
|
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');
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2014-08-08 09:24:38 +00:00
|
|
|
$('.wc_input_table .remove_rows').click(function() {
|
|
|
|
var $tbody = $(this).closest('.wc_input_table').find('tbody');
|
2013-08-05 15:34:48 +00:00
|
|
|
if ( $tbody.find('tr.current').size() > 0 ) {
|
|
|
|
$current = $tbody.find('tr.current');
|
|
|
|
|
|
|
|
$current.each(function(){
|
2014-08-08 09:24:38 +00:00
|
|
|
$(this).remove();
|
2013-08-05 15:34:48 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
});
|
|
|
|
|
|
|
|
var controlled = false;
|
|
|
|
var shifted = false;
|
|
|
|
var hasFocus = false;
|
|
|
|
|
2014-08-08 09:24:38 +00:00
|
|
|
$(document).bind('keyup keydown', function(e){ shifted = e.shiftKey; controlled = e.ctrlKey || e.metaKey } );
|
2013-08-05 15:34:48 +00:00
|
|
|
|
2014-08-08 09:24:38 +00:00
|
|
|
$('.wc_input_table').on( 'focus click', 'input', function( e ) {
|
2013-08-05 15:34:48 +00:00
|
|
|
|
2014-08-08 09:24:38 +00:00
|
|
|
$this_table = $(this).closest('table');
|
|
|
|
$this_row = $(this).closest('tr');
|
2013-08-05 15:34:48 +00:00
|
|
|
|
2014-08-08 09:24:38 +00:00
|
|
|
if ( ( e.type == 'focus' && hasFocus != $this_row.index() ) || ( e.type == 'click' && $(this).is(':focus') ) ) {
|
2013-08-05 15:34:48 +00:00
|
|
|
|
|
|
|
hasFocus = $this_row.index();
|
|
|
|
|
|
|
|
if ( ! shifted && ! controlled ) {
|
2014-08-08 09:24:38 +00:00
|
|
|
$('tr', $this_table).removeClass('current').removeClass('last_selected');
|
2013-08-05 15:34:48 +00:00
|
|
|
$this_row.addClass('current').addClass('last_selected');
|
|
|
|
} else if ( shifted ) {
|
2014-08-08 09:24:38 +00:00
|
|
|
$('tr', $this_table).removeClass('current');
|
2013-08-05 15:34:48 +00:00
|
|
|
$this_row.addClass('selected_now').addClass('current');
|
|
|
|
|
2014-08-08 09:24:38 +00:00
|
|
|
if ( $('tr.last_selected', $this_table).size() > 0 ) {
|
|
|
|
if ( $this_row.index() > $('tr.last_selected, $this_table').index() ) {
|
|
|
|
$('tr', $this_table).slice( $('tr.last_selected', $this_table).index(), $this_row.index() ).addClass('current');
|
2013-08-05 15:34:48 +00:00
|
|
|
} else {
|
2014-08-08 09:24:38 +00:00
|
|
|
$('tr', $this_table).slice( $this_row.index(), $('tr.last_selected', $this_table).index() + 1 ).addClass('current');
|
2013-08-05 15:34:48 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-08-08 09:24:38 +00:00
|
|
|
$('tr', $this_table).removeClass('last_selected');
|
2013-08-05 15:34:48 +00:00
|
|
|
$this_row.addClass('last_selected');
|
|
|
|
} else {
|
2014-08-08 09:24:38 +00:00
|
|
|
$('tr', $this_table).removeClass('last_selected');
|
|
|
|
if ( controlled && $(this).closest('tr').is('.current') ) {
|
2013-08-05 15:34:48 +00:00
|
|
|
$this_row.removeClass('current');
|
|
|
|
} else {
|
|
|
|
$this_row.addClass('current').addClass('last_selected');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-08-08 09:24:38 +00:00
|
|
|
$('tr', $this_table).removeClass('selected_now');
|
2013-08-05 15:34:48 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
}).on( 'blur', 'input', function( e ) {
|
|
|
|
hasFocus = false;
|
|
|
|
});
|
|
|
|
|
2014-03-25 13:59:30 +00:00
|
|
|
// Additional cost tables
|
2014-08-08 09:24:38 +00:00
|
|
|
$( '.woocommerce_page_wc-settings .shippingrows tbody tr:even' ).addClass( 'alternate' );
|
2014-03-25 13:59:30 +00:00
|
|
|
|
2013-08-05 15:34:48 +00:00
|
|
|
// Availability inputs
|
2014-08-08 09:24:38 +00:00
|
|
|
$('select.availability').change(function(){
|
|
|
|
if ( $(this).val() == "all" ) {
|
|
|
|
$(this).closest('tr').next('tr').hide();
|
2013-08-22 10:58:03 +00:00
|
|
|
} else {
|
2014-08-08 09:24:38 +00:00
|
|
|
$(this).closest('tr').next('tr').show();
|
2011-11-28 15:50:19 +00:00
|
|
|
}
|
|
|
|
}).change();
|
2012-08-10 09:35:25 +00:00
|
|
|
|
2013-07-31 14:12:53 +00:00
|
|
|
// Show order items on orders page
|
2014-08-08 09:24:38 +00:00
|
|
|
$('body').on( 'click', '.show_order_items', function() {
|
|
|
|
$(this).closest('td').find('table').toggle();
|
2013-07-31 14:12:53 +00:00
|
|
|
return false;
|
|
|
|
});
|
|
|
|
|
2011-12-21 21:12:34 +00:00
|
|
|
// Hidden options
|
2014-08-08 09:24:38 +00:00
|
|
|
$('.hide_options_if_checked').each(function(){
|
2012-08-10 09:35:25 +00:00
|
|
|
|
2014-08-08 09:24:38 +00:00
|
|
|
$(this).find('input:eq(0)').change(function() {
|
2012-08-10 09:35:25 +00:00
|
|
|
|
2014-08-08 09:24:38 +00:00
|
|
|
if ($(this).is(':checked')) {
|
|
|
|
$(this).closest('fieldset, tr').nextUntil( '.hide_options_if_checked, .show_options_if_checked', '.hidden_option').hide();
|
2012-03-12 15:48:22 +00:00
|
|
|
} else {
|
2014-08-08 09:24:38 +00:00
|
|
|
$(this).closest('fieldset, tr').nextUntil( '.hide_options_if_checked, .show_options_if_checked', '.hidden_option').show();
|
2012-03-12 15:48:22 +00:00
|
|
|
}
|
2012-08-10 09:35:25 +00:00
|
|
|
|
2012-03-12 15:48:22 +00:00
|
|
|
}).change();
|
2012-08-10 09:35:25 +00:00
|
|
|
|
2012-03-12 15:48:22 +00:00
|
|
|
});
|
2012-08-10 09:35:25 +00:00
|
|
|
|
2014-08-08 09:24:38 +00:00
|
|
|
$('.show_options_if_checked').each(function(){
|
2012-08-10 09:35:25 +00:00
|
|
|
|
2014-08-08 09:24:38 +00:00
|
|
|
$(this).find('input:eq(0)').change(function() {
|
2012-08-10 09:35:25 +00:00
|
|
|
|
2014-08-08 09:24:38 +00:00
|
|
|
if ($(this).is(':checked')) {
|
|
|
|
$(this).closest('fieldset, tr').nextUntil( '.hide_options_if_checked, .show_options_if_checked', '.hidden_option').show();
|
2012-03-12 15:48:22 +00:00
|
|
|
} else {
|
2014-08-08 09:24:38 +00:00
|
|
|
$(this).closest('fieldset, tr').nextUntil( '.hide_options_if_checked, .show_options_if_checked', '.hidden_option').hide();
|
2012-03-12 15:48:22 +00:00
|
|
|
}
|
2012-08-10 09:35:25 +00:00
|
|
|
|
2012-03-12 15:48:22 +00:00
|
|
|
}).change();
|
2012-08-10 09:35:25 +00:00
|
|
|
|
2012-03-12 15:48:22 +00:00
|
|
|
});
|
2012-03-12 09:25:06 +00:00
|
|
|
|
2014-08-08 09:24:38 +00:00
|
|
|
$('input#woocommerce_demo_store').change(function() {
|
|
|
|
if ($(this).is(':checked')) {
|
|
|
|
$('#woocommerce_demo_store_notice').closest('tr').show();
|
2012-08-10 09:35:25 +00:00
|
|
|
} else {
|
2014-08-08 09:24:38 +00:00
|
|
|
$('#woocommerce_demo_store_notice').closest('tr').hide();
|
2012-08-10 09:35:25 +00:00
|
|
|
}
|
|
|
|
}).change();
|
|
|
|
|
2013-11-19 11:04:45 +00:00
|
|
|
// Attribute term table
|
2014-08-08 09:24:38 +00:00
|
|
|
$( 'table.attributes-table tbody tr:nth-child(odd)' ).addClass( 'alternate' );
|
2013-11-19 11:04:45 +00:00
|
|
|
|
2014-05-27 22:02:27 +00:00
|
|
|
});
|