Fix JSHint bugs within woocommerce_admin.js

This commit is contained in:
Shiva Poudel 2015-05-02 22:24:44 +05:45
parent 0074777d92
commit b0448209f8
1 changed files with 76 additions and 86 deletions

View File

@ -96,30 +96,29 @@ jQuery( function ( $ ) {
}); });
// wc_input_table tables // wc_input_table tables
$('.wc_input_table.sortable tbody').sortable({ $( '.wc_input_table.sortable tbody' ).sortable({
items:'tr', items: 'tr',
cursor:'move', cursor: 'move',
axis:'y', axis: 'y',
scrollSensitivity:40, scrollSensitivity: 40,
forcePlaceholderSize: true, forcePlaceholderSize: true,
helper: 'clone', helper: 'clone',
opacity: 0.65, opacity: 0.65,
placeholder: 'wc-metabox-sortable-placeholder', placeholder: 'wc-metabox-sortable-placeholder',
start:function(event,ui){ start: function( event, ui ) {
ui.item.css('background-color','#f6f6f6'); ui.item.css( 'background-color', '#f6f6f6' );
}, },
stop:function(event,ui){ stop: function( event, ui ) {
ui.item.removeAttr('style'); ui.item.removeAttr( 'style' );
} }
}); });
$('.wc_input_table .remove_rows').click(function() { $( '.wc_input_table .remove_rows' ).click( function() {
var $tbody = $(this).closest('.wc_input_table').find('tbody'); var $tbody = $( this ).closest( '.wc_input_table' ).find( 'tbody' );
if ( $tbody.find('tr.current').size() > 0 ) { if ( $tbody.find( 'tr.current' ).size() > 0 ) {
$current = $tbody.find('tr.current'); var $current = $tbody.find( 'tr.current' );
$current.each( function() {
$current.each(function(){ $( this ).remove();
$(this).remove();
}); });
} }
return false; return false;
@ -129,115 +128,106 @@ jQuery( function ( $ ) {
var shifted = false; var shifted = false;
var hasFocus = 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 ) { $( '.wc_input_table' ).on( 'focus click', 'input', function( e ) {
var $this_table = $( this ).closest( 'table' );
$this_table = $(this).closest('table'); var $this_row = $( this ).closest( 'tr' );
$this_row = $(this).closest('tr');
if ( ( e.type == 'focus' && hasFocus != $this_row.index() ) || ( e.type == 'click' && $(this).is(':focus') ) ) {
if ( ( e.type === 'focus' && hasFocus !== $this_row.index() ) || ( e.type === 'click' && $( this ).is( ':focus' ) ) ) {
hasFocus = $this_row.index(); hasFocus = $this_row.index();
if ( ! shifted && ! controlled ) { if ( ! shifted && ! controlled ) {
$('tr', $this_table).removeClass('current').removeClass('last_selected'); $( 'tr', $this_table ).removeClass( 'current' ).removeClass( 'last_selected' );
$this_row.addClass('current').addClass('last_selected'); $this_row.addClass( 'current' ).addClass( 'last_selected' );
} else if ( shifted ) { } else if ( shifted ) {
$('tr', $this_table).removeClass('current'); $( 'tr', $this_table ).removeClass( 'current' );
$this_row.addClass('selected_now').addClass('current'); $this_row.addClass( 'selected_now' ).addClass( 'current' );
if ( $('tr.last_selected', $this_table).size() > 0 ) { if ( $( 'tr.last_selected', $this_table ).size() > 0 ) {
if ( $this_row.index() > $('tr.last_selected, $this_table').index() ) { 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'); $( 'tr', $this_table ).slice( $( 'tr.last_selected', $this_table ).index(), $this_row.index() ).addClass( 'current' );
} else { } 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'); $( 'tr', $this_table ).removeClass( 'last_selected' );
$this_row.addClass('last_selected'); $this_row.addClass( 'last_selected' );
} else { } else {
$('tr', $this_table).removeClass('last_selected'); $( 'tr', $this_table ).removeClass( 'last_selected' );
if ( controlled && $(this).closest('tr').is('.current') ) { if ( controlled && $( this ).closest( 'tr' ).is( '.current' ) ) {
$this_row.removeClass('current'); $this_row.removeClass( 'current' );
} else { } 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; hasFocus = false;
}); });
// Additional cost tables // Additional cost tables
$( '.woocommerce_page_wc-settings .shippingrows tbody tr:even' ).addClass( 'alternate' ); $( '.woocommerce_page_wc-settings .shippingrows tbody tr:even' ).addClass( 'alternate' );
// Availability inputs // Attribute term table
$('select.availability').change(function(){ $( 'table.attributes-table tbody tr:nth-child(odd)' ).addClass( 'alternate' );
if ( $(this).val() == "all" ) {
$(this).closest('tr').next('tr').hide();
} else {
$(this).closest('tr').next('tr').show();
}
}).change();
// Show order items on orders page // Show order items on orders page
$( document.body ).on( 'click', '.show_order_items', function() { $( document.body ).on( 'click', '.show_order_items', function() {
$(this).closest('td').find('table').toggle(); $( this ).closest( 'td' ).find( 'table' ).toggle();
return false; return false;
}); });
// Hidden options // Select availability
$('.hide_options_if_checked').each(function(){ $( 'select.availability' ).change( function() {
if ( $( this ).val() === 'all' ) {
$(this).find('input:eq(0)').change(function() { $( this ).closest( 'tr' ).next( 'tr' ).hide();
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();
} else { } else {
$('#woocommerce_demo_store_notice').closest('tr').hide(); $( this ).closest( 'tr' ).next( 'tr' ).show();
} }
}).change(); }).change();
// Attribute term table // Hidden options
$( 'table.attributes-table tbody tr:nth-child(odd)' ).addClass( 'alternate' ); $( '.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 // Generate QR Code
if ( typeof woocommerce_admin !== 'undefined' && typeof woocommerce_admin.qrcode_key !== 'undefined' ) { if ( typeof woocommerce_admin !== 'undefined' && typeof woocommerce_admin.qrcode_key !== 'undefined' ) {
$( '#qrcode_small' ).qrcode({ $( '#qrcode_small' ).qrcode({
text: woocommerce_admin.qrcode_key, text: woocommerce_admin.qrcode_key,
width: 90, width: 90,
height: 90, height: 90
}); });
} }
}); });