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,81 +1,87 @@
jQuery(function($) { 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() {
if (xhr) xhr.abort(); if ( xhr ) xhr.abort();
var shipping_methods = []; var shipping_methods = [];
$('select.shipping_method, input[name^=shipping_method][type=radio]:checked, input[name^=shipping_method][type=hidden]').each( function( index, input ) { $( '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(); 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 } });
var data = { var data = {
action: 'woocommerce_update_order_review', action: 'woocommerce_update_order_review',
security: wc_checkout_params.update_order_review_nonce, security: wc_checkout_params.update_order_review_nonce,
shipping_method: shipping_methods, shipping_method: shipping_methods,
payment_method: payment_method, payment_method: payment_method,
country: country, country: country,
state: state, state: state,
postcode: postcode, postcode: postcode,
city: city, city: city,
address: address, address: address,
address_2: address_2, address_2: address_2,
s_country: s_country, s_country: s_country,
s_state: s_state, s_state: s_state,
s_postcode: s_postcode, s_postcode: s_postcode,
s_city: s_city, s_city: s_city,
s_address: s_address, s_address: s_address,
s_address_2: s_address_2, s_address_2: s_address_2,
post_data: $('form.checkout').serialize() post_data: $( 'form.checkout' ).serialize()
}; };
xhr = $.ajax({ xhr = $.ajax({
type: 'POST', type: 'POST',
url: wc_checkout_params.ajax_url, url: wc_checkout_params.ajax_url,
data: data, data: data,
success: function( response ) { success: function( response ) {
if ( response ) { if ( response ) {
var order_output = $($.parseHTML($.trim(response))); var order_output = $( $.parseHTML( $.trim( response ) ) );
$('#order_review').html(order_output.html()); $( '#order_review' ).html( order_output.html() );
$('#order_review').find('input[name=payment_method]:checked').click(); $( '#order_review' ).find( 'input[name=payment_method]:checked' ).click();
$('body').trigger('updated_checkout'); $( 'body' ).trigger('updated_checkout' );
} }
} }
}); });
@ -83,44 +89,47 @@ jQuery(function($) {
} }
// Event for updating the checkout // Event for updating the checkout
$('body').bind('update_checkout', function() { $( 'body' ).bind( 'update_checkout', function() {
clearTimeout(updateTimer); clearTimeout( updateTimer );
update_checkout(); 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(){ $( 'input.show_password' ).change( function() {
$('p.password').slideToggle(); $( 'p.password' ).slideToggle();
}); });
$('a.showlogin').click(function(){ $( 'a.showlogin' ).click( function() {
$('form.login').slideToggle(); $( 'form.login' ).slideToggle();
return false; return false;
}); });
$('a.showcoupon').click(function(){ $( 'a.showcoupon' ).click( function() {
$('.checkout_coupon').slideToggle(400, function() { $( '.checkout_coupon' ).slideToggle( 400, function() {
$('#coupon_code').focus(); $( '#coupon_code' ).focus();
}); });
return false; return false;
}); });
$('#ship-to-different-address input').change(function(){ $( '#ship-to-different-address input' ).change( function() {
$('div.shipping_address').hide(); $( 'div.shipping_address' ).hide();
if ($(this).is(':checked')) { if ( $( this ).is( ':checked' ) ) {
$('div.shipping_address').slideDown(); $( 'div.shipping_address' ).slideDown();
} }
}).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')) {
$('div.create-account').slideDown(); if ( $( this ).is( ':checked' ) ) {
$( 'div.create-account' ).slideDown();
} }
}).change(); }).change();
@ -130,61 +139,64 @@ jQuery(function($) {
function input_changed() { function input_changed() {
var update_totals = true; 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() ) { 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;
} }
}); });
} }
} }
if ( update_totals ) { if ( update_totals ) {
dirtyInput = false; dirtyInput = false;
$('body').trigger('update_checkout'); $( 'body' ).trigger( 'update_checkout' );
} }
} }
$('#order_review') $( '#order_review' )
/* Payment option selection */ /* Payment option selection */
.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') ) {
$('div.payment_box').filter(':visible').slideUp(250); if ( $( this ).is( ':checked' ) && ! target_payment_box.is( ':visible' ) ) {
if ( $(this).is(':checked') ) { $( 'div.payment_box' ).filter( ':visible' ).slideUp( 250 );
$('div.payment_box.' + $(this).attr('ID') ).slideDown(250);
if ( $( this ).is( ':checked' ) ) {
$( 'div.payment_box.' + $( this ).attr( 'ID' ) ).slideDown( 250 );
} }
} }
} else { } 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 { } else {
$('#place_order').val( $('#place_order').data( 'value' ) ); $( '#place_order' ).val( $( '#place_order' ).data( 'value' ) );
} }
}) })
// Trigger initial click // 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 */ /* Update totals/taxes/shipping */
// Inputs/selects which update totals instantly // 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 ); clearTimeout( updateTimer );
dirtyInput = false; dirtyInput = false;
$('body').trigger('update_checkout'); $( 'body' ).trigger( 'update_checkout' );
}) })
// Address-fields which refresh totals when all required fields are filled // 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 ){ .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;
} }
@ -245,82 +260,86 @@ jQuery(function($) {
.submit( function() { .submit( function() {
clearTimeout( updateTimer ); clearTimeout( updateTimer );
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 ) {
$form.addClass('processing'); $form.addClass( 'processing' );
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',
url: wc_checkout_params.checkout_url, url: wc_checkout_params.checkout_url,
data: $form.serialize(), data: $form.serialize(),
success: function( code ) { success: function( code ) {
var result = ''; var result = '';
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;
} }
// Remove old errors // Remove old errors
$('.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();
// Lose focus for all fields // Lose focus for all fields
$form.find( '.input-text, select' ).blur(); $form.find( '.input-text, select' ).blur();
// Scroll to top // Scroll to top
$('html, body').animate({ $( 'html, body' ).animate({
scrollTop: ($('form.checkout').offset().top - 100) scrollTop: ( $( 'form.checkout' ).offset().top - 100 )
}, 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'
}); });
} }
@ -329,50 +348,51 @@ jQuery(function($) {
}); });
/* AJAX Coupon Form Submission */ /* AJAX Coupon Form Submission */
$('form.checkout_coupon').submit( function() { $( 'form.checkout_coupon' ).submit( function() {
var $form = $(this); 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 = { var data = {
action: 'woocommerce_apply_coupon', action: 'woocommerce_apply_coupon',
security: wc_checkout_params.apply_coupon_nonce, 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({ $.ajax({
type: 'POST', type: 'POST',
url: wc_checkout_params.ajax_url, url: wc_checkout_params.ajax_url,
data: data, data: data,
success: function( code ) { success: function( code ) {
$('.woocommerce-error, .woocommerce-message').remove(); $( '.woocommerce-error, .woocommerce-message' ).remove();
$form.removeClass('processing').unblock(); $form.removeClass( 'processing' ).unblock();
if ( code ) { if ( code ) {
$form.before( code ); $form.before( code );
$form.slideUp(); $form.slideUp();
$('body').trigger('update_checkout'); $( 'body' ).trigger( 'update_checkout' );
} }
}, },
dataType: "html" dataType: 'html'
}); });
return false; return false;
}); });
$('body') $( 'body' )
// Init trigger // Init trigger
.bind('init_checkout', function() { .bind( 'init_checkout', function() {
$('#billing_country, #shipping_country, .country_to_state').change(); $( '#billing_country, #shipping_country, .country_to_state' ).change();
$('body').trigger('update_checkout'); $( 'body' ).trigger( 'update_checkout' );
}); });
// 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,72 +1,77 @@
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' ),
$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'); if ( states[ country ] ) {
var $parent = $statebox.parent(); if ( states[ country ].length === 0 ) {
var input_name = $statebox.attr('name'); $statebox.parent().hide().find( '.chosen-container' ).remove();
var input_id = $statebox.attr('id'); $statebox.replaceWith( '<input type="hidden" class="hidden" name="' + input_name + '" id="' + input_id + '" value="" placeholder="' + placeholder + '" />' );
var value = $statebox.val();
var placeholder = $statebox.attr('placeholder');
if (states[country]) { $( 'body' ).trigger( 'country_to_state_changed', [country, $( this ).closest( 'div' )] );
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')]);
} else { } else {
var options = ''; var options = '',
var state = states[country]; state = states[ country ];
for(var index in state) {
options = options + '<option value="' + index + '">' + state[index] + '</option>'; for( var index in state ) {
if ( state.hasOwnProperty( index ) ) {
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.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 { } else {
if ($statebox.is('select')) { if ( $statebox.is( 'select' ) ) {
$parent.show().find('.chosen-container').remove(); $parent.show().find( '.chosen-container' ).remove();
$statebox.replaceWith('<input type="text" class="input-text" name="' + input_name + '" id="' + input_id + '" placeholder="' + placeholder + '" />'); $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(); $parent.show().find( '.chosen-container' ).remove();
$statebox.replaceWith('<input type="text" class="input-text" name="' + input_name + '" id="' + input_id + '" placeholder="' + placeholder + '" />'); $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(); }).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()})