Skip to content

Commit

Permalink
use Spree.ready instead of document ready on checkout address book
Browse files Browse the repository at this point in the history
  • Loading branch information
chinoxchen authored and damianlegawiec committed Jul 25, 2020
1 parent f16fa8f commit 1dec26a
Showing 1 changed file with 38 additions and 40 deletions.
Original file line number Diff line number Diff line change
@@ -1,56 +1,54 @@
(function ($) {
$(document).ready(function () {
if ($('.select_address').length > 0) {
$('input#order_use_billing').unbind('change')
Spree.ready(function ($) {
if ($('.select_address').length > 0) {
$('input#order_use_billing').unbind('change');

hide_address_form('billing')
hide_address_form('shipping')
hide_address_form('billing');
hide_address_form('shipping');

if ($('input#order_use_billing').is(':checked')) {
$('#shipping .select_address').hide()
}

$('input#order_use_billing').click(function () {
if ($(this).is(':checked')) {
$('#shipping .select_address').hide()
hide_address_form('shipping')
} else {
$('#shipping .select_address').show()
if ($("input[name='order[ship_address_id]']:checked").val() == '0') {
show_address_form('shipping')
} else {
hide_address_form('shipping')
}
}
})

$("input[name='order[bill_address_id]']:radio").change(function () {
if ($("input[name='order[bill_address_id]']:checked").val() == '0') {
show_address_form('billing')
} else {
hide_address_form('billing')
}
})
if ($('input#order_use_billing').is(':checked')) {
$('#shipping .select_address').hide()
}

$("input[name='order[ship_address_id]']:radio").change(function () {
$('input#order_use_billing').click(function () {
if ($(this).is(':checked')) {
$('#shipping .select_address').hide()
hide_address_form('shipping')
} else {
$('#shipping .select_address').show()
if ($("input[name='order[ship_address_id]']:checked").val() == '0') {
show_address_form('shipping')
} else {
hide_address_form('shipping')
}
})
}
})
}
});

$("input[name='order[bill_address_id]']:radio").change(function () {
if ($("input[name='order[bill_address_id]']:checked").val() == '0') {
show_address_form('billing')
} else {
hide_address_form('billing')
}
});

$("input[name='order[ship_address_id]']:radio").change(function () {
if ($("input[name='order[ship_address_id]']:checked").val() == '0') {
show_address_form('shipping')
} else {
hide_address_form('shipping')
}
})
}

function hide_address_form (address_type) {
$('#' + address_type + ' .inner').hide()
function hide_address_form(address_type) {
$('#' + address_type + ' .inner').hide();
$('#' + address_type + ' .inner input').prop('disabled', true)
$('#' + address_type + ' .inner select').prop('disabled', true)
}

function show_address_form (address_type) {
$('#' + address_type + ' .inner').show()
function show_address_form(address_type) {
$('#' + address_type + ' .inner').show();
$('#' + address_type + ' .inner input').prop('disabled', false)
$('#' + address_type + ' .inner select').prop('disabled', false)
}
})(jQuery)
});

0 comments on commit 1dec26a

Please sign in to comment.