2011-11-28 15:50:19 +00:00
|
|
|
/**
|
|
|
|
* WooCommerce Admin JS
|
|
|
|
*/
|
|
|
|
jQuery(function(){
|
|
|
|
|
2013-09-27 19:28:42 +00:00
|
|
|
// Price input validation - Keep price inputs formatted correctly
|
2013-10-01 16:54:29 +00:00
|
|
|
jQuery(".wc_input_decimal[type=text]")
|
|
|
|
.each(function(){
|
|
|
|
var value = jQuery(this).val();
|
|
|
|
var newvalue = value.replace( '.', woocommerce_admin.locale_decimal_point );
|
|
|
|
jQuery(this).val( newvalue );
|
|
|
|
});
|
|
|
|
jQuery(".wc_input_decimal[type=text]")
|
2013-09-27 19:28:42 +00:00
|
|
|
.bind( 'keyup change', function() {
|
|
|
|
var value = jQuery(this).val();
|
2013-10-02 11:58:26 +00:00
|
|
|
var regex = new RegExp( "[^0-9\%.\\" + woocommerce_admin.locale_decimal_point + "]+", "gi" );
|
2013-10-01 16:54:29 +00:00
|
|
|
var newvalue = value.replace( regex, '' );
|
2013-09-27 19:28:42 +00:00
|
|
|
|
|
|
|
if ( value !== newvalue ) {
|
|
|
|
jQuery(this).val( newvalue );
|
|
|
|
if ( jQuery(this).parent().find('.wc_error_tip').size() == 0 ) {
|
|
|
|
var offset = jQuery(this).position();
|
2013-10-01 16:54:29 +00:00
|
|
|
jQuery(this).after( '<div class="wc_error_tip">' + woocommerce_admin.i18n_decimal_input_error + '</div>' );
|
2013-09-27 19:28:42 +00:00
|
|
|
jQuery('.wc_error_tip')
|
|
|
|
.css('left', offset.left + jQuery(this).width() - ( jQuery(this).width() / 2 ) - ( jQuery('.wc_error_tip').width() / 2 ) )
|
|
|
|
.css('top', offset.top + jQuery(this).height() )
|
|
|
|
.fadeIn('100');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return this;
|
|
|
|
})
|
|
|
|
.bind( 'blur', function() {
|
|
|
|
jQuery('.wc_error_tip').fadeOut('100', function(){ jQuery(this).remove(); } );
|
|
|
|
return this;
|
|
|
|
});
|
|
|
|
|
|
|
|
jQuery("body").click(function(){
|
|
|
|
jQuery('.wc_error_tip').fadeOut('100', function(){ jQuery(this).remove(); } );
|
|
|
|
});
|
|
|
|
|
2012-03-05 17:19:00 +00:00
|
|
|
// Tooltips
|
|
|
|
jQuery(".tips, .help_tip").tipTip({
|
2012-03-20 19:40:52 +00:00
|
|
|
'attribute' : 'data-tip',
|
2011-11-28 15:50:19 +00:00
|
|
|
'fadeIn' : 50,
|
2012-07-22 12:50:45 +00:00
|
|
|
'fadeOut' : 50,
|
|
|
|
'delay' : 200
|
2011-11-28 15:50:19 +00:00
|
|
|
});
|
2012-08-10 09:35:25 +00:00
|
|
|
|
2013-08-05 15:34:48 +00:00
|
|
|
// wc_input_table tables
|
|
|
|
jQuery('.wc_input_table.sortable tbody').sortable({
|
|
|
|
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');
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
jQuery('.wc_input_table .remove_rows').click(function() {
|
|
|
|
var $tbody = jQuery(this).closest('.wc_input_table').find('tbody');
|
|
|
|
if ( $tbody.find('tr.current').size() > 0 ) {
|
|
|
|
$current = $tbody.find('tr.current');
|
|
|
|
|
|
|
|
$current.each(function(){
|
|
|
|
jQuery(this).remove();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
});
|
|
|
|
|
|
|
|
var controlled = false;
|
|
|
|
var shifted = false;
|
|
|
|
var hasFocus = false;
|
|
|
|
|
|
|
|
jQuery(document).bind('keyup keydown', function(e){ shifted = e.shiftKey; controlled = e.ctrlKey || e.metaKey } );
|
|
|
|
|
|
|
|
jQuery('.wc_input_table').on( 'focus click', 'input', function( e ) {
|
|
|
|
|
|
|
|
$this_table = jQuery(this).closest('table');
|
|
|
|
$this_row = jQuery(this).closest('tr');
|
|
|
|
|
|
|
|
if ( ( e.type == 'focus' && hasFocus != $this_row.index() ) || ( e.type == 'click' && jQuery(this).is(':focus') ) ) {
|
|
|
|
|
|
|
|
hasFocus = $this_row.index();
|
|
|
|
|
|
|
|
if ( ! shifted && ! controlled ) {
|
|
|
|
jQuery('tr', $this_table).removeClass('current').removeClass('last_selected');
|
|
|
|
$this_row.addClass('current').addClass('last_selected');
|
|
|
|
} else if ( shifted ) {
|
|
|
|
jQuery('tr', $this_table).removeClass('current');
|
|
|
|
$this_row.addClass('selected_now').addClass('current');
|
|
|
|
|
|
|
|
if ( jQuery('tr.last_selected', $this_table).size() > 0 ) {
|
|
|
|
if ( $this_row.index() > jQuery('tr.last_selected, $this_table').index() ) {
|
|
|
|
jQuery('tr', $this_table).slice( jQuery('tr.last_selected', $this_table).index(), $this_row.index() ).addClass('current');
|
|
|
|
} else {
|
|
|
|
jQuery('tr', $this_table).slice( $this_row.index(), jQuery('tr.last_selected', $this_table).index() + 1 ).addClass('current');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
jQuery('tr', $this_table).removeClass('last_selected');
|
|
|
|
$this_row.addClass('last_selected');
|
|
|
|
} else {
|
|
|
|
jQuery('tr', $this_table).removeClass('last_selected');
|
|
|
|
if ( controlled && jQuery(this).closest('tr').is('.current') ) {
|
|
|
|
$this_row.removeClass('current');
|
|
|
|
} else {
|
|
|
|
$this_row.addClass('current').addClass('last_selected');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
jQuery('tr', $this_table).removeClass('selected_now');
|
|
|
|
|
|
|
|
}
|
|
|
|
}).on( 'blur', 'input', function( e ) {
|
|
|
|
hasFocus = false;
|
|
|
|
});
|
|
|
|
|
|
|
|
// Availability inputs
|
2011-11-28 15:50:19 +00:00
|
|
|
jQuery('select.availability').change(function(){
|
2013-08-22 10:58:03 +00:00
|
|
|
if ( jQuery(this).val() == "all" ) {
|
2011-11-28 15:50:19 +00:00
|
|
|
jQuery(this).closest('tr').next('tr').hide();
|
2013-08-22 10:58:03 +00:00
|
|
|
} else {
|
|
|
|
jQuery(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
|
|
|
|
jQuery('body').on( 'click', '.show_order_items', function() {
|
|
|
|
jQuery(this).closest('td').find('table').toggle();
|
|
|
|
return false;
|
|
|
|
});
|
|
|
|
|
2011-12-21 21:12:34 +00:00
|
|
|
// Hidden options
|
2012-03-12 15:48:22 +00:00
|
|
|
jQuery('.hide_options_if_checked').each(function(){
|
2012-08-10 09:35:25 +00:00
|
|
|
|
2012-03-12 15:48:22 +00:00
|
|
|
jQuery(this).find('input:eq(0)').change(function() {
|
2012-08-10 09:35:25 +00:00
|
|
|
|
2012-03-12 15:48:22 +00:00
|
|
|
if (jQuery(this).is(':checked')) {
|
|
|
|
jQuery(this).closest('fieldset, tr').nextUntil( '.hide_options_if_checked, .show_options_if_checked', '.hidden_option').hide();
|
|
|
|
} else {
|
|
|
|
jQuery(this).closest('fieldset, tr').nextUntil( '.hide_options_if_checked, .show_options_if_checked', '.hidden_option').show();
|
|
|
|
}
|
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
|
|
|
|
2012-03-12 15:48:22 +00:00
|
|
|
jQuery('.show_options_if_checked').each(function(){
|
2012-08-10 09:35:25 +00:00
|
|
|
|
2012-03-12 15:48:22 +00:00
|
|
|
jQuery(this).find('input:eq(0)').change(function() {
|
2012-08-10 09:35:25 +00:00
|
|
|
|
2012-03-12 15:48:22 +00:00
|
|
|
if (jQuery(this).is(':checked')) {
|
|
|
|
jQuery(this).closest('fieldset, tr').nextUntil( '.hide_options_if_checked, .show_options_if_checked', '.hidden_option').show();
|
|
|
|
} else {
|
|
|
|
jQuery(this).closest('fieldset, tr').nextUntil( '.hide_options_if_checked, .show_options_if_checked', '.hidden_option').hide();
|
|
|
|
}
|
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
|
|
|
|
2012-08-10 09:35:25 +00:00
|
|
|
jQuery('input#woocommerce_demo_store').change(function() {
|
|
|
|
if (jQuery(this).is(':checked')) {
|
|
|
|
jQuery('#woocommerce_demo_store_notice').closest('tr').show();
|
|
|
|
} else {
|
|
|
|
jQuery('#woocommerce_demo_store_notice').closest('tr').hide();
|
|
|
|
}
|
|
|
|
}).change();
|
|
|
|
|
2011-11-28 15:50:19 +00:00
|
|
|
});
|