woocommerce/assets/js/admin/woocommerce_admin.js

144 lines
4.2 KiB
JavaScript
Raw Normal View History

2011-11-28 15:50:19 +00:00
/**
* WooCommerce Admin JS
*/
jQuery(function(){
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
// 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(){
if ( jQuery(this).val() == "all" ) {
2011-11-28 15:50:19 +00:00
jQuery(this).closest('tr').next('tr').hide();
} 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-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
});