diff --git a/assets/js/admin/woocommerce_admin.js b/assets/js/admin/woocommerce_admin.js index dde82e61851..0bda7c499ef 100644 --- a/assets/js/admin/woocommerce_admin.js +++ b/assets/js/admin/woocommerce_admin.js @@ -96,30 +96,29 @@ jQuery( function ( $ ) { }); // wc_input_table tables - $('.wc_input_table.sortable tbody').sortable({ - items:'tr', - cursor:'move', - axis:'y', - scrollSensitivity:40, + $( '.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'); + start: function( event, ui ) { + ui.item.css( 'background-color', '#f6f6f6' ); }, - stop:function(event,ui){ - ui.item.removeAttr('style'); + stop: function( event, ui ) { + ui.item.removeAttr( 'style' ); } }); - $('.wc_input_table .remove_rows').click(function() { - var $tbody = $(this).closest('.wc_input_table').find('tbody'); - if ( $tbody.find('tr.current').size() > 0 ) { - $current = $tbody.find('tr.current'); - - $current.each(function(){ - $(this).remove(); + $( '.wc_input_table .remove_rows' ).click( function() { + var $tbody = $( this ).closest( '.wc_input_table' ).find( 'tbody' ); + if ( $tbody.find( 'tr.current' ).size() > 0 ) { + var $current = $tbody.find( 'tr.current' ); + $current.each( function() { + $( this ).remove(); }); } return false; @@ -129,115 +128,106 @@ jQuery( function ( $ ) { var shifted = false; var hasFocus = false; - $(document).bind('keyup keydown', function(e){ shifted = e.shiftKey; controlled = e.ctrlKey || e.metaKey } ); + $( document.body ).bind( 'keyup keydown', function( e ) { + shifted = e.shiftKey; controlled = e.ctrlKey || e.metaKey; + }); - $('.wc_input_table').on( 'focus click', 'input', function( e ) { - - $this_table = $(this).closest('table'); - $this_row = $(this).closest('tr'); - - if ( ( e.type == 'focus' && hasFocus != $this_row.index() ) || ( e.type == 'click' && $(this).is(':focus') ) ) { + $( '.wc_input_table' ).on( 'focus click', 'input', function( e ) { + var $this_table = $( this ).closest( 'table' ); + var $this_row = $( this ).closest( 'tr' ); + if ( ( e.type === 'focus' && hasFocus !== $this_row.index() ) || ( e.type === 'click' && $( this ).is( ':focus' ) ) ) { hasFocus = $this_row.index(); if ( ! shifted && ! controlled ) { - $('tr', $this_table).removeClass('current').removeClass('last_selected'); - $this_row.addClass('current').addClass('last_selected'); + $( 'tr', $this_table ).removeClass( 'current' ).removeClass( 'last_selected' ); + $this_row.addClass( 'current' ).addClass( 'last_selected' ); } else if ( shifted ) { - $('tr', $this_table).removeClass('current'); - $this_row.addClass('selected_now').addClass('current'); + $( 'tr', $this_table ).removeClass( 'current' ); + $this_row.addClass( 'selected_now' ).addClass( 'current' ); - 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'); + 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' ); } else { - $('tr', $this_table).slice( $this_row.index(), $('tr.last_selected', $this_table).index() + 1 ).addClass('current'); + $( 'tr', $this_table ).slice( $this_row.index(), $( 'tr.last_selected', $this_table ).index() + 1 ).addClass( 'current' ); } } - $('tr', $this_table).removeClass('last_selected'); - $this_row.addClass('last_selected'); + $( 'tr', $this_table ).removeClass( 'last_selected' ); + $this_row.addClass( 'last_selected' ); } else { - $('tr', $this_table).removeClass('last_selected'); - if ( controlled && $(this).closest('tr').is('.current') ) { - $this_row.removeClass('current'); + $( 'tr', $this_table ).removeClass( 'last_selected' ); + if ( controlled && $( this ).closest( 'tr' ).is( '.current' ) ) { + $this_row.removeClass( 'current' ); } else { - $this_row.addClass('current').addClass('last_selected'); + $this_row.addClass( 'current' ).addClass( 'last_selected' ); } } - $('tr', $this_table).removeClass('selected_now'); - + $( 'tr', $this_table ).removeClass( 'selected_now' ); } - }).on( 'blur', 'input', function( e ) { + }).on( 'blur', 'input', function() { hasFocus = false; }); // Additional cost tables $( '.woocommerce_page_wc-settings .shippingrows tbody tr:even' ).addClass( 'alternate' ); - // Availability inputs - $('select.availability').change(function(){ - if ( $(this).val() == "all" ) { - $(this).closest('tr').next('tr').hide(); - } else { - $(this).closest('tr').next('tr').show(); - } - }).change(); + // Attribute term table + $( 'table.attributes-table tbody tr:nth-child(odd)' ).addClass( 'alternate' ); // Show order items on orders page $( document.body ).on( 'click', '.show_order_items', function() { - $(this).closest('td').find('table').toggle(); + $( this ).closest( 'td' ).find( 'table' ).toggle(); return false; }); - // Hidden options - $('.hide_options_if_checked').each(function(){ - - $(this).find('input:eq(0)').change(function() { - - if ($(this).is(':checked')) { - $(this).closest('fieldset, tr').nextUntil( '.hide_options_if_checked, .show_options_if_checked', '.hidden_option').hide(); - } else { - $(this).closest('fieldset, tr').nextUntil( '.hide_options_if_checked, .show_options_if_checked', '.hidden_option').show(); - } - - }).change(); - - }); - - $('.show_options_if_checked').each(function(){ - - $(this).find('input:eq(0)').change(function() { - - if ($(this).is(':checked')) { - $(this).closest('fieldset, tr').nextUntil( '.hide_options_if_checked, .show_options_if_checked', '.hidden_option').show(); - } else { - $(this).closest('fieldset, tr').nextUntil( '.hide_options_if_checked, .show_options_if_checked', '.hidden_option').hide(); - } - - }).change(); - - }); - - $('input#woocommerce_demo_store').change(function() { - if ($(this).is(':checked')) { - $('#woocommerce_demo_store_notice').closest('tr').show(); + // Select availability + $( 'select.availability' ).change( function() { + if ( $( this ).val() === 'all' ) { + $( this ).closest( 'tr' ).next( 'tr' ).hide(); } else { - $('#woocommerce_demo_store_notice').closest('tr').hide(); + $( this ).closest( 'tr' ).next( 'tr' ).show(); } }).change(); - // Attribute term table - $( 'table.attributes-table tbody tr:nth-child(odd)' ).addClass( 'alternate' ); + // Hidden options + $( '.hide_options_if_checked' ).each( function() { + $( this ).find( 'input:eq(0)' ).change( function() { + if ( $( this ).is( ':checked' ) ) { + $( this ).closest( 'fieldset, tr' ).nextUntil( '.hide_options_if_checked, .show_options_if_checked', '.hidden_option' ).hide(); + } else { + $( this ).closest( 'fieldset, tr' ).nextUntil( '.hide_options_if_checked, .show_options_if_checked', '.hidden_option' ).show(); + } + }).change(); + }); + + $( '.show_options_if_checked' ).each( function() { + $( this ).find( 'input:eq(0)' ).change( function() { + if ( $( this ).is( ':checked' ) ) { + $( this ).closest( 'fieldset, tr' ).nextUntil( '.hide_options_if_checked, .show_options_if_checked', '.hidden_option' ).show(); + } else { + $( this ).closest( 'fieldset, tr' ).nextUntil( '.hide_options_if_checked, .show_options_if_checked', '.hidden_option' ).hide(); + } + }).change(); + }); + + // Demo store notice + $( 'input#woocommerce_demo_store' ).change(function() { + if ( $( this ).is( ':checked' ) ) { + $( '#woocommerce_demo_store_notice' ).closest( 'tr' ).show(); + } else { + $( '#woocommerce_demo_store_notice' ).closest( 'tr' ).hide(); + } + }).change(); // Generate QR Code if ( typeof woocommerce_admin !== 'undefined' && typeof woocommerce_admin.qrcode_key !== 'undefined' ) { $( '#qrcode_small' ).qrcode({ text: woocommerce_admin.qrcode_key, width: 90, - height: 90, + height: 90 }); } - });