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

@ -1,50 +1,56 @@
jQuery(function($) {
jQuery( function( $ ) {
$.blockUI.defaults.overlayCSS.cursor = 'default';
// 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;
var updateTimer;
var dirtyInput = false;
var xhr;
var updateTimer,
dirtyInput = false,
xhr;
function update_checkout() {
if (xhr) xhr.abort();
if ( xhr ) xhr.abort();
var shipping_methods = [];
$('select.shipping_method, input[name^=shipping_method][type=radio]:checked, input[name^=shipping_method][type=hidden]').each( function( index, input ) {
shipping_methods[ $(this).data( 'index' ) ] = $(this).val();
$( 'select.shipping_method, input[name^=shipping_method][type=radio]:checked, input[name^=shipping_method][type=hidden]' ).each( function( index, input ) {
shipping_methods[ $( this ).data( 'index' ) ] = $( this ).val();
} );
var payment_method = $('#order_review input[name=payment_method]:checked').val();
var country = $('#billing_country').val();
var state = $('#billing_state').val();
var postcode = $('input#billing_postcode').val();
var city = $('#billing_city').val();
var address = $('input#billing_address_1').val();
var address_2 = $('input#billing_address_2').val();
var payment_method = $( '#order_review input[name=payment_method]:checked' ).val(),
country = $( '#billing_country' ).val(),
state = $( '#billing_state' ).val(),
postcode = $( 'input#billing_postcode' ).val(),
city = $( '#billing_city' ).val(),
address = $( 'input#billing_address_1' ).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 ) {
var s_country = $('#shipping_country').val();
var s_state = $('#shipping_state').val();
var s_postcode = $('input#shipping_postcode').val();
var s_city = $('#shipping_city').val();
var s_address = $('input#shipping_address_1').val();
var s_address_2 = $('input#shipping_address_2').val();
if ( $( '#ship-to-different-address input' ).is( ':checked' ) || $( '#ship-to-different-address input' ).size() === 0 ) {
s_country = $( '#shipping_country' ).val();
s_state = $( '#shipping_state' ).val();
s_postcode = $( 'input#shipping_postcode' ).val();
s_city = $( '#shipping_city' ).val();
s_address = $( 'input#shipping_address_1' ).val();
s_address_2 = $( 'input#shipping_address_2' ).val();
} else {
var s_country = country;
var s_state = state;
var s_postcode = postcode;
var s_city = city;
var s_address = address;
var s_address_2 = address_2;
s_country = country;
s_state = state;
s_postcode = postcode;
s_city = city;
s_address = address;
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 } });
var data = {
action: 'woocommerce_update_order_review',
@ -63,7 +69,7 @@ jQuery(function($) {
s_city: s_city,
s_address: s_address,
s_address_2: s_address_2,
post_data: $('form.checkout').serialize()
post_data: $( 'form.checkout' ).serialize()
};
xhr = $.ajax({
@ -72,10 +78,10 @@ jQuery(function($) {
data: data,
success: function( response ) {
if ( response ) {
var order_output = $($.parseHTML($.trim(response)));
$('#order_review').html(order_output.html());
$('#order_review').find('input[name=payment_method]:checked').click();
$('body').trigger('updated_checkout');
var order_output = $( $.parseHTML( $.trim( response ) ) );
$( '#order_review' ).html( order_output.html() );
$( '#order_review' ).find( 'input[name=payment_method]:checked' ).click();
$( 'body' ).trigger('updated_checkout' );
}
}
});
@ -83,44 +89,47 @@ jQuery(function($) {
}
// Event for updating the checkout
$('body').bind('update_checkout', function() {
clearTimeout(updateTimer);
$( 'body' ).bind( 'update_checkout', function() {
clearTimeout( updateTimer );
update_checkout();
});
$('p.password, form.login, .checkout_coupon, div.shipping_address').hide();
$( 'p.password, form.login, .checkout_coupon, div.shipping_address' ).hide();
$('input.show_password').change(function(){
$('p.password').slideToggle();
$( 'input.show_password' ).change( function() {
$( 'p.password' ).slideToggle();
});
$('a.showlogin').click(function(){
$('form.login').slideToggle();
$( 'a.showlogin' ).click( function() {
$( 'form.login' ).slideToggle();
return false;
});
$('a.showcoupon').click(function(){
$('.checkout_coupon').slideToggle(400, function() {
$('#coupon_code').focus();
$( 'a.showcoupon' ).click( function() {
$( '.checkout_coupon' ).slideToggle( 400, function() {
$( '#coupon_code' ).focus();
});
return false;
});
$('#ship-to-different-address input').change(function(){
$('div.shipping_address').hide();
if ($(this).is(':checked')) {
$('div.shipping_address').slideDown();
$( '#ship-to-different-address input' ).change( function() {
$( 'div.shipping_address' ).hide();
if ( $( this ).is( ':checked' ) ) {
$( 'div.shipping_address' ).slideDown();
}
}).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(){
$('div.create-account').hide();
if ($(this).is(':checked')) {
$('div.create-account').slideDown();
$( 'input#createaccount' ).change( function() {
$( 'div.create-account' ).hide();
if ( $( this ).is( ':checked' ) ) {
$( 'div.create-account' ).slideDown();
}
}).change();
@ -130,13 +139,13 @@ jQuery(function($) {
function input_changed() {
var update_totals = true;
if ( $(dirtyInput).size() ) {
if ( $( dirtyInput ).size() ) {
$required_siblings = $(dirtyInput).closest('.form-row').siblings('.address-field.validate-required');
$required_siblings = $( dirtyInput ).closest( '.form-row' ).siblings( '.address-field.validate-required' );
if ( $required_siblings.size() ) {
$required_siblings.each(function(){
if ( $(this).find('input.input-text').val() == '' || $(this).find('input.input-text').val() == 'undefined' ) {
$required_siblings.each( function() {
if ( $( this ).find( 'input.input-text' ).val() === '' || $( this ).find( 'input.input-text' ).val() === 'undefined' ) {
update_totals = false;
}
});
@ -146,45 +155,48 @@ jQuery(function($) {
if ( update_totals ) {
dirtyInput = false;
$('body').trigger('update_checkout');
$( 'body' ).trigger( 'update_checkout' );
}
}
$('#order_review')
$( '#order_review' )
/* Payment option selection */
.on( 'click', '.payment_methods input.input-radio', function() {
if ( $('.payment_methods input.input-radio').length > 1 ) {
var target_payment_box = $('div.payment_box.' + $(this).attr('ID') );
if ( $(this).is(':checked') && ! target_payment_box.is(':visible') ) {
$('div.payment_box').filter(':visible').slideUp(250);
if ( $(this).is(':checked') ) {
$('div.payment_box.' + $(this).attr('ID') ).slideDown(250);
if ( $( '.payment_methods input.input-radio' ).length > 1 ) {
var target_payment_box = $( 'div.payment_box.' + $( this ).attr( 'ID' ) );
if ( $( this ).is( ':checked' ) && ! target_payment_box.is( ':visible' ) ) {
$( 'div.payment_box' ).filter( ':visible' ).slideUp( 250 );
if ( $( this ).is( ':checked' ) ) {
$( 'div.payment_box.' + $( this ).attr( 'ID' ) ).slideDown( 250 );
}
}
} else {
$('div.payment_box').show();
$( 'div.payment_box' ).show();
}
if ( $(this).data('order_button_text') ) {
$('#place_order').val( $(this).data('order_button_text') );
if ( $( this ).data( 'order_button_text' ) ) {
$( '#place_order' ).val( $( this ).data( 'order_button_text' ) );
} else {
$('#place_order').val( $('#place_order').data( 'value' ) );
$( '#place_order' ).val( $( '#place_order' ).data( 'value' ) );
}
})
// Trigger initial click
.find('input[name=payment_method]:checked').click();
.find( 'input[name=payment_method]:checked' ).click();
$('form.checkout')
$( 'form.checkout' )
/* Update totals/taxes/shipping */
// Inputs/selects which update totals instantly
.on( 'input change', 'select.shipping_method, input[name^=shipping_method], #ship-to-different-address input, .update_totals_on_change select', function(){
.on( 'input change', 'select.shipping_method, input[name^=shipping_method], #ship-to-different-address input, .update_totals_on_change select', function() {
clearTimeout( updateTimer );
dirtyInput = false;
$('body').trigger('update_checkout');
$( 'body' ).trigger( 'update_checkout' );
})
// Address-fields which refresh totals when all required fields are filled
@ -201,8 +213,11 @@ jQuery(function($) {
.on( 'keydown', '.address-field input.input-text, .update_totals_on_change input.input-text', function( e ){
var code = e.keyCode || e.which;
if ( code == '9' )
if ( code === '9' ) {
return;
}
dirtyInput = this;
clearTimeout( updateTimer );
updateTimer = setTimeout( input_changed, '1000' );
@ -211,12 +226,12 @@ jQuery(function($) {
/* Inline validation */
.on( 'blur input change', '.input-text, select', function() {
var $this = $(this);
var $parent = $this.closest('.form-row');
var validated = true;
var $this = $( this ),
$parent = $this.closest( '.form-row' ),
validated = true;
if ( $parent.is( '.validate-required' ) ) {
if ( $this.val() == '' ) {
if ( $this.val() === '' ) {
$parent.removeClass( 'woocommerce-validated' ).addClass( 'woocommerce-invalid woocommerce-invalid-required-field' );
validated = false;
}
@ -245,20 +260,22 @@ jQuery(function($) {
.submit( function() {
clearTimeout( updateTimer );
var $form = $(this);
var $form = $( this );
if ( $form.is('.processing') )
if ( $form.is( '.processing' ) ) {
return false;
}
// 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 ) {
$form.addClass('processing');
$form.addClass( 'processing' );
var form_data = $form.data();
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}});
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 } });
}
$.ajax({
type: 'POST',
@ -269,58 +286,60 @@ jQuery(function($) {
try {
// Get the valid JSON only from the returned string
if ( code.indexOf("<!--WC_START-->") >= 0 )
code = code.split("<!--WC_START-->")[1]; // Strip off before after WC_START
if ( code.indexOf( '<!--WC_START-->' ) >= 0 )
code = code.split( '<!--WC_START-->' )[1]; // Strip off before after WC_START
if ( code.indexOf("<!--WC_END-->") >= 0 )
code = code.split("<!--WC_END-->")[0]; // Strip off anything after WC_END
if ( code.indexOf( '<!--WC_END-->' ) >= 0 )
code = code.split( '<!--WC_END-->' )[0]; // Strip off anything after WC_END
// Parse
result = $.parseJSON( code );
if ( result.result == 'success' ) {
window.location = decodeURI(result.redirect);
} else if ( result.result == 'failure' ) {
throw "Result failure";
if ( result.result === 'success' ) {
window.location = decodeURI( result.redirect );
} else if ( result.result === 'failure' ) {
throw 'Result failure';
} else {
throw "Invalid response";
throw 'Invalid response';
}
}
catch( err ) {
if ( result.reload == 'true' ) {
if ( result.reload === 'true' ) {
window.location.reload();
return;
}
// Remove old errors
$('.woocommerce-error, .woocommerce-message').remove();
$( '.woocommerce-error, .woocommerce-message' ).remove();
// Add new errors
if ( result.messages )
if ( result.messages ) {
$form.prepend( result.messages );
else
} else {
$form.prepend( code );
}
// Cancel processing
$form.removeClass('processing').unblock();
$form.removeClass( 'processing' ).unblock();
// Lose focus for all fields
$form.find( '.input-text, select' ).blur();
// Scroll to top
$('html, body').animate({
scrollTop: ($('form.checkout').offset().top - 100)
}, 1000);
$( 'html, body' ).animate({
scrollTop: ( $( 'form.checkout' ).offset().top - 100 )
}, 1000 );
// Trigger update in case we need a fresh nonce
if ( result.refresh == 'true' )
$('body').trigger('update_checkout');
if ( result.refresh === 'true' )
$( 'body' ).trigger( 'update_checkout' );
$('body').trigger('checkout_error');
$( 'body' ).trigger( 'checkout_error' );
}
},
dataType: "html"
dataType: 'html'
});
}
@ -329,17 +348,17 @@ jQuery(function($) {
});
/* AJAX Coupon Form Submission */
$('form.checkout_coupon').submit( function() {
var $form = $(this);
$( 'form.checkout_coupon' ).submit( function() {
var $form = $( this );
if ( $form.is('.processing') ) return false;
if ( $form.is( '.processing' ) ) return false;
$form.addClass('processing').block({message: null, overlayCSS: {background: '#fff url(' + wc_checkout_params.ajax_loader_url + ') no-repeat center', backgroundSize: '16px 16px', opacity: 0.6}});
$form.addClass( 'processing' ).block({ message: null, overlayCSS: {background: '#fff url(' + wc_checkout_params.ajax_loader_url + ') no-repeat center', backgroundSize: '16px 16px', opacity: 0.6 } });
var data = {
action: 'woocommerce_apply_coupon',
security: wc_checkout_params.apply_coupon_nonce,
coupon_code: $form.find('input[name=coupon_code]').val()
coupon_code: $form.find( 'input[name=coupon_code]' ).val()
};
$.ajax({
@ -347,32 +366,33 @@ jQuery(function($) {
url: wc_checkout_params.ajax_url,
data: data,
success: function( code ) {
$('.woocommerce-error, .woocommerce-message').remove();
$form.removeClass('processing').unblock();
$( '.woocommerce-error, .woocommerce-message' ).remove();
$form.removeClass( 'processing' ).unblock();
if ( code ) {
$form.before( code );
$form.slideUp();
$('body').trigger('update_checkout');
$( 'body' ).trigger( 'update_checkout' );
}
},
dataType: "html"
dataType: 'html'
});
return false;
});
$('body')
$( 'body' )
// Init trigger
.bind('init_checkout', function() {
$('#billing_country, #shipping_country, .country_to_state').change();
$('body').trigger('update_checkout');
.bind( 'init_checkout', function() {
$( '#billing_country, #shipping_country, .country_to_state' ).change();
$( 'body' ).trigger( 'update_checkout' );
});
// Update on page load
if ( wc_checkout_params.is_checkout == 1 ) {
$('body').trigger('init_checkout');
if ( wc_checkout_params.is_checkout === 1 ) {
$( '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
$("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(){
$("select.state_select").chosen().trigger("chosen:updated");
$( 'body' ).bind( 'country_to_state_changed', function() {
$( '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,72 +1,77 @@
jQuery(function($) {
jQuery( function( $ ) {
// 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;
}
/* State/Country select boxes */
var states_json = wc_country_select_params.countries.replace(/&quot;/g, '"');
var states = $.parseJSON( states_json );
var states_json = wc_country_select_params.countries.replace( /&quot;/g, '"' ),
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' ),
$parent = $statebox.parent(),
input_name = $statebox.attr( 'name' ),
input_id = $statebox.attr( 'id' ),
value = $statebox.val(),
placeholder = $statebox.attr( 'placeholder' );
var $statebox = $(this).closest('div').find('#billing_state, #shipping_state, #calc_shipping_state');
var $parent = $statebox.parent();
if ( states[ country ] ) {
if ( states[ country ].length === 0 ) {
var input_name = $statebox.attr('name');
var input_id = $statebox.attr('id');
var value = $statebox.val();
var placeholder = $statebox.attr('placeholder');
$statebox.parent().hide().find( '.chosen-container' ).remove();
$statebox.replaceWith( '<input type="hidden" class="hidden" name="' + input_name + '" id="' + input_id + '" value="" placeholder="' + placeholder + '" />' );
if (states[country]) {
if (states[country].length == 0) {
$statebox.parent().hide().find('.chosen-container').remove();
$statebox.replaceWith('<input type="hidden" class="hidden" name="' + input_name + '" id="' + input_id + '" value="" placeholder="' + placeholder + '" />');
$('body').trigger('country_to_state_changed', [country, $(this).closest('div')]);
$( 'body' ).trigger( 'country_to_state_changed', [country, $( this ).closest( 'div' )] );
} else {
var options = '';
var state = states[country];
for(var index in state) {
options = options + '<option value="' + index + '">' + state[index] + '</option>';
var options = '',
state = states[ country ];
for( var index in state ) {
if ( state.hasOwnProperty( index ) ) {
options = options + '<option value="' + index + '">' + state[ index ] + '</option>';
}
}
$statebox.parent().show();
if ($statebox.is('input')) {
if ( $statebox.is( 'input' ) ) {
// Change for 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.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.html( '<option value="">' + wc_country_select_params.i18n_select_state_text + '</option>' + options);
$statebox.val(value);
$statebox.html( '<option value="">' + wc_country_select_params.i18n_select_state_text + '</option>' + options );
$('body').trigger('country_to_state_changed', [country, $(this).closest('div')]);
$statebox.val( value );
$( 'body' ).trigger( 'country_to_state_changed', [country, $( this ).closest( 'div' )] );
}
} else {
if ($statebox.is('select')) {
if ( $statebox.is( 'select' ) ) {
$parent.show().find('.chosen-container').remove();
$statebox.replaceWith('<input type="text" class="input-text" name="' + input_name + '" id="' + input_id + '" placeholder="' + placeholder + '" />');
$parent.show().find( '.chosen-container' ).remove();
$statebox.replaceWith( '<input type="text" class="input-text" name="' + input_name + '" id="' + input_id + '" placeholder="' + placeholder + '" />' );
$('body').trigger('country_to_state_changed', [country, $(this).closest('div')]);
$( 'body' ).trigger( 'country_to_state_changed', [country, $( this ).closest( 'div' )] );
} else if ($statebox.is('.hidden')) {
} else if ( $statebox.is( '.hidden' ) ) {
$parent.show().find('.chosen-container').remove();
$statebox.replaceWith('<input type="text" class="input-text" name="' + input_name + '" id="' + input_id + '" placeholder="' + placeholder + '" />');
$parent.show().find( '.chosen-container' ).remove();
$statebox.replaceWith( '<input type="text" class="input-text" name="' + input_name + '" id="' + input_id + '" placeholder="' + placeholder + '" />' );
$('body').trigger('country_to_state_changed', [country, $(this).closest('div')]);
$( 'body' ).trigger( 'country_to_state_changed', [country, $( this ).closest( 'div' )] );
}
}
$('body').trigger('country_to_state_changing', [country, $(this).closest('div')]);
$( 'body' ).trigger( 'country_to_state_changing', [country, $( this ).closest( 'div' )] );
}).change();

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()})