-
Notifications
You must be signed in to change notification settings - Fork 4.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
use Spree.ready instead of document ready on checkout address book
- Loading branch information
1 parent
f16fa8f
commit 1dec26a
Showing
1 changed file
with
38 additions
and
40 deletions.
There are no files selected for viewing
78 changes: 38 additions & 40 deletions
78
frontend/app/assets/javascripts/spree/frontend/checkout/address_book.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
}); |