diff --git a/assets/js/frontend/checkout.js b/assets/js/frontend/checkout.js index e408c093634..b3d3cd3c31e 100644 --- a/assets/js/frontend/checkout.js +++ b/assets/js/frontend/checkout.js @@ -1,81 +1,87 @@ -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', - security: wc_checkout_params.update_order_review_nonce, - shipping_method: shipping_methods, - payment_method: payment_method, - country: country, - state: state, - postcode: postcode, - city: city, - address: address, - address_2: address_2, - s_country: s_country, - s_state: s_state, - s_postcode: s_postcode, - s_city: s_city, - s_address: s_address, - s_address_2: s_address_2, - post_data: $('form.checkout').serialize() + action: 'woocommerce_update_order_review', + security: wc_checkout_params.update_order_review_nonce, + shipping_method: shipping_methods, + payment_method: payment_method, + country: country, + state: state, + postcode: postcode, + city: city, + address: address, + address_2: address_2, + s_country: s_country, + s_state: s_state, + s_postcode: s_postcode, + s_city: s_city, + s_address: s_address, + s_address_2: s_address_2, + post_data: $( 'form.checkout' ).serialize() }; xhr = $.ajax({ - type: 'POST', - url: wc_checkout_params.ajax_url, - data: data, - success: function( response ) { + type: 'POST', + url: wc_checkout_params.ajax_url, + 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,61 +139,64 @@ 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; } - }); + }); } } 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,82 +260,86 @@ 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', - url: wc_checkout_params.checkout_url, - data: $form.serialize(), - success: function( code ) { + type: 'POST', + url: wc_checkout_params.checkout_url, + data: $form.serialize(), + success: function( code ) { var result = ''; try { // Get the valid JSON only from the returned string - if ( code.indexOf("") >= 0 ) - code = code.split("")[1]; // Strip off before after WC_START + if ( code.indexOf( '' ) >= 0 ) + code = code.split( '' )[1]; // Strip off before after WC_START - if ( code.indexOf("") >= 0 ) - code = code.split("")[0]; // Strip off anything after WC_END + if ( code.indexOf( '' ) >= 0 ) + code = code.split( '' )[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(); + // Cancel processing + $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,50 +348,51 @@ 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() + action: 'woocommerce_apply_coupon', + security: wc_checkout_params.apply_coupon_nonce, + coupon_code: $form.find( 'input[name=coupon_code]' ).val() }; $.ajax({ - type: 'POST', - url: wc_checkout_params.ajax_url, - data: data, - success: function( code ) { - $('.woocommerce-error, .woocommerce-message').remove(); - $form.removeClass('processing').unblock(); + type: 'POST', + url: wc_checkout_params.ajax_url, + data: data, + success: function( code ) { + $( '.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' ); } }); diff --git a/assets/js/frontend/checkout.min.js b/assets/js/frontend/checkout.min.js index c2a1b244a5a..7f876ea8c42 100644 --- a/assets/js/frontend/checkout.min.js +++ b/assets/js/frontend/checkout.min.js @@ -1 +1 @@ -jQuery(function(a){function b(){e&&e.abort();var b=[];a("select.shipping_method, input[name^=shipping_method][type=radio]:checked, input[name^=shipping_method][type=hidden]").each(function(){b[a(this).data("index")]=a(this).val()});var c=a("#order_review input[name=payment_method]:checked").val(),d=a("#billing_country").val(),f=a("#billing_state").val(),g=a("input#billing_postcode").val(),h=a("#billing_city").val(),i=a("input#billing_address_1").val(),j=a("input#billing_address_2").val();if(a("#ship-to-different-address input").is(":checked")||0==a("#ship-to-different-address input").size())var k=a("#shipping_country").val(),l=a("#shipping_state").val(),m=a("input#shipping_postcode").val(),n=a("#shipping_city").val(),o=a("input#shipping_address_1").val(),p=a("input#shipping_address_2").val();else var k=d,l=f,m=g,n=h,o=i,p=j;a("#order_methods, #order_review").block({message:null,overlayCSS:{background:"#fff url("+wc_checkout_params.ajax_loader_url+") no-repeat center",backgroundSize:"16px 16px",opacity:.6}});var q={action:"woocommerce_update_order_review",security:wc_checkout_params.update_order_review_nonce,shipping_method:b,payment_method:c,country:d,state:f,postcode:g,city:h,address:i,address_2:j,s_country:k,s_state:l,s_postcode:m,s_city:n,s_address:o,s_address_2:p,post_data:a("form.checkout").serialize()};e=a.ajax({type:"POST",url:wc_checkout_params.ajax_url,data:q,success:function(b){if(b){var c=a(a.parseHTML(a.trim(b)));a("#order_review").html(c.html()),a("#order_review").find("input[name=payment_method]:checked").click(),a("body").trigger("updated_checkout")}}})}function c(){var b=!0;a(f).size()&&($required_siblings=a(f).closest(".form-row").siblings(".address-field.validate-required"),$required_siblings.size()&&$required_siblings.each(function(){(""==a(this).find("input.input-text").val()||"undefined"==a(this).find("input.input-text").val())&&(b=!1)})),b&&(f=!1,a("body").trigger("update_checkout"))}if(a.blockUI.defaults.overlayCSS.cursor="default","undefined"==typeof wc_checkout_params)return!1;var d,e,f=!1;a("body").bind("update_checkout",function(){clearTimeout(d),b()}),a("p.password, form.login, .checkout_coupon, div.shipping_address").hide(),a("input.show_password").change(function(){a("p.password").slideToggle()}),a("a.showlogin").click(function(){return a("form.login").slideToggle(),!1}),a("a.showcoupon").click(function(){return a(".checkout_coupon").slideToggle(400,function(){a("#coupon_code").focus()}),!1}),a("#ship-to-different-address input").change(function(){a("div.shipping_address").hide(),a(this).is(":checked")&&a("div.shipping_address").slideDown()}).change(),"yes"==wc_checkout_params.option_guest_checkout&&(a("div.create-account").hide(),a("input#createaccount").change(function(){a("div.create-account").hide(),a(this).is(":checked")&&a("div.create-account").slideDown()}).change()),a("#order_review").on("click",".payment_methods input.input-radio",function(){if(a(".payment_methods input.input-radio").length>1){var b=a("div.payment_box."+a(this).attr("ID"));a(this).is(":checked")&&!b.is(":visible")&&(a("div.payment_box").filter(":visible").slideUp(250),a(this).is(":checked")&&a("div.payment_box."+a(this).attr("ID")).slideDown(250))}else a("div.payment_box").show();a("#place_order").val(a(this).data("order_button_text")?a(this).data("order_button_text"):a("#place_order").data("value"))}).find("input[name=payment_method]:checked").click(),a("form.checkout").on("input change","select.shipping_method, input[name^=shipping_method], #ship-to-different-address input, .update_totals_on_change select",function(){clearTimeout(d),f=!1,a("body").trigger("update_checkout")}).on("input change",".address-field input.input-text, .update_totals_on_change input.input-text",function(){f&&c()}).on("input change",".address-field select",function(){f=this,c()}).on("keydown",".address-field input.input-text, .update_totals_on_change input.input-text",function(a){var b=a.keyCode||a.which;"9"!=b&&(f=this,clearTimeout(d),d=setTimeout(c,"1000"))}).on("blur input change",".input-text, select",function(){var b=a(this),c=b.closest(".form-row"),d=!0;if(c.is(".validate-required")&&""==b.val()&&(c.removeClass("woocommerce-validated").addClass("woocommerce-invalid woocommerce-invalid-required-field"),d=!1),c.is(".validate-email")&&b.val()){var e=new RegExp(/^((([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+(\.([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+)*)|((\x22)((((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(([\x01-\x08\x0b\x0c\x0e-\x1f\x7f]|\x21|[\x23-\x5b]|[\x5d-\x7e]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(\\([\x01-\x09\x0b\x0c\x0d-\x7f]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]))))*(((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(\x22)))@((([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)+(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.?$/i);e.test(b.val())||(c.removeClass("woocommerce-validated").addClass("woocommerce-invalid woocommerce-invalid-email"),d=!1)}d&&c.removeClass("woocommerce-invalid woocommerce-invalid-required-field").addClass("woocommerce-validated")}).submit(function(){clearTimeout(d);var b=a(this);if(b.is(".processing"))return!1;if(b.triggerHandler("checkout_place_order")!==!1&&b.triggerHandler("checkout_place_order_"+a("#order_review input[name=payment_method]:checked").val())!==!1){b.addClass("processing");var c=b.data();1!=c["blockUI.isBlocked"]&&b.block({message:null,overlayCSS:{background:"#fff url("+wc_checkout_params.ajax_loader_url+") no-repeat center",backgroundSize:"16px 16px",opacity:.6}}),a.ajax({type:"POST",url:wc_checkout_params.checkout_url,data:b.serialize(),success:function(c){var d="";try{if(c.indexOf("")>=0&&(c=c.split("")[1]),c.indexOf("")>=0&&(c=c.split("")[0]),d=a.parseJSON(c),"success"!=d.result)throw"failure"==d.result?"Result failure":"Invalid response";window.location=decodeURI(d.redirect)}catch(e){if("true"==d.reload)return void window.location.reload();a(".woocommerce-error, .woocommerce-message").remove(),b.prepend(d.messages?d.messages:c),b.removeClass("processing").unblock(),b.find(".input-text, select").blur(),a("html, body").animate({scrollTop:a("form.checkout").offset().top-100},1e3),"true"==d.refresh&&a("body").trigger("update_checkout"),a("body").trigger("checkout_error")}},dataType:"html"})}return!1}),a("form.checkout_coupon").submit(function(){var b=a(this);if(b.is(".processing"))return!1;b.addClass("processing").block({message:null,overlayCSS:{background:"#fff url("+wc_checkout_params.ajax_loader_url+") no-repeat center",backgroundSize:"16px 16px",opacity:.6}});var c={action:"woocommerce_apply_coupon",security:wc_checkout_params.apply_coupon_nonce,coupon_code:b.find("input[name=coupon_code]").val()};return a.ajax({type:"POST",url:wc_checkout_params.ajax_url,data:c,success:function(c){a(".woocommerce-error, .woocommerce-message").remove(),b.removeClass("processing").unblock(),c&&(b.before(c),b.slideUp(),a("body").trigger("update_checkout"))},dataType:"html"}),!1}),a("body").bind("init_checkout",function(){a("#billing_country, #shipping_country, .country_to_state").change(),a("body").trigger("update_checkout")}),1==wc_checkout_params.is_checkout&&a("body").trigger("init_checkout")}); \ No newline at end of file +jQuery(function(e){function i(){if(r)r.abort();var t=[];e("select.shipping_method, input[name^=shipping_method][type=radio]:checked, input[name^=shipping_method][type=hidden]").each(function(n,r){t[e(this).data("index")]=e(this).val()});var n=e("#order_review input[name=payment_method]:checked").val(),i=e("#billing_country").val(),s=e("#billing_state").val(),o=e("input#billing_postcode").val(),u=e("#billing_city").val(),a=e("input#billing_address_1").val(),f=e("input#billing_address_2").val(),l,c,h,p,d,v;if(e("#ship-to-different-address input").is(":checked")||e("#ship-to-different-address input").size()===0){l=e("#shipping_country").val();c=e("#shipping_state").val();h=e("input#shipping_postcode").val();p=e("#shipping_city").val();d=e("input#shipping_address_1").val();v=e("input#shipping_address_2").val()}else{l=i;c=s;h=o;p=u;d=a;v=f}e("#order_methods, #order_review").block({message:null,overlayCSS:{background:"#fff url("+wc_checkout_params.ajax_loader_url+") no-repeat center",backgroundSize:"16px 16px",opacity:.6}});var m={action:"woocommerce_update_order_review",security:wc_checkout_params.update_order_review_nonce,shipping_method:t,payment_method:n,country:i,state:s,postcode:o,city:u,address:a,address_2:f,s_country:l,s_state:c,s_postcode:h,s_city:p,s_address:d,s_address_2:v,post_data:e("form.checkout").serialize()};r=e.ajax({type:"POST",url:wc_checkout_params.ajax_url,data:m,success:function(t){if(t){var n=e(e.parseHTML(e.trim(t)));e("#order_review").html(n.html());e("#order_review").find("input[name=payment_method]:checked").click();e("body").trigger("updated_checkout")}}})}function s(){var t=true;if(e(n).size()){$required_siblings=e(n).closest(".form-row").siblings(".address-field.validate-required");if($required_siblings.size()){$required_siblings.each(function(){if(e(this).find("input.input-text").val()===""||e(this).find("input.input-text").val()==="undefined"){t=false}})}}if(t){n=false;e("body").trigger("update_checkout")}}e.blockUI.defaults.overlayCSS.cursor="default";if(typeof wc_checkout_params==="undefined")return false;var t,n=false,r;e("body").bind("update_checkout",function(){clearTimeout(t);i()});e("p.password, form.login, .checkout_coupon, div.shipping_address").hide();e("input.show_password").change(function(){e("p.password").slideToggle()});e("a.showlogin").click(function(){e("form.login").slideToggle();return false});e("a.showcoupon").click(function(){e(".checkout_coupon").slideToggle(400,function(){e("#coupon_code").focus()});return false});e("#ship-to-different-address input").change(function(){e("div.shipping_address").hide();if(e(this).is(":checked")){e("div.shipping_address").slideDown()}}).change();if(wc_checkout_params.option_guest_checkout==="yes"){e("div.create-account").hide();e("input#createaccount").change(function(){e("div.create-account").hide();if(e(this).is(":checked")){e("div.create-account").slideDown()}}).change()}e("#order_review").on("click",".payment_methods input.input-radio",function(){if(e(".payment_methods input.input-radio").length>1){var t=e("div.payment_box."+e(this).attr("ID"));if(e(this).is(":checked")&&!t.is(":visible")){e("div.payment_box").filter(":visible").slideUp(250);if(e(this).is(":checked")){e("div.payment_box."+e(this).attr("ID")).slideDown(250)}}}else{e("div.payment_box").show()}if(e(this).data("order_button_text")){e("#place_order").val(e(this).data("order_button_text"))}else{e("#place_order").val(e("#place_order").data("value"))}}).find("input[name=payment_method]:checked").click();e("form.checkout").on("input change","select.shipping_method, input[name^=shipping_method], #ship-to-different-address input, .update_totals_on_change select",function(){clearTimeout(t);n=false;e("body").trigger("update_checkout")}).on("input change",".address-field input.input-text, .update_totals_on_change input.input-text",function(){if(n){s()}}).on("input change",".address-field select",function(){n=this;s()}).on("keydown",".address-field input.input-text, .update_totals_on_change input.input-text",function(e){var r=e.keyCode||e.which;if(r==="9"){return}n=this;clearTimeout(t);t=setTimeout(s,"1000")}).on("blur input change",".input-text, select",function(){var t=e(this),n=t.closest(".form-row"),r=true;if(n.is(".validate-required")){if(t.val()===""){n.removeClass("woocommerce-validated").addClass("woocommerce-invalid woocommerce-invalid-required-field");r=false}}if(n.is(".validate-email")){if(t.val()){var i=new RegExp(/^((([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+(\.([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+)*)|((\x22)((((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(([\x01-\x08\x0b\x0c\x0e-\x1f\x7f]|\x21|[\x23-\x5b]|[\x5d-\x7e]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(\\([\x01-\x09\x0b\x0c\x0d-\x7f]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]))))*(((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(\x22)))@((([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)+(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.?$/i);if(!i.test(t.val())){n.removeClass("woocommerce-validated").addClass("woocommerce-invalid woocommerce-invalid-email");r=false}}}if(r){n.removeClass("woocommerce-invalid woocommerce-invalid-required-field").addClass("woocommerce-validated")}}).submit(function(){clearTimeout(t);var n=e(this);if(n.is(".processing")){return false}if(n.triggerHandler("checkout_place_order")!==false&&n.triggerHandler("checkout_place_order_"+e("#order_review input[name=payment_method]:checked").val())!==false){n.addClass("processing");var r=n.data();if(r["blockUI.isBlocked"]!=1){n.block({message:null,overlayCSS:{background:"#fff url("+wc_checkout_params.ajax_loader_url+") no-repeat center",backgroundSize:"16px 16px",opacity:.6}})}e.ajax({type:"POST",url:wc_checkout_params.checkout_url,data:n.serialize(),success:function(t){var r="";try{if(t.indexOf("")>=0)t=t.split("")[1];if(t.indexOf("")>=0)t=t.split("")[0];r=e.parseJSON(t);if(r.result==="success"){window.location=decodeURI(r.redirect)}else if(r.result==="failure"){throw"Result failure"}else{throw"Invalid response"}}catch(i){if(r.reload==="true"){window.location.reload();return}e(".woocommerce-error, .woocommerce-message").remove();if(r.messages){n.prepend(r.messages)}else{n.prepend(t)}n.removeClass("processing").unblock();n.find(".input-text, select").blur();e("html, body").animate({scrollTop:e("form.checkout").offset().top-100},1e3);if(r.refresh==="true")e("body").trigger("update_checkout");e("body").trigger("checkout_error")}},dataType:"html"})}return false});e("form.checkout_coupon").submit(function(){var t=e(this);if(t.is(".processing"))return false;t.addClass("processing").block({message:null,overlayCSS:{background:"#fff url("+wc_checkout_params.ajax_loader_url+") no-repeat center",backgroundSize:"16px 16px",opacity:.6}});var n={action:"woocommerce_apply_coupon",security:wc_checkout_params.apply_coupon_nonce,coupon_code:t.find("input[name=coupon_code]").val()};e.ajax({type:"POST",url:wc_checkout_params.ajax_url,data:n,success:function(n){e(".woocommerce-error, .woocommerce-message").remove();t.removeClass("processing").unblock();if(n){t.before(n);t.slideUp();e("body").trigger("update_checkout")}},dataType:"html"});return false});e("body").bind("init_checkout",function(){e("#billing_country, #shipping_country, .country_to_state").change();e("body").trigger("update_checkout")});if(wc_checkout_params.is_checkout===1){e("body").trigger("init_checkout")}}) \ No newline at end of file diff --git a/assets/js/frontend/chosen-frontend.js b/assets/js/frontend/chosen-frontend.js index e183632b380..b91734e5f19 100644 --- a/assets/js/frontend/chosen-frontend.js +++ b/assets/js/frontend/chosen-frontend.js @@ -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' ); }); }); diff --git a/assets/js/frontend/chosen-frontend.min.js b/assets/js/frontend/chosen-frontend.min.js index 736c7121539..eb79d64721a 100644 --- a/assets/js/frontend/chosen-frontend.min.js +++ b/assets/js/frontend/chosen-frontend.min.js @@ -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")})}); \ No newline at end of file +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")})}) \ No newline at end of file diff --git a/assets/js/frontend/country-select.js b/assets/js/frontend/country-select.js index f46c74d0c7a..dcc09764f46 100644 --- a/assets/js/frontend/country-select.js +++ b/assets/js/frontend/country-select.js @@ -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(/"/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(){ + $( '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( '' ); - if (states[country]) { - if (states[country].length == 0) { - - $statebox.parent().hide().find('.chosen-container').remove(); - $statebox.replaceWith(''); - - $('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 + ''; + var options = '', + state = states[ country ]; + + for( var index in state ) { + if ( state.hasOwnProperty( index ) ) { + options = options + ''; + } } + $statebox.parent().show(); - if ($statebox.is('input')) { + + if ( $statebox.is( 'input' ) ) { // Change for select - $statebox.replaceWith(''); - $statebox = $(this).closest('div').find('#billing_state, #shipping_state, #calc_shipping_state'); + $statebox.replaceWith( '' ); + $statebox = $( this ).closest( 'div' ).find( '#billing_state, #shipping_state, #calc_shipping_state' ); } - $statebox.html( '' + options); - $statebox.val(value); + $statebox.html( '' + 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(''); + $parent.show().find( '.chosen-container' ).remove(); + $statebox.replaceWith( '' ); - $('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(''); + $parent.show().find( '.chosen-container' ).remove(); + $statebox.replaceWith( '' ); - $('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(); diff --git a/assets/js/frontend/country-select.min.js b/assets/js/frontend/country-select.min.js index f89d00e5df0..ca966c3aae5 100644 --- a/assets/js/frontend/country-select.min.js +++ b/assets/js/frontend/country-select.min.js @@ -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(''),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+'";d.parent().show(),d.is("input")&&(d.replaceWith(''),d=a(this).closest("div").find("#billing_state, #shipping_state, #calc_shipping_state")),d.html('"+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(''),a("body").trigger("country_to_state_changed",[b,a(this).closest("div")])):d.is(".hidden")&&(e.show().find(".chosen-container").remove(),d.replaceWith(''),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()}); \ No newline at end of file +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('');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+'"}}r.parent().show();if(r.is("input")){r.replaceWith('');r=e(this).closest("div").find("#billing_state, #shipping_state, #calc_shipping_state")}r.html('"+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('');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('');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()}) \ No newline at end of file