commit
030aced0a2
|
@ -3,12 +3,12 @@ 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() {
|
||||
|
||||
|
@ -20,28 +20,34 @@ jQuery(function($) {
|
|||
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 } });
|
||||
|
@ -96,6 +102,7 @@ jQuery(function($) {
|
|||
|
||||
$( 'a.showlogin' ).click( function() {
|
||||
$( 'form.login' ).slideToggle();
|
||||
|
||||
return false;
|
||||
});
|
||||
|
||||
|
@ -103,6 +110,7 @@ jQuery(function($) {
|
|||
$( '.checkout_coupon' ).slideToggle( 400, function() {
|
||||
$( '#coupon_code' ).focus();
|
||||
});
|
||||
|
||||
return false;
|
||||
});
|
||||
|
||||
|
@ -113,12 +121,13 @@ jQuery(function($) {
|
|||
}
|
||||
}).change();
|
||||
|
||||
if ( wc_checkout_params.option_guest_checkout == 'yes' ) {
|
||||
if ( wc_checkout_params.option_guest_checkout === 'yes' ) {
|
||||
|
||||
$( 'div.create-account' ).hide();
|
||||
|
||||
$( 'input#createaccount' ).change( function() {
|
||||
$( 'div.create-account' ).hide();
|
||||
|
||||
if ( $( this ).is( ':checked' ) ) {
|
||||
$( 'div.create-account' ).slideDown();
|
||||
}
|
||||
|
@ -136,7 +145,7 @@ jQuery(function($) {
|
|||
|
||||
if ( $required_siblings.size() ) {
|
||||
$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;
|
||||
}
|
||||
});
|
||||
|
@ -157,8 +166,10 @@ jQuery(function($) {
|
|||
.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 );
|
||||
}
|
||||
|
@ -166,6 +177,7 @@ jQuery(function($) {
|
|||
} else {
|
||||
$( 'div.payment_box' ).show();
|
||||
}
|
||||
|
||||
if ( $( this ).data( 'order_button_text' ) ) {
|
||||
$( '#place_order' ).val( $( this ).data( 'order_button_text' ) );
|
||||
} else {
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -247,8 +262,9 @@ jQuery(function($) {
|
|||
|
||||
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 ) {
|
||||
|
@ -257,8 +273,9 @@ jQuery(function($) {
|
|||
|
||||
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 } });
|
||||
}
|
||||
|
||||
$.ajax({
|
||||
type: 'POST',
|
||||
|
@ -269,26 +286,27 @@ 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' ) {
|
||||
if ( result.result === 'success' ) {
|
||||
window.location = decodeURI( result.redirect );
|
||||
} else if ( result.result == 'failure' ) {
|
||||
throw "Result failure";
|
||||
} 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;
|
||||
}
|
||||
|
@ -297,10 +315,11 @@ jQuery(function($) {
|
|||
$( '.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();
|
||||
|
@ -314,13 +333,13 @@ jQuery(function($) {
|
|||
}, 1000 );
|
||||
|
||||
// Trigger update in case we need a fresh nonce
|
||||
if ( result.refresh == 'true' )
|
||||
if ( result.refresh === 'true' )
|
||||
$( 'body' ).trigger( 'update_checkout' );
|
||||
|
||||
$( 'body' ).trigger( 'checkout_error' );
|
||||
}
|
||||
},
|
||||
dataType: "html"
|
||||
dataType: 'html'
|
||||
});
|
||||
|
||||
}
|
||||
|
@ -357,8 +376,9 @@ jQuery(function($) {
|
|||
$( 'body' ).trigger( 'update_checkout' );
|
||||
}
|
||||
},
|
||||
dataType: "html"
|
||||
dataType: 'html'
|
||||
});
|
||||
|
||||
return false;
|
||||
});
|
||||
|
||||
|
@ -371,7 +391,7 @@ jQuery(function($) {
|
|||
});
|
||||
|
||||
// Update on page load
|
||||
if ( wc_checkout_params.is_checkout == 1 ) {
|
||||
if ( wc_checkout_params.is_checkout === 1 ) {
|
||||
$( 'body' ).trigger( 'init_checkout' );
|
||||
}
|
||||
|
||||
|
|
File diff suppressed because one or more lines are too long
|
@ -1,10 +1,10 @@
|
|||
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");
|
||||
$( 'select.state_select' ).chosen().trigger( 'chosen:updated' );
|
||||
});
|
||||
|
||||
});
|
||||
|
|
|
@ -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")})})
|
|
@ -1,27 +1,26 @@
|
|||
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(/"/g, '"');
|
||||
var states = $.parseJSON( states_json );
|
||||
var states_json = wc_country_select_params.countries.replace( /"/g, '"' ),
|
||||
states = $.parseJSON( states_json );
|
||||
|
||||
$( 'select.country_to_state, input.country_to_state' ).change( function() {
|
||||
|
||||
var country = $(this).val();
|
||||
|
||||
var $statebox = $(this).closest('div').find('#billing_state, #shipping_state, #calc_shipping_state');
|
||||
var $parent = $statebox.parent();
|
||||
|
||||
var input_name = $statebox.attr('name');
|
||||
var input_id = $statebox.attr('id');
|
||||
var value = $statebox.val();
|
||||
var placeholder = $statebox.attr('placeholder');
|
||||
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' );
|
||||
|
||||
if ( states[ country ] ) {
|
||||
if (states[country].length == 0) {
|
||||
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 + '" />' );
|
||||
|
@ -30,17 +29,23 @@ jQuery(function($) {
|
|||
|
||||
} else {
|
||||
|
||||
var options = '';
|
||||
var state = states[country];
|
||||
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' ) ) {
|
||||
// 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.html( '<option value="">' + wc_country_select_params.i18n_select_state_text + '</option>' + options );
|
||||
|
||||
$statebox.val( value );
|
||||
|
|
|
@ -1 +1 @@
|
|||
jQuery(function(a){if("undefined"==typeof wc_country_select_params)return!1;var b=wc_country_select_params.countries.replace(/"/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(/"/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()})
|
Loading…
Reference in New Issue