Merge pull request #5175 from splashingpixels/jshint

Jshint
This commit is contained in:
Mike Jolley 2014-03-19 08:25:25 +00:00
commit 030aced0a2
6 changed files with 223 additions and 198 deletions

View File

@ -3,12 +3,12 @@ jQuery(function($) {
$.blockUI.defaults.overlayCSS.cursor = 'default'; $.blockUI.defaults.overlayCSS.cursor = 'default';
// wc_checkout_params is required to continue, ensure the object exists // wc_checkout_params is required to continue, ensure the object exists
if (typeof wc_checkout_params === "undefined") if ( typeof wc_checkout_params === 'undefined' )
return false; return false;
var updateTimer; var updateTimer,
var dirtyInput = false; dirtyInput = false,
var xhr; xhr;
function update_checkout() { function update_checkout() {
@ -20,28 +20,34 @@ jQuery(function($) {
shipping_methods[ $( this ).data( 'index' ) ] = $( this ).val(); shipping_methods[ $( this ).data( 'index' ) ] = $( this ).val();
} ); } );
var payment_method = $('#order_review input[name=payment_method]:checked').val(); var payment_method = $( '#order_review input[name=payment_method]:checked' ).val(),
var country = $('#billing_country').val(); country = $( '#billing_country' ).val(),
var state = $('#billing_state').val(); state = $( '#billing_state' ).val(),
var postcode = $('input#billing_postcode').val(); postcode = $( 'input#billing_postcode' ).val(),
var city = $('#billing_city').val(); city = $( '#billing_city' ).val(),
var address = $('input#billing_address_1').val(); address = $( 'input#billing_address_1' ).val(),
var address_2 = $('input#billing_address_2').val(); address_2 = $( 'input#billing_address_2' ).val(),
s_country,
s_state,
s_postcode,
s_city,
s_address,
s_address_2;
if ( $('#ship-to-different-address input').is(':checked') || $('#ship-to-different-address input').size() == 0 ) { if ( $( '#ship-to-different-address input' ).is( ':checked' ) || $( '#ship-to-different-address input' ).size() === 0 ) {
var s_country = $('#shipping_country').val(); s_country = $( '#shipping_country' ).val();
var s_state = $('#shipping_state').val(); s_state = $( '#shipping_state' ).val();
var s_postcode = $('input#shipping_postcode').val(); s_postcode = $( 'input#shipping_postcode' ).val();
var s_city = $('#shipping_city').val(); s_city = $( '#shipping_city' ).val();
var s_address = $('input#shipping_address_1').val(); s_address = $( 'input#shipping_address_1' ).val();
var s_address_2 = $('input#shipping_address_2').val(); s_address_2 = $( 'input#shipping_address_2' ).val();
} else { } else {
var s_country = country; s_country = country;
var s_state = state; s_state = state;
var s_postcode = postcode; s_postcode = postcode;
var s_city = city; s_city = city;
var s_address = address; s_address = address;
var s_address_2 = address_2; s_address_2 = address_2;
} }
$( '#order_methods, #order_review' ).block({ message: null, overlayCSS: { background: '#fff url(' + wc_checkout_params.ajax_loader_url + ') no-repeat center', backgroundSize: '16px 16px', opacity: 0.6 } }); $( '#order_methods, #order_review' ).block({ message: null, overlayCSS: { background: '#fff url(' + wc_checkout_params.ajax_loader_url + ') no-repeat center', backgroundSize: '16px 16px', opacity: 0.6 } });
@ -96,6 +102,7 @@ jQuery(function($) {
$( 'a.showlogin' ).click( function() { $( 'a.showlogin' ).click( function() {
$( 'form.login' ).slideToggle(); $( 'form.login' ).slideToggle();
return false; return false;
}); });
@ -103,6 +110,7 @@ jQuery(function($) {
$( '.checkout_coupon' ).slideToggle( 400, function() { $( '.checkout_coupon' ).slideToggle( 400, function() {
$( '#coupon_code' ).focus(); $( '#coupon_code' ).focus();
}); });
return false; return false;
}); });
@ -113,12 +121,13 @@ jQuery(function($) {
} }
}).change(); }).change();
if ( wc_checkout_params.option_guest_checkout == 'yes' ) { if ( wc_checkout_params.option_guest_checkout === 'yes' ) {
$( 'div.create-account' ).hide(); $( 'div.create-account' ).hide();
$( 'input#createaccount' ).change( function() { $( 'input#createaccount' ).change( function() {
$( 'div.create-account' ).hide(); $( 'div.create-account' ).hide();
if ( $( this ).is( ':checked' ) ) { if ( $( this ).is( ':checked' ) ) {
$( 'div.create-account' ).slideDown(); $( 'div.create-account' ).slideDown();
} }
@ -136,7 +145,7 @@ jQuery(function($) {
if ( $required_siblings.size() ) { if ( $required_siblings.size() ) {
$required_siblings.each( function() { $required_siblings.each( function() {
if ( $(this).find('input.input-text').val() == '' || $(this).find('input.input-text').val() == 'undefined' ) { if ( $( this ).find( 'input.input-text' ).val() === '' || $( this ).find( 'input.input-text' ).val() === 'undefined' ) {
update_totals = false; update_totals = false;
} }
}); });
@ -157,8 +166,10 @@ jQuery(function($) {
.on( 'click', '.payment_methods input.input-radio', function() { .on( 'click', '.payment_methods input.input-radio', function() {
if ( $( '.payment_methods input.input-radio' ).length > 1 ) { if ( $( '.payment_methods input.input-radio' ).length > 1 ) {
var target_payment_box = $( 'div.payment_box.' + $( this ).attr( 'ID' ) ); var target_payment_box = $( 'div.payment_box.' + $( this ).attr( 'ID' ) );
if ( $( this ).is( ':checked' ) && ! target_payment_box.is( ':visible' ) ) { if ( $( this ).is( ':checked' ) && ! target_payment_box.is( ':visible' ) ) {
$( 'div.payment_box' ).filter( ':visible' ).slideUp( 250 ); $( 'div.payment_box' ).filter( ':visible' ).slideUp( 250 );
if ( $( this ).is( ':checked' ) ) { if ( $( this ).is( ':checked' ) ) {
$( 'div.payment_box.' + $( this ).attr( 'ID' ) ).slideDown( 250 ); $( 'div.payment_box.' + $( this ).attr( 'ID' ) ).slideDown( 250 );
} }
@ -166,6 +177,7 @@ jQuery(function($) {
} else { } else {
$( 'div.payment_box' ).show(); $( 'div.payment_box' ).show();
} }
if ( $( this ).data( 'order_button_text' ) ) { if ( $( this ).data( 'order_button_text' ) ) {
$( '#place_order' ).val( $( this ).data( 'order_button_text' ) ); $( '#place_order' ).val( $( this ).data( 'order_button_text' ) );
} else { } else {
@ -201,8 +213,11 @@ jQuery(function($) {
.on( 'keydown', '.address-field input.input-text, .update_totals_on_change input.input-text', function( e ){ .on( 'keydown', '.address-field input.input-text, .update_totals_on_change input.input-text', function( e ){
var code = e.keyCode || e.which; var code = e.keyCode || e.which;
if ( code == '9' )
if ( code === '9' ) {
return; return;
}
dirtyInput = this; dirtyInput = this;
clearTimeout( updateTimer ); clearTimeout( updateTimer );
updateTimer = setTimeout( input_changed, '1000' ); updateTimer = setTimeout( input_changed, '1000' );
@ -211,12 +226,12 @@ jQuery(function($) {
/* Inline validation */ /* Inline validation */
.on( 'blur input change', '.input-text, select', function() { .on( 'blur input change', '.input-text, select', function() {
var $this = $(this); var $this = $( this ),
var $parent = $this.closest('.form-row'); $parent = $this.closest( '.form-row' ),
var validated = true; validated = true;
if ( $parent.is( '.validate-required' ) ) { if ( $parent.is( '.validate-required' ) ) {
if ( $this.val() == '' ) { if ( $this.val() === '' ) {
$parent.removeClass( 'woocommerce-validated' ).addClass( 'woocommerce-invalid woocommerce-invalid-required-field' ); $parent.removeClass( 'woocommerce-validated' ).addClass( 'woocommerce-invalid woocommerce-invalid-required-field' );
validated = false; validated = false;
} }
@ -247,8 +262,9 @@ jQuery(function($) {
var $form = $( this ); var $form = $( this );
if ( $form.is('.processing') ) if ( $form.is( '.processing' ) ) {
return false; return false;
}
// Trigger a handler to let gateways manipulate the checkout if needed // Trigger a handler to let gateways manipulate the checkout if needed
if ( $form.triggerHandler( 'checkout_place_order' ) !== false && $form.triggerHandler( 'checkout_place_order_' + $( '#order_review input[name=payment_method]:checked' ).val() ) !== false ) { if ( $form.triggerHandler( 'checkout_place_order' ) !== false && $form.triggerHandler( 'checkout_place_order_' + $( '#order_review input[name=payment_method]:checked' ).val() ) !== false ) {
@ -257,8 +273,9 @@ jQuery(function($) {
var form_data = $form.data(); var form_data = $form.data();
if ( form_data["blockUI.isBlocked"] != 1 ) if ( form_data["blockUI.isBlocked"] != 1 ) {
$form.block({ message: null, overlayCSS: { background: '#fff url(' + wc_checkout_params.ajax_loader_url + ') no-repeat center', backgroundSize: '16px 16px', opacity: 0.6 } }); $form.block({ message: null, overlayCSS: { background: '#fff url(' + wc_checkout_params.ajax_loader_url + ') no-repeat center', backgroundSize: '16px 16px', opacity: 0.6 } });
}
$.ajax({ $.ajax({
type: 'POST', type: 'POST',
@ -269,26 +286,27 @@ jQuery(function($) {
try { try {
// Get the valid JSON only from the returned string // Get the valid JSON only from the returned string
if ( code.indexOf("<!--WC_START-->") >= 0 ) if ( code.indexOf( '<!--WC_START-->' ) >= 0 )
code = code.split("<!--WC_START-->")[1]; // Strip off before after WC_START code = code.split( '<!--WC_START-->' )[1]; // Strip off before after WC_START
if ( code.indexOf("<!--WC_END-->") >= 0 ) if ( code.indexOf( '<!--WC_END-->' ) >= 0 )
code = code.split("<!--WC_END-->")[0]; // Strip off anything after WC_END code = code.split( '<!--WC_END-->' )[0]; // Strip off anything after WC_END
// Parse // Parse
result = $.parseJSON( code ); result = $.parseJSON( code );
if ( result.result == 'success' ) { if ( result.result === 'success' ) {
window.location = decodeURI( result.redirect ); window.location = decodeURI( result.redirect );
} else if ( result.result == 'failure' ) { } else if ( result.result === 'failure' ) {
throw "Result failure"; throw 'Result failure';
} else { } else {
throw "Invalid response"; throw 'Invalid response';
} }
} }
catch( err ) { catch( err ) {
if ( result.reload == 'true' ) { if ( result.reload === 'true' ) {
window.location.reload(); window.location.reload();
return; return;
} }
@ -297,10 +315,11 @@ jQuery(function($) {
$( '.woocommerce-error, .woocommerce-message' ).remove(); $( '.woocommerce-error, .woocommerce-message' ).remove();
// Add new errors // Add new errors
if ( result.messages ) if ( result.messages ) {
$form.prepend( result.messages ); $form.prepend( result.messages );
else } else {
$form.prepend( code ); $form.prepend( code );
}
// Cancel processing // Cancel processing
$form.removeClass( 'processing' ).unblock(); $form.removeClass( 'processing' ).unblock();
@ -314,13 +333,13 @@ jQuery(function($) {
}, 1000 ); }, 1000 );
// Trigger update in case we need a fresh nonce // Trigger update in case we need a fresh nonce
if ( result.refresh == 'true' ) if ( result.refresh === 'true' )
$( 'body' ).trigger( 'update_checkout' ); $( 'body' ).trigger( 'update_checkout' );
$( 'body' ).trigger( 'checkout_error' ); $( 'body' ).trigger( 'checkout_error' );
} }
}, },
dataType: "html" dataType: 'html'
}); });
} }
@ -357,8 +376,9 @@ jQuery(function($) {
$( 'body' ).trigger( 'update_checkout' ); $( 'body' ).trigger( 'update_checkout' );
} }
}, },
dataType: "html" dataType: 'html'
}); });
return false; return false;
}); });
@ -371,7 +391,7 @@ jQuery(function($) {
}); });
// Update on page load // Update on page load
if ( wc_checkout_params.is_checkout == 1 ) { if ( wc_checkout_params.is_checkout === 1 ) {
$( 'body' ).trigger( 'init_checkout' ); $( 'body' ).trigger( 'init_checkout' );
} }

File diff suppressed because one or more lines are too long

View File

@ -1,10 +1,10 @@
jQuery( function( $ ) { jQuery( function( $ ) {
// Frontend Chosen selects // Frontend Chosen selects
$("select.country_select, select.state_select").chosen( { search_contains: true } ); $( 'select.country_select, select.state_select' ).chosen( { search_contains: true } );
$( 'body' ).bind( 'country_to_state_changed', function() { $( 'body' ).bind( 'country_to_state_changed', function() {
$("select.state_select").chosen().trigger("chosen:updated"); $( 'select.state_select' ).chosen().trigger( 'chosen:updated' );
}); });
}); });

View File

@ -1 +1 @@
jQuery(function(a){a("select.country_select, select.state_select").chosen({search_contains:!0}),a("body").bind("country_to_state_changed",function(){a("select.state_select").chosen().trigger("chosen:updated")})}); jQuery(function(e){e("select.country_select, select.state_select").chosen({search_contains:true});e("body").bind("country_to_state_changed",function(){e("select.state_select").chosen().trigger("chosen:updated")})})

View File

@ -1,27 +1,26 @@
jQuery( function( $ ) { jQuery( function( $ ) {
// wc_country_select_params is required to continue, ensure the object exists // wc_country_select_params is required to continue, ensure the object exists
if (typeof wc_country_select_params === "undefined") if ( typeof wc_country_select_params === 'undefined' ) {
return false; return false;
}
/* State/Country select boxes */ /* State/Country select boxes */
var states_json = wc_country_select_params.countries.replace(/&quot;/g, '"'); var states_json = wc_country_select_params.countries.replace( /&quot;/g, '"' ),
var states = $.parseJSON( states_json ); states = $.parseJSON( states_json );
$( 'select.country_to_state, input.country_to_state' ).change( function() { $( 'select.country_to_state, input.country_to_state' ).change( function() {
var country = $(this).val(); var country = $( this ).val(),
$statebox = $( this ).closest( 'div' ).find( '#billing_state, #shipping_state, #calc_shipping_state' ),
var $statebox = $(this).closest('div').find('#billing_state, #shipping_state, #calc_shipping_state'); $parent = $statebox.parent(),
var $parent = $statebox.parent(); input_name = $statebox.attr( 'name' ),
input_id = $statebox.attr( 'id' ),
var input_name = $statebox.attr('name'); value = $statebox.val(),
var input_id = $statebox.attr('id'); placeholder = $statebox.attr( 'placeholder' );
var value = $statebox.val();
var placeholder = $statebox.attr('placeholder');
if ( states[ country ] ) { if ( states[ country ] ) {
if (states[country].length == 0) { if ( states[ country ].length === 0 ) {
$statebox.parent().hide().find( '.chosen-container' ).remove(); $statebox.parent().hide().find( '.chosen-container' ).remove();
$statebox.replaceWith( '<input type="hidden" class="hidden" name="' + input_name + '" id="' + input_id + '" value="" placeholder="' + placeholder + '" />' ); $statebox.replaceWith( '<input type="hidden" class="hidden" name="' + input_name + '" id="' + input_id + '" value="" placeholder="' + placeholder + '" />' );
@ -30,17 +29,23 @@ jQuery(function($) {
} else { } else {
var options = ''; var options = '',
var state = states[country]; state = states[ country ];
for( var index in state ) { for( var index in state ) {
if ( state.hasOwnProperty( index ) ) {
options = options + '<option value="' + index + '">' + state[ index ] + '</option>'; options = options + '<option value="' + index + '">' + state[ index ] + '</option>';
} }
}
$statebox.parent().show(); $statebox.parent().show();
if ( $statebox.is( 'input' ) ) { if ( $statebox.is( 'input' ) ) {
// Change for select // Change for select
$statebox.replaceWith( '<select name="' + input_name + '" id="' + input_id + '" class="state_select" placeholder="' + placeholder + '"></select>' ); $statebox.replaceWith( '<select name="' + input_name + '" id="' + input_id + '" class="state_select" placeholder="' + placeholder + '"></select>' );
$statebox = $( this ).closest( 'div' ).find( '#billing_state, #shipping_state, #calc_shipping_state' ); $statebox = $( this ).closest( 'div' ).find( '#billing_state, #shipping_state, #calc_shipping_state' );
} }
$statebox.html( '<option value="">' + wc_country_select_params.i18n_select_state_text + '</option>' + options ); $statebox.html( '<option value="">' + wc_country_select_params.i18n_select_state_text + '</option>' + options );
$statebox.val( value ); $statebox.val( value );

View File

@ -1 +1 @@
jQuery(function(a){if("undefined"==typeof wc_country_select_params)return!1;var b=wc_country_select_params.countries.replace(/&quot;/g,'"'),c=a.parseJSON(b);a("select.country_to_state, input.country_to_state").change(function(){var b=a(this).val(),d=a(this).closest("div").find("#billing_state, #shipping_state, #calc_shipping_state"),e=d.parent(),f=d.attr("name"),g=d.attr("id"),h=d.val(),i=d.attr("placeholder");if(c[b])if(0==c[b].length)d.parent().hide().find(".chosen-container").remove(),d.replaceWith('<input type="hidden" class="hidden" name="'+f+'" id="'+g+'" value="" placeholder="'+i+'" />'),a("body").trigger("country_to_state_changed",[b,a(this).closest("div")]);else{var j="",k=c[b];for(var l in k)j=j+'<option value="'+l+'">'+k[l]+"</option>";d.parent().show(),d.is("input")&&(d.replaceWith('<select name="'+f+'" id="'+g+'" class="state_select" placeholder="'+i+'"></select>'),d=a(this).closest("div").find("#billing_state, #shipping_state, #calc_shipping_state")),d.html('<option value="">'+wc_country_select_params.i18n_select_state_text+"</option>"+j),d.val(h),a("body").trigger("country_to_state_changed",[b,a(this).closest("div")])}else d.is("select")?(e.show().find(".chosen-container").remove(),d.replaceWith('<input type="text" class="input-text" name="'+f+'" id="'+g+'" placeholder="'+i+'" />'),a("body").trigger("country_to_state_changed",[b,a(this).closest("div")])):d.is(".hidden")&&(e.show().find(".chosen-container").remove(),d.replaceWith('<input type="text" class="input-text" name="'+f+'" id="'+g+'" placeholder="'+i+'" />'),a("body").trigger("country_to_state_changed",[b,a(this).closest("div")]));a("body").trigger("country_to_state_changing",[b,a(this).closest("div")])}).change()}); jQuery(function(e){if(typeof wc_country_select_params==="undefined"){return false}var t=wc_country_select_params.countries.replace(/&quot;/g,'"'),n=e.parseJSON(t);e("select.country_to_state, input.country_to_state").change(function(){var t=e(this).val(),r=e(this).closest("div").find("#billing_state, #shipping_state, #calc_shipping_state"),i=r.parent(),s=r.attr("name"),o=r.attr("id"),u=r.val(),a=r.attr("placeholder");if(n[t]){if(n[t].length===0){r.parent().hide().find(".chosen-container").remove();r.replaceWith('<input type="hidden" class="hidden" name="'+s+'" id="'+o+'" value="" placeholder="'+a+'" />');e("body").trigger("country_to_state_changed",[t,e(this).closest("div")])}else{var f="",l=n[t];for(var c in l){if(l.hasOwnProperty(c)){f=f+'<option value="'+c+'">'+l[c]+"</option>"}}r.parent().show();if(r.is("input")){r.replaceWith('<select name="'+s+'" id="'+o+'" class="state_select" placeholder="'+a+'"></select>');r=e(this).closest("div").find("#billing_state, #shipping_state, #calc_shipping_state")}r.html('<option value="">'+wc_country_select_params.i18n_select_state_text+"</option>"+f);r.val(u);e("body").trigger("country_to_state_changed",[t,e(this).closest("div")])}}else{if(r.is("select")){i.show().find(".chosen-container").remove();r.replaceWith('<input type="text" class="input-text" name="'+s+'" id="'+o+'" placeholder="'+a+'" />');e("body").trigger("country_to_state_changed",[t,e(this).closest("div")])}else if(r.is(".hidden")){i.show().find(".chosen-container").remove();r.replaceWith('<input type="text" class="input-text" name="'+s+'" id="'+o+'" placeholder="'+a+'" />');e("body").trigger("country_to_state_changed",[t,e(this).closest("div")])}}e("body").trigger("country_to_state_changing",[t,e(this).closest("div")])}).change()})