Fixup js/order-opc.js

Error fixes:
1. Added missing var on line 89
2. Added missing semicolons on lines 98, 104, 110, 181, 766, 781

General fixes:
1. Replace == with === and != with !==
2. Added missing var to for loops
3. Moved a few var scopes to the correct location
This commit is contained in:
Milow
2012-11-23 22:23:28 -06:00
parent 41371b1938
commit c57c53711a
+73 -68
View File
@@ -45,8 +45,8 @@ function updatePaymentMethods(json)
function updateAddressSelection()
{
var idAddress_delivery = ($('#opc_id_address_delivery').length == 1 ? $('#opc_id_address_delivery').val() : $('#id_address_delivery').val());
var idAddress_invoice = ($('#opc_id_address_invoice').length == 1 ? $('#opc_id_address_invoice').val() : ($('#addressesAreEquals:checked').length == 1 ? idAddress_delivery : ($('#id_address_invoice').length == 1 ? $('#id_address_invoice').val() : idAddress_delivery)));
var idAddress_delivery = ($('#opc_id_address_delivery').length === 1 ? $('#opc_id_address_delivery').val() : $('#id_address_delivery').val());
var idAddress_invoice = ($('#opc_id_address_invoice').length === 1 ? $('#opc_id_address_invoice').val() : ($('#addressesAreEquals:checked').length === 1 ? idAddress_delivery : ($('#id_address_invoice').length === 1 ? $('#id_address_invoice').val() : idAddress_delivery)));
$('#opc_account-overlay').fadeIn('slow');
$('#opc_delivery_methods-overlay').fadeIn('slow');
@@ -64,9 +64,9 @@ function updateAddressSelection()
if (jsonData.hasError)
{
var errors = '';
for(error in jsonData.errors)
for(var error in jsonData.errors)
//IE6 bug fix
if(error != 'indexOf')
if(error !== 'indexOf')
errors += jsonData.errors[error] + "\n";
alert(errors);
}
@@ -86,7 +86,7 @@ function updateAddressSelection()
if ($(this).find('.cart_quantity_input').length > 0 && $(this).find('.cart_quantity_input').attr('name').length > 0)
{
name = $(this).find('.cart_quantity_input').attr('name')+'_hidden';
var name = $(this).find('.cart_quantity_input').attr('name')+'_hidden';
$(this).find('.cart_quantity_input').attr('name', $(this).find('.cart_quantity_input').attr('name').replace(/_\d+$/, '_'+idAddress_delivery));
if ($(this).find('[name='+name+']').length > 0)
$(this).find('[name='+name+']').attr('name', name.replace(/_\d+_hidden$/, '_'+idAddress_delivery+'_hidden'));
@@ -95,19 +95,19 @@ function updateAddressSelection()
if ($(this).find('.cart_quantity_delete').length > 0 && $(this).find('.cart_quantity_delete').attr('id').length > 0) {
$(this).find('.cart_quantity_delete')
.attr('id', $(this).find('.cart_quantity_delete').attr('id').replace(/_\d+$/, '_'+idAddress_delivery))
.attr('href', $(this).find('.cart_quantity_delete').attr('href').replace(/id_address_delivery=\d+&/, 'id_address_delivery='+idAddress_delivery+'&'))
.attr('href', $(this).find('.cart_quantity_delete').attr('href').replace(/id_address_delivery=\d+&/, 'id_address_delivery='+idAddress_delivery+'&'));
}
if ($(this).find('.cart_quantity_down').length > 0 && $(this).find('.cart_quantity_down').attr('id').length > 0) {
$(this).find('.cart_quantity_down')
.attr('id', $(this).find('.cart_quantity_down').attr('id').replace(/_\d+$/, '_'+idAddress_delivery))
.attr('href', $(this).find('.cart_quantity_down').attr('href').replace(/id_address_delivery=\d+&/, 'id_address_delivery='+idAddress_delivery+'&'))
.attr('href', $(this).find('.cart_quantity_down').attr('href').replace(/id_address_delivery=\d+&/, 'id_address_delivery='+idAddress_delivery+'&'));
}
if ($(this).find('.cart_quantity_up').length > 0 && $(this).find('.cart_quantity_up').attr('id').length > 0) {
$(this).find('.cart_quantity_up')
.attr('id', $(this).find('.cart_quantity_up').attr('id').replace(/_\d+$/, '_'+idAddress_delivery))
.attr('href', $(this).find('.cart_quantity_up').attr('href').replace(/id_address_delivery=\d+&/, 'id_address_delivery='+idAddress_delivery+'&'))
.attr('href', $(this).find('.cart_quantity_up').attr('href').replace(/id_address_delivery=\d+&/, 'id_address_delivery='+idAddress_delivery+'&'));
}
});
@@ -120,7 +120,7 @@ function updateAddressSelection()
updateCartSummary(jsonData.summary);
updateHookShoppingCart(jsonData.HOOK_SHOPPING_CART);
updateHookShoppingCartExtra(jsonData.HOOK_SHOPPING_CART_EXTRA);
if ($('#gift-price').length == 1)
if ($('#gift-price').length === 1)
$('#gift-price').html(jsonData.gift_price);
$('#opc_account-overlay').fadeOut('slow');
$('#opc_delivery_methods-overlay').fadeOut('slow');
@@ -128,7 +128,7 @@ function updateAddressSelection()
}
},
error: function(XMLHttpRequest, textStatus, errorThrown) {
if (textStatus != 'abort')
if (textStatus !== 'abort')
alert("TECHNICAL ERROR: unable to save adresses \n\nDetails:\nError thrown: " + XMLHttpRequest + "\n" + 'Text status: ' + textStatus);
$('#opc_account-overlay').fadeOut('slow');
$('#opc_delivery_methods-overlay').fadeOut('slow');
@@ -152,9 +152,9 @@ function getCarrierListAndUpdate()
if (jsonData.hasError)
{
var errors = '';
for(error in jsonData.errors)
for(var error in jsonData.errors)
//IE6 bug fix
if(error != 'indexOf')
if(error !== 'indexOf')
errors += jsonData.errors[error] + "\n";
alert(errors);
}
@@ -177,8 +177,8 @@ function updateCarrierSelectionAndGift()
if ($(this).prop('checked'))
delivery_option_params += $(delivery_option_radio[i]).attr('name') + '=' + $(delivery_option_radio[i]).val() + '&';
});
if (delivery_option_params == '&')
delivery_option_params = '&delivery_option=&'
if (delivery_option_params === '&')
delivery_option_params = '&delivery_option=&';
if ($('input#recyclable:checked').length)
recyclablePackage = 1;
@@ -202,9 +202,9 @@ function updateCarrierSelectionAndGift()
if (jsonData.hasError)
{
var errors = '';
for(error in jsonData.errors)
for(var error in jsonData.errors)
//IE6 bug fix
if(error != 'indexOf')
if(error !== 'indexOf')
errors += jsonData.errors[error] + "\n";
alert(errors);
}
@@ -221,7 +221,7 @@ function updateCarrierSelectionAndGift()
}
},
error: function(XMLHttpRequest, textStatus, errorThrown) {
if (textStatus != 'abort')
if (textStatus !== 'abort')
alert("TECHNICAL ERROR: unable to save carrier \n\nDetails:\nError thrown: " + XMLHttpRequest + "\n" + 'Text status: ' + textStatus);
$('#opc_payment_methods-overlay').fadeOut('slow');
$('#opc_delivery_methods-overlay').fadeOut('slow');
@@ -231,7 +231,7 @@ function updateCarrierSelectionAndGift()
function confirmFreeOrder()
{
if ($('#opc_new_account-overlay').length != 0)
if ($('#opc_new_account-overlay').length !== 0)
$('#opc_new_account-overlay').fadeIn('slow');
else
$('#opc_account-overlay').fadeIn('slow');
@@ -256,7 +256,7 @@ function confirmFreeOrder()
}
},
error: function(XMLHttpRequest, textStatus, errorThrown) {
if (textStatus != 'abort')
if (textStatus !== 'abort')
alert("TECHNICAL ERROR: unable to confirm the order \n\nDetails:\nError thrown: " + XMLHttpRequest + "\n" + 'Text status: ' + textStatus);
}
});
@@ -264,26 +264,26 @@ function confirmFreeOrder()
function saveAddress(type)
{
if (type != 'delivery' && type != 'invoice')
if (type !== 'delivery' && type !== 'invoice')
return false;
var params = 'firstname='+encodeURIComponent($('#firstname'+(type == 'invoice' ? '_invoice' : '')).val())+'&lastname='+encodeURIComponent($('#lastname'+(type == 'invoice' ? '_invoice' : '')).val())+'&';
params += 'company='+encodeURIComponent($('#company'+(type == 'invoice' ? '_invoice' : '')).val())+'&';
params += 'vat_number='+encodeURIComponent($('#vat_number'+(type == 'invoice' ? '_invoice' : '')).val())+'&';
params += 'dni='+encodeURIComponent($('#dni'+(type == 'invoice' ? '_invoice' : '')).val())+'&';
params += 'address1='+encodeURIComponent($('#address1'+(type == 'invoice' ? '_invoice' : '')).val())+'&';
params += 'address2='+encodeURIComponent($('#address2'+(type == 'invoice' ? '_invoice' : '')).val())+'&';
params += 'postcode='+encodeURIComponent($('#postcode'+(type == 'invoice' ? '_invoice' : '')).val())+'&';
params += 'city='+encodeURIComponent($('#city'+(type == 'invoice' ? '_invoice' : '')).val())+'&';
var params = 'firstname='+encodeURIComponent($('#firstname'+(type === 'invoice' ? '_invoice' : '')).val())+'&lastname='+encodeURIComponent($('#lastname'+(type === 'invoice' ? '_invoice' : '')).val())+'&';
params += 'company='+encodeURIComponent($('#company'+(type === 'invoice' ? '_invoice' : '')).val())+'&';
params += 'vat_number='+encodeURIComponent($('#vat_number'+(type === 'invoice' ? '_invoice' : '')).val())+'&';
params += 'dni='+encodeURIComponent($('#dni'+(type === 'invoice' ? '_invoice' : '')).val())+'&';
params += 'address1='+encodeURIComponent($('#address1'+(type === 'invoice' ? '_invoice' : '')).val())+'&';
params += 'address2='+encodeURIComponent($('#address2'+(type === 'invoice' ? '_invoice' : '')).val())+'&';
params += 'postcode='+encodeURIComponent($('#postcode'+(type === 'invoice' ? '_invoice' : '')).val())+'&';
params += 'city='+encodeURIComponent($('#city'+(type === 'invoice' ? '_invoice' : '')).val())+'&';
params += 'id_country='+encodeURIComponent($('#id_country').val())+'&';
if ($('#id_state'+(type == 'invoice' ? '_invoice' : '')).val())
if ($('#id_state'+(type === 'invoice' ? '_invoice' : '')).val())
{
params += 'id_state='+encodeURIComponent($('#id_state'+(type == 'invoice' ? '_invoice' : '')).val())+'&';
params += 'id_state='+encodeURIComponent($('#id_state'+(type === 'invoice' ? '_invoice' : '')).val())+'&';
}
params += 'other='+encodeURIComponent($('#other'+(type == 'invoice' ? '_invoice' : '')).val())+'&';
params += 'phone='+encodeURIComponent($('#phone'+(type == 'invoice' ? '_invoice' : '')).val())+'&';
params += 'phone_mobile='+encodeURIComponent($('#phone_mobile'+(type == 'invoice' ? '_invoice' : '')).val())+'&';
params += 'alias='+encodeURIComponent($('#alias'+(type == 'invoice' ? '_invoice' : '')).val())+'&';
params += 'other='+encodeURIComponent($('#other'+(type === 'invoice' ? '_invoice' : '')).val())+'&';
params += 'phone='+encodeURIComponent($('#phone'+(type === 'invoice' ? '_invoice' : '')).val())+'&';
params += 'phone_mobile='+encodeURIComponent($('#phone_mobile'+(type === 'invoice' ? '_invoice' : '')).val())+'&';
params += 'alias='+encodeURIComponent($('#alias'+(type === 'invoice' ? '_invoice' : '')).val())+'&';
// Clean the last &
params = params.substr(0, params.length-1);
@@ -302,9 +302,9 @@ function saveAddress(type)
{
var tmp = '';
var i = 0;
for(error in jsonData.errors)
for(var error in jsonData.errors)
//IE6 bug fix
if(error != 'indexOf')
if(error !== 'indexOf')
{
i = i+1;
tmp += '<li>'+jsonData.errors[error]+'</li>';
@@ -327,7 +327,7 @@ function saveAddress(type)
}
},
error: function(XMLHttpRequest, textStatus, errorThrown) {
if (textStatus != 'abort')
if (textStatus !== 'abort')
alert("TECHNICAL ERROR: unable to save adresses \n\nDetails:\nError thrown: " + XMLHttpRequest + "\n" + 'Text status: ' + textStatus);
$('#opc_new_account-overlay').fadeOut('slow');
$('#opc_delivery_methods-overlay').fadeOut('slow');
@@ -353,13 +353,13 @@ function updateNewAccountToAddressBlock()
success: function(json)
{
isLogged = 1;
if (json.no_address == 1)
if (json.no_address === 1)
document.location.href = addressUrl;
$('#opc_new_account').fadeOut('fast', function() {
$('#opc_new_account').html(json.order_opc_adress);
// update block user info
if (json.block_user_info != '' && $('#header_user').length == 1)
if (json.block_user_info !== '' && $('#header_user').length === 1)
{
$('#header_user').fadeOut('slow', function() {
$(this).attr('id', 'header_user_old').after(json.block_user_info).fadeIn('slow');
@@ -377,7 +377,7 @@ function updateNewAccountToAddressBlock()
updateAddressesDisplay(true);
updateCarrierList(json.carrier_data);
updatePaymentMethods(json);
if ($('#gift-price').length == 1)
if ($('#gift-price').length === 1)
$('#gift-price').html(json.gift_price);
$('#opc_delivery_methods-overlay').fadeOut('slow');
$('#opc_payment_methods-overlay').fadeOut('slow');
@@ -385,7 +385,7 @@ function updateNewAccountToAddressBlock()
});
},
error: function(XMLHttpRequest, textStatus, errorThrown) {
if (textStatus != 'abort')
if (textStatus !== 'abort')
alert("TECHNICAL ERROR: unable to send login informations \n\nDetails:\nError thrown: " + XMLHttpRequest + "\n" + 'Text status: ' + textStatus);
$('#opc_delivery_methods-overlay').fadeOut('slow');
$('#opc_payment_methods-overlay').fadeOut('slow');
@@ -471,9 +471,9 @@ $(function() {
if (jsonData.hasError)
{
var errors = '<b>'+txtThereis+' '+jsonData.errors.length+' '+txtErrors+':</b><ol>';
for(error in jsonData.errors)
for(var error in jsonData.errors)
//IE6 bug fix
if(error != 'indexOf')
if(error !== 'indexOf')
errors += '<li>'+jsonData.errors[error]+'</li>';
errors += '</ol>';
$('#opc_login_errors').html(errors).slideDown('slow');
@@ -486,7 +486,7 @@ $(function() {
}
},
error: function(XMLHttpRequest, textStatus, errorThrown) {
if (textStatus != 'abort')
if (textStatus !== 'abort')
alert("TECHNICAL ERROR: unable to send login informations \n\nDetails:\nError thrown: " + XMLHttpRequest + "\n" + 'Text status: ' + textStatus);
}
});
@@ -498,7 +498,7 @@ $(function() {
if ($('#invoice_address:checked').length > 0)
{
$('#opc_invoice_address').slideDown('slow');
if ($('#company_invoice').val() == '')
if ($('#company_invoice').val() === '')
$('#vat_number_block_invoice').hide();
updateState('invoice');
updateNeedIDNumber('invoice');
@@ -517,15 +517,18 @@ $(function() {
// RESET ERROR(S) MESSAGE(S)
$('#opc_account_errors').html('').slideUp('slow');
if ($('#opc_id_customer').val() == 0)
var callingFile = '';
var params = '';
if ($('#opc_id_customer').val() === 0)
{
var callingFile = authenticationUrl;
var params = 'submitAccount=true&';
callingFile = authenticationUrl;
params = 'submitAccount=true&';
}
else
{
var callingFile = orderOpcUrl;
var params = 'method=editCustomer&';
callingFile = orderOpcUrl;
params = 'method=editCustomer&';
}
$('#opc_account_form input:visible, #opc_account_form input[type=hidden]').each(function() {
@@ -566,9 +569,9 @@ $(function() {
{
var tmp = '';
var i = 0;
for(error in jsonData.errors)
for(var error in jsonData.errors)
//IE6 bug fix
if(error != 'indexOf')
if(error !== 'indexOf')
{
i = i+1;
tmp += '<li>'+jsonData.errors[error]+'</li>';
@@ -579,9 +582,9 @@ $(function() {
$.scrollTo('#opc_account_errors', 800);
}
isGuest = ($('#is_new_customer').val() == 1 ? 0 : 1);
isGuest = ($('#is_new_customer').val() === 1 ? 0 : 1);
if (jsonData.id_customer != undefined && jsonData.id_customer != 0 && jsonData.isSaved)
if (jsonData.id_customer !== undefined && jsonData.id_customer !== 0 && jsonData.isSaved)
{
// update token
static_token = jsonData.token;
@@ -591,7 +594,7 @@ $(function() {
$('#opc_id_address_invoice').val(jsonData.id_address_invoice);
// It's not a new customer
if ($('#opc_id_customer').val() != '0')
if ($('#opc_id_customer').val() !== '0')
{
if (!saveAddress('delivery'))
return false;
@@ -600,7 +603,7 @@ $(function() {
// update id_customer
$('#opc_id_customer').val(jsonData.id_customer);
if ($('#invoice_address:checked').length != 0)
if ($('#invoice_address:checked').length !== 0)
{
if (!saveAddress('invoice'))
return false;
@@ -625,7 +628,7 @@ $(function() {
$('#opc_payment_methods-overlay').fadeOut('slow');
},
error: function(XMLHttpRequest, textStatus, errorThrown) {
if (textStatus != 'abort')
if (textStatus !== 'abort')
alert("TECHNICAL ERROR: unable to save account \n\nDetails:\nError thrown: " + XMLHttpRequest + "\n" + 'Text status: ' + textStatus);
$('#opc_new_account-overlay').fadeOut('slow');
$('#opc_delivery_methods-overlay').fadeOut('slow');
@@ -665,9 +668,9 @@ function bindInputs()
if (jsonData.hasError)
{
var errors = '';
for(error in jsonData.errors)
for(var error in jsonData.errors)
//IE6 bug fix
if(error != 'indexOf')
if(error !== 'indexOf')
errors += jsonData.errors[error] + "\n";
alert(errors);
}
@@ -675,7 +678,7 @@ function bindInputs()
$('#opc_delivery_methods-overlay').fadeOut('slow');
},
error: function(XMLHttpRequest, textStatus, errorThrown) {
if (textStatus != 'abort')
if (textStatus !== 'abort')
alert("TECHNICAL ERROR: unable to save message \n\nDetails:\nError thrown: " + XMLHttpRequest + "\n" + 'Text status: ' + textStatus);
$('#opc_delivery_methods-overlay').fadeOut('slow');
}
@@ -708,10 +711,12 @@ function bindInputs()
// Term Of Service (TOS)
$('#cgv').click(function() {
if ($('#cgv:checked').length != 0)
var checked = 1;
var checked = '';
if ($('#cgv:checked').length !== 0)
checked = 1;
else
var checked = 0;
checked = 0;
$('#opc_payment_methods-overlay').fadeIn('slow');
$.ajax({
@@ -758,7 +763,7 @@ function multishippingMode(it)
cache: false,
success: function(data) {
$('#cart_summary').replaceWith($(data).find('#cart_summary'));
$('.cart_quantity_input').typeWatch({ highlight: true, wait: 600, captureLength: 0, callback: function(val) { updateQty(val, true, this.el) } });
$('.cart_quantity_input').typeWatch({ highlight: true, wait: 600, captureLength: 0, callback: function(val) { updateQty(val, true, this.el); } });
}
});
updateCarrierSelectionAndGift();
@@ -773,7 +778,7 @@ function multishippingMode(it)
},
'onComplete': function()
{
$('#fancybox-content .cart_quantity_input').typeWatch({ highlight: true, wait: 600, captureLength: 0, callback: function(val) { updateQty(val, false, this.el)} });
$('#fancybox-content .cart_quantity_input').typeWatch({ highlight: true, wait: 600, captureLength: 0, callback: function(val) { updateQty(val, false, this.el);} });
cleanSelectAddressDelivery();
$('#fancybox-content').append($('<div class="multishipping_close_container"><a id="multishipping-close" class="button_large" href="#">' + CloseTxt + '</a></div>'));
$('#multishipping-close').click(function() {
@@ -781,7 +786,7 @@ function multishippingMode(it)
$('#fancybox-content .cart_quantity_input').each(function(){
newTotalQty += parseInt($(this).val());
});
if (newTotalQty != totalQty) {
if (newTotalQty !== totalQty) {
if(!confirm(QtyChanged)) {
return false;
}
@@ -835,12 +840,12 @@ $(document).ready(function() {
// If the multishipping mode is off assure us the checkbox "I want to specify a delivery address for each products I order." is unchecked.
$('#multishipping_mode_checkbox').attr('checked', false);
// If the multishipping mode is on, check the box "I want to specify a delivery address for each products I order.".
if (typeof(multishipping_mode) != 'undefined' && multishipping_mode) {
if (typeof(multishipping_mode) !== 'undefined' && multishipping_mode) {
$('#multishipping_mode_checkbox').click();
$('.addressesAreEquals').hide();
$('.addressesAreEquals').find('input').attr('checked', false);
}
if (typeof(open_multishipping_fancybox) != 'undefined' && open_multishipping_fancybox)
if (typeof(open_multishipping_fancybox) !== 'undefined' && open_multishipping_fancybox)
$('#link_multishipping_form').click();
});