fixed coding standards meta-boxes-variations.js

fixed some JSHint issues
this commit helps in #4680
This commit is contained in:
claudiosmweb 2014-02-14 18:49:36 -02:00
parent f3eb602532
commit 3dd39c1fb9
1 changed files with 155 additions and 122 deletions

View File

@ -1,3 +1,4 @@
/* global wp, woocommerce_admin_meta_boxes_variations */
jQuery( function ( $ ) { jQuery( function ( $ ) {
var variation_sortable_options = { var variation_sortable_options = {
@ -20,11 +21,17 @@ jQuery( function($){
}; };
// Add a variation // Add a variation
jQuery('#variable_product_options').on('click', 'button.add_variation', function(){ $( '#variable_product_options' ).on( 'click', 'button.add_variation', function () {
jQuery('.woocommerce_variations').block({ message: null, overlayCSS: { background: '#fff url(' + woocommerce_admin_meta_boxes_variations.plugin_url + '/assets/images/ajax-loader.gif) no-repeat center', opacity: 0.6 } }); $('.woocommerce_variations').block({
message: null,
overlayCSS: {
background: '#fff url(' + woocommerce_admin_meta_boxes_variations.plugin_url + '/assets/images/ajax-loader.gif) no-repeat center',
opacity: 0.6
}
});
var loop = jQuery('.woocommerce_variation').size(); var loop = $('.woocommerce_variation').size();
var data = { var data = {
action: 'woocommerce_add_variation', action: 'woocommerce_add_variation',
@ -33,33 +40,39 @@ jQuery( function($){
security: woocommerce_admin_meta_boxes_variations.add_variation_nonce security: woocommerce_admin_meta_boxes_variations.add_variation_nonce
}; };
jQuery.post( woocommerce_admin_meta_boxes_variations.ajax_url, data, function(response) { $.post( woocommerce_admin_meta_boxes_variations.ajax_url, data, function ( response ) {
jQuery('.woocommerce_variations').append( response ); $( '.woocommerce_variations' ).append( response );
jQuery(".tips").tipTip({ $( '.tips' ).tipTip({
'attribute': 'data-tip', 'attribute': 'data-tip',
'fadeIn': 50, 'fadeIn': 50,
'fadeOut': 50 'fadeOut': 50
}); });
jQuery('input.variable_is_downloadable, input.variable_is_virtual').change(); $( 'input.variable_is_downloadable, input.variable_is_virtual' ).change();
jQuery('.woocommerce_variations').unblock(); $( '.woocommerce_variations' ).unblock();
jQuery('#variable_product_options').trigger('woocommerce_variations_added'); $( '#variable_product_options' ).trigger( 'woocommerce_variations_added' );
}); });
return false; return false;
}); });
jQuery('#variable_product_options').on('click', 'button.link_all_variations', function() { $( '#variable_product_options').on( 'click', 'button.link_all_variations', function () {
var answer = confirm( woocommerce_admin_meta_boxes_variations.i18n_link_all_variations ); var answer = window.confirm( woocommerce_admin_meta_boxes_variations.i18n_link_all_variations );
if ( answer ) { if ( answer ) {
jQuery('#variable_product_options').block({ message: null, overlayCSS: { background: '#fff url(' + woocommerce_admin_meta_boxes_variations.plugin_url + '/assets/images/ajax-loader.gif) no-repeat center', opacity: 0.6 } }); $( '#variable_product_options' ).block({
message: null,
overlayCSS: {
background: '#fff url(' + woocommerce_admin_meta_boxes_variations.plugin_url + '/assets/images/ajax-loader.gif) no-repeat center',
opacity: 0.6
}
});
var data = { var data = {
action: 'woocommerce_link_all_variations', action: 'woocommerce_link_all_variations',
@ -67,16 +80,16 @@ jQuery( function($){
security: woocommerce_admin_meta_boxes_variations.link_variation_nonce security: woocommerce_admin_meta_boxes_variations.link_variation_nonce
}; };
jQuery.post( woocommerce_admin_meta_boxes_variations.ajax_url, data, function(response) { $.post( woocommerce_admin_meta_boxes_variations.ajax_url, data, function ( response ) {
var count = parseInt( response ); var count = parseInt( response, 10 );
if (count==1) { if ( 1 === count ) {
alert( count + ' ' + woocommerce_admin_meta_boxes_variations.i18n_variation_added ); window.alert( count + ' ' + woocommerce_admin_meta_boxes_variations.i18n_variation_added );
} else if (count==0 || count>1) { } else if ( 0 === count || count > 1 ) {
alert( count + ' ' + woocommerce_admin_meta_boxes_variations.i18n_variations_added ); window.alert( count + ' ' + woocommerce_admin_meta_boxes_variations.i18n_variations_added );
} else { } else {
alert( woocommerce_admin_meta_boxes_variations.i18n_no_variations_added ); window.alert( woocommerce_admin_meta_boxes_variations.i18n_no_variations_added );
} }
if ( count > 0 ) { if ( count > 0 ) {
@ -86,9 +99,9 @@ jQuery( function($){
$( '#variable_product_options' ).load( this_page + ' #variable_product_options_inner', function () { $( '#variable_product_options' ).load( this_page + ' #variable_product_options_inner', function () {
$( '#variable_product_options' ).unblock(); $( '#variable_product_options' ).unblock();
jQuery('#variable_product_options').trigger('woocommerce_variations_added'); $( '#variable_product_options' ).trigger( 'woocommerce_variations_added' );
jQuery(".tips").tipTip({ $( '.tips' ).tipTip({
'attribute': 'data-tip', 'attribute': 'data-tip',
'fadeIn': 50, 'fadeIn': 50,
'fadeOut': 50 'fadeOut': 50
@ -102,18 +115,24 @@ jQuery( function($){
return false; return false;
}); });
jQuery('#variable_product_options').on('click', 'button.remove_variation', function(e){ $( '#variable_product_options' ).on( 'click', 'button.remove_variation', function ( e ) {
e.preventDefault(); e.preventDefault();
var answer = confirm( woocommerce_admin_meta_boxes_variations.i18n_remove_variation ); var answer = window.confirm( woocommerce_admin_meta_boxes_variations.i18n_remove_variation );
if ( answer ) { if ( answer ) {
var el = jQuery(this).parent().parent(); var el = $( this ).parent().parent();
var variation = jQuery(this).attr('rel'); var variation = $( this ).attr( 'rel' );
if ( variation > 0 ) { if ( variation > 0 ) {
jQuery(el).block({ message: null, overlayCSS: { background: '#fff url(' + woocommerce_admin_meta_boxes_variations.plugin_url + '/assets/images/ajax-loader.gif) no-repeat center', opacity: 0.6 } }); $( el ).block({
message: null,
overlayCSS: {
background: '#fff url(' + woocommerce_admin_meta_boxes_variations.plugin_url + '/assets/images/ajax-loader.gif) no-repeat center',
opacity: 0.6
}
});
var data = { var data = {
action: 'woocommerce_remove_variation', action: 'woocommerce_remove_variation',
@ -121,16 +140,16 @@ jQuery( function($){
security: woocommerce_admin_meta_boxes_variations.delete_variation_nonce security: woocommerce_admin_meta_boxes_variations.delete_variation_nonce
}; };
jQuery.post(woocommerce_admin_meta_boxes_variations.ajax_url, data, function(response) { $.post( woocommerce_admin_meta_boxes_variations.ajax_url, data, function ( response ) {
// Success // Success
jQuery(el).fadeOut('300', function(){ $( el ).fadeOut( '300', function () {
jQuery(el).remove(); $( el ).remove();
}); });
}); });
} else { } else {
jQuery(el).fadeOut('300', function(){ $( el ).fadeOut( '300', function () {
jQuery(el).remove(); $( el ).remove();
}); });
} }
@ -138,40 +157,49 @@ jQuery( function($){
return false; return false;
}); });
jQuery('.wc-metaboxes-wrapper').on('click', 'a.bulk_edit', function(event){ $( '.wc-metaboxes-wrapper' ).on( 'click', 'a.bulk_edit', function ( event ) {
var bulk_edit = jQuery('select#field_to_edit').val(); var bulk_edit = $( 'select#field_to_edit' ).val(),
checkbox,
answer,
value;
switch ( bulk_edit ) { switch ( bulk_edit ) {
case 'toggle_enabled' : case 'toggle_enabled' :
var checkbox = jQuery('input[name^="variable_enabled"]'); checkbox = $( 'input[name^="variable_enabled"]' );
checkbox.attr('checked', ! checkbox.attr( 'checked' ) ); checkbox.attr('checked', ! checkbox.attr( 'checked' ) );
break; break;
case 'toggle_downloadable' : case 'toggle_downloadable' :
var checkbox = jQuery('input[name^="variable_is_downloadable"]'); checkbox = $( 'input[name^="variable_is_downloadable"]' );
checkbox.attr( 'checked', ! checkbox.attr( 'checked' ) ); checkbox.attr( 'checked', ! checkbox.attr( 'checked' ) );
jQuery('input.variable_is_downloadable').change(); $('input.variable_is_downloadable').change();
break; break;
case 'toggle_virtual' : case 'toggle_virtual' :
var checkbox = jQuery('input[name^="variable_is_virtual"]'); checkbox = $('input[name^="variable_is_virtual"]');
checkbox.attr( 'checked', ! checkbox.attr( 'checked' ) ); checkbox.attr( 'checked', ! checkbox.attr( 'checked' ) );
jQuery('input.variable_is_virtual').change(); $( 'input.variable_is_virtual' ).change();
break; break;
case 'delete_all' : case 'delete_all' :
var answer = confirm( woocommerce_admin_meta_boxes_variations.i18n_delete_all_variations ); answer = window.confirm( woocommerce_admin_meta_boxes_variations.i18n_delete_all_variations );
if ( answer ) { if ( answer ) {
var answer = confirm( woocommerce_admin_meta_boxes_variations.i18n_last_warning ); answer = window.confirm( woocommerce_admin_meta_boxes_variations.i18n_last_warning );
if ( answer ) { if ( answer ) {
var variation_ids = []; var variation_ids = [];
jQuery('.woocommerce_variations .woocommerce_variation').block({ message: null, overlayCSS: { background: '#fff url(' + woocommerce_admin_meta_boxes_variations.plugin_url + '/assets/images/ajax-loader.gif) no-repeat center', opacity: 0.6 } }); $( '.woocommerce_variations .woocommerce_variation' ).block({
message: null,
overlayCSS: {
background: '#fff url(' + woocommerce_admin_meta_boxes_variations.plugin_url + '/assets/images/ajax-loader.gif) no-repeat center',
opacity: 0.6
}
});
jQuery('.woocommerce_variations .woocommerce_variation .remove_variation').each(function(){ $( '.woocommerce_variations .woocommerce_variation .remove_variation' ).each( function () {
var variation = jQuery(this).attr('rel'); var variation = $( this ).attr( 'rel' );
if ( variation > 0 ) { if ( variation > 0 ) {
variation_ids.push( variation ); variation_ids.push( variation );
} }
@ -183,9 +211,9 @@ jQuery( function($){
security: woocommerce_admin_meta_boxes_variations.delete_variations_nonce security: woocommerce_admin_meta_boxes_variations.delete_variations_nonce
}; };
jQuery.post(woocommerce_admin_meta_boxes_variations.ajax_url, data, function(response) { $.post( woocommerce_admin_meta_boxes_variations.ajax_url, data, function( response ) {
jQuery('.woocommerce_variations .woocommerce_variation').fadeOut('300', function(){ $( '.woocommerce_variations .woocommerce_variation' ).fadeOut( '300', function () {
jQuery('.woocommerce_variations .woocommerce_variation').remove(); $( '.woocommerce_variations .woocommerce_variation' ).remove();
}); });
}); });
} }
@ -195,27 +223,32 @@ jQuery( function($){
case 'variable_regular_price_decrease': case 'variable_regular_price_decrease':
case 'variable_sale_price_increase': case 'variable_sale_price_increase':
case 'variable_sale_price_decrease': case 'variable_sale_price_decrease':
if ( bulk_edit.lastIndexOf( 'variable_regular_price', 0 ) === 0 ) var edit_field;
var edit_field = 'variable_regular_price'; if ( bulk_edit.lastIndexOf( 'variable_regular_price', 0 ) === 0 ) {
else edit_field = 'variable_regular_price';
var edit_field = 'variable_sale_price'; } else {
edit_field = 'variable_sale_price';
}
var value = prompt( woocommerce_admin_meta_boxes_variations.i18n_enter_a_value_fixed_or_percent ); value = window.prompt( woocommerce_admin_meta_boxes_variations.i18n_enter_a_value_fixed_or_percent );
jQuery( ':input[name^="' + edit_field + '["]').each(function() { $( ':input[name^="' + edit_field + '["]' ).each( function () {
var current_value = Number( jQuery(this).val() ); var current_value = Number( $( this ).val() ),
new_value;
if ( value.toString().indexOf("%") >= 0 ) if ( value.toString().indexOf( '%' ) >= 0 ) {
value = Number( ( Number( current_value ) / 100 ) * Number( value.replace(/\%/, "" ) ) ); value = Number( ( Number( current_value ) / 100 ) * Number( value.replace(/\%/, '' ) ) );
else } else {
value = Number( value ); value = Number( value );
}
if ( bulk_edit.indexOf( "increase" ) != -1 ) if ( bulk_edit.indexOf( 'increase' ) !== -1 ) {
var new_value = current_value + value; new_value = current_value + value;
else } else {
var new_value = current_value - value; new_value = current_value - value;
}
jQuery(this).val( new_value ).change(); $( this ).val( new_value ).change();
}); });
break; break;
case 'variable_regular_price' : case 'variable_regular_price' :
@ -227,38 +260,38 @@ jQuery( function($){
case 'variable_height' : case 'variable_height' :
case 'variable_download_limit' : case 'variable_download_limit' :
case 'variable_download_expiry' : case 'variable_download_expiry' :
var value = prompt( woocommerce_admin_meta_boxes_variations.i18n_enter_a_value ); value = window.prompt( woocommerce_admin_meta_boxes_variations.i18n_enter_a_value );
jQuery( ':input[name^="' + bulk_edit + '["]').val( value ).change(); $( ':input[name^="' + bulk_edit + '["]').val( value ).change();
break; break;
default: default:
jQuery('select#field_to_edit').trigger(bulk_edit); $( 'select#field_to_edit' ).trigger( bulk_edit );
break; break;
} }
}); });
jQuery('#variable_product_options').on('change', 'input.variable_is_downloadable', function(){ $( '#variable_product_options' ).on( 'change', 'input.variable_is_downloadable', function () {
jQuery(this).closest('.woocommerce_variation').find('.show_if_variation_downloadable').hide(); $( this ).closest( '.woocommerce_variation' ).find( '.show_if_variation_downloadable' ).hide();
if (jQuery(this).is(':checked')) { if ( $( this ).is( ':checked' ) ) {
jQuery(this).closest('.woocommerce_variation').find('.show_if_variation_downloadable').show(); $( this ).closest( '.woocommerce_variation' ).find( '.show_if_variation_downloadable' ).show();
} }
}); });
jQuery('#variable_product_options').on('change', 'input.variable_is_virtual', function(){ $( '#variable_product_options' ).on( 'change', 'input.variable_is_virtual', function () {
jQuery(this).closest('.woocommerce_variation').find('.hide_if_variation_virtual').show(); $( this ).closest( '.woocommerce_variation' ).find( '.hide_if_variation_virtual' ).show();
if (jQuery(this).is(':checked')) { if ( $( this ).is( ':checked' ) ) {
jQuery(this).closest('.woocommerce_variation').find('.hide_if_variation_virtual').hide(); $( this ).closest( '.woocommerce_variation' ).find( '.hide_if_variation_virtual' ).hide();
} }
}); });
jQuery('input.variable_is_downloadable, input.variable_is_virtual').change(); $( 'input.variable_is_downloadable, input.variable_is_virtual' ).change();
// Ordering // Ordering
$( '#variable_product_options' ).on( 'woocommerce_variations_added', function () { $( '#variable_product_options' ).on( 'woocommerce_variations_added', function () {
@ -269,9 +302,9 @@ jQuery( function($){
function variation_row_indexes() { function variation_row_indexes() {
$( '.woocommerce_variations .woocommerce_variation' ).each( function ( index, el ) { $( '.woocommerce_variations .woocommerce_variation' ).each( function ( index, el ) {
$('.variation_menu_order', el).val( parseInt( $(el).index('.woocommerce_variations .woocommerce_variation') ) ); $( '.variation_menu_order', el ).val( parseInt( $( el ).index( '.woocommerce_variations .woocommerce_variation' ), 10 ) );
}); });
}; }
// Uploader // Uploader
var variable_image_frame; var variable_image_frame;
@ -279,9 +312,9 @@ jQuery( function($){
var setting_variation_image; var setting_variation_image;
var wp_media_post_id = wp.media.model.settings.post.id; var wp_media_post_id = wp.media.model.settings.post.id;
jQuery('#variable_product_options').on('click', '.upload_image_button', function( event ) { $( '#variable_product_options' ).on( 'click', '.upload_image_button', function ( event ) {
var $button = jQuery( this ); var $button = $( this );
var post_id = $button.attr( 'rel' ); var post_id = $button.attr( 'rel' );
var $parent = $button.closest( '.upload_image' ); var $parent = $button.closest( '.upload_image' );
setting_variation_image = $parent; setting_variation_image = $parent;
@ -324,7 +357,7 @@ jQuery( function($){
// When an image is selected, run a callback. // When an image is selected, run a callback.
variable_image_frame.on( 'select', function () { variable_image_frame.on( 'select', function () {
attachment = variable_image_frame.state().get('selection').first().toJSON(); var attachment = variable_image_frame.state().get( 'selection' ).first().toJSON();
setting_variation_image.find( '.upload_image_id' ).val( attachment.id ); setting_variation_image.find( '.upload_image_id' ).val( attachment.id );
setting_variation_image.find( '.upload_image_button' ).addClass( 'remove' ); setting_variation_image.find( '.upload_image_button' ).addClass( 'remove' );
@ -339,7 +372,7 @@ jQuery( function($){
}); });
// Restore ID // Restore ID
jQuery('a.add_media').on('click', function() { $( 'a.add_media' ).on(' click', function () {
wp.media.model.settings.post.id = wp_media_post_id; wp.media.model.settings.post.id = wp_media_post_id;
}); });