From c57c53711a6f2b7cc4f2c903463b53307ab9cfca Mon Sep 17 00:00:00 2001 From: Milow <{email}> Date: Fri, 23 Nov 2012 22:23:28 -0600 Subject: [PATCH] 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 --- themes/default/js/order-opc.js | 141 +++++++++++++++++---------------- 1 file changed, 73 insertions(+), 68 deletions(-) diff --git a/themes/default/js/order-opc.js b/themes/default/js/order-opc.js index 0ff500cd0..561107de1 100644 --- a/themes/default/js/order-opc.js +++ b/themes/default/js/order-opc.js @@ -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 += '