1(function(_, $) { 2 3 var prevent_scroll = false; 4 5 (function($) { 6 7 var inputs_selector = 'input, textarea, select'; 8 var place_order_buttons_selector = '.cm-checkout-place-order-buttons'; 9 var recalculate_buttons_selector = '.cm-checkout-recalculate-buttons'; 10 var form_values = {}; 11 12 function changed() { 13 var form = $(this); 14 15 if (checkFormChanged(form) && form.ceFormValidator('check')) { 16 displayRecalculate(form); 17 } 18 } 19 20 function displayRecalculate(form) { 21 var changed_groups = { 22 user_data: false 23 }; 24 25 form.find(inputs_selector).each(function(){ 26 var elm = $(this); 27 if (elm.attr('type') != 'hidden' && form_values[elm.attr('name') + '_' + elm.attr('id')] != getVal(elm)) { 28 var elm_name = elm.attr('name'); 29 if (elm_name) { 30 var elm_group = elm_name.split('[')[0]; 31 changed_groups[elm_group] = true; 32 } 33 } 34 }); 35 36 // require recalculate only when user data changed 37 if (changed_groups['user_data']) { 38 form.find(place_order_buttons_selector).hide(); 39 form.find(recalculate_buttons_selector).show(); 40 } 41 } 42 43 function saveFormValues(form) { 44 form.find(inputs_selector).each(function(){ 45 var elm = $(this); 46 form_values[elm.attr('name') + '_' + elm.attr('id')] = getVal(elm); 47 }); 48 } 49 50 function checkFormChanged(form) { 51 var result = false;
52 53 form.find(inputs_selector).each(function(){ 54 var elm = $(this); 55 if (elm.attr('type') != 'hidden' && form_values[elm.attr('name') + '_' + elm.attr('id')] != getVal(elm)) { 56 result = true; 57 } 58 }); 59 60 return result; 61 } 62 63 function getVal(elm) 64 { 65 return ['checkbox', 'radio'].indexOf(elm.attr('type')) != -1 ? elm.is(':checked') : elm.val(); 66 } 67 68 var methods = { 69 init: function(v1) { 70 var form = $(this); 71 72 if (form.data('CheckoutRecalculateFormInited')) { 73 return false; 74 } 75 76 form.data('CheckoutRecalculateFormInited', true); 77 78 if (!form.find(recalculate_buttons_selector).length) { 79 return true; 80 } 81 82 saveFormValues(form); 83 84 form.find(inputs_selector).on('input propertychange change', function(e) { 85 changed.apply(form); 86 }); 87 } 88 }; 89 90 $.fn.ceCheckoutRecalculateForm = function(method) { 91 if (methods[method]) { 92 return methods[method].apply(this, Array.prototype.slice.call(arguments, 1)); 93 } else if ( typeof method === 'object' || !method ) { 94 return methods.init.apply(this, arguments); 95 } else { 96 $.error('ty.ceCheckoutRecalculateForm: method ' + method + ' does not exist'); 97 } 98 }; 99 100 })($); 101 102 $.ceEvent('on', 'ce.commoninit', function(context) { 103 104 var elm = context.find('.ty-step__title-active'); 105 if (elm.length && !prevent_scroll) { 106 $.scrollToElm(elm); 107 } 108 prevent_scroll = false; 109 110 elm = context.find('.cm-checkout-recalculate-form'); 111 if (elm.length) { 112 elm.ceCheckoutRecalculateForm(); 113 } 114 115 restoreCustomerNote($('.ty-customer-notes__text')); 116 117 }); 118 119 $(_.doc).on('click', '.cm-checkout-place-order', function() { 120 var jelm = $(this), 121 form = jelm.parents('form'); 122 123 if (!form.ceFormValidator('check')) { 124 return; 125 } 126 127 form.removeClass('cm-ajax').removeClass('cm-ajax-full-render'); 128 $.ceEvent('on', 'ce.formpost_' + $(form).attr('name'), function() { 129 $.toggleStatusBox('show', { 130 statusContent: '<span class="ty-ajax-loading-box-with__text-wrapper">' + _.tr('placing_order') + '</span>', 131 statusClass: 'ty-ajax-loading-box_text_block' 132 }); 133 }); 134 }); 135 136 $(_.doc).on('click', '.cm-checkout-recalculate', function() { 137 prevent_scroll = true; 138 }); 139 140 $(_.doc).on('click', '.cm-select-payment', function() { 141 var jelm = $(this), 142 url = jelm.data('caUrl'), 143 result_ids = jelm.data('caResultIds'); 144 145 $.ceAjax('request', fn_url(url + '&payment_id=' + jelm.val()), { 146 result_ids: result_ids, 147 full_render: true 148 }); 149 }); 150 151 $.ceEvent('on', 'ce.loadershow', function() { 152 var forms = $('#checkout_steps', _.doc).find('form'); 153 154 forms.on('submit.checkout_lock', function() { return false; }); 155 forms.find('button[type="submit"]').on('click.checkout_lock', function() { return false; }); 156 }); 157 158 $.ceEvent('on', 'ce.loaderhide', function() { 159 var forms = $('#checkout_steps', _.doc).find('form'); 160 161 forms.off('submit.checkout_lock'); 162 forms.find('button[type="submit"]').off('click.checkout_lock'); 163 }); 164 165 $.ceEvent('on', 'ce.ajaxlink.done.payments_tab_switch', function () { 166 restoreCustomerNote($('.ty-customer-notes__text')); 167 }) 168 169 var customerNote = ''; 170 171 function saveCustomerNote ($textarea) { 172 customerNote = $textarea.val(); 173 } 174 175 function restoreCustomerNote ($textarea) { 176 $textarea.val(customerNote); 177 } 178 179 $(_.doc).on('input', '.ty-customer-notes__text', function() { 180 saveCustomerNote($(this)); 181 }); 182})(Tygh, Tygh.$); 183 184function fn_switch_checkout_type() 185{ 186 var $ = Tygh.$; 187 188 $.ceNotification('closeAll'); 189 $('#step_one_register').show(); 190 $('#step_one_login').hide(); 191} 192 193function fn_show_checkout_buttons(type) 194{ 195 var $ = Tygh.$; 196 if (type == 'register') { 197 $('#register_checkout').show(); 198 $('#anonymous_checkout').hide(); 199 } else { 200 $('#register_checkout').hide(); 201 $('#anonymous_checkout').show(); 202 } 203} 204 205/** 206 * This workaround is mainly required for a shipping estimator block to work outside of cart page. 207 * This function cannot be just moved from checkout.js, because some themes ("boilerplate" for example) 208 * might not include cs-cart's native core.js, which will lead to breaking delivery estimation 209 * functionality on the cart page. 210 **/ 211if (window.fn_calculate_total_shipping === undefined) { 212 213 function fn_calculate_total_shipping(wrapper_id) { 214 var $ = Tygh.$; 215 216 wrapper_id = wrapper_id || 'shipping_estimation'; 217 var parent = $('#' + wrapper_id); 218 219 var radio = $('input[type=radio]:checked', parent); 220 var params = []; 221 222 $.each(radio, function(id, elm) { 223 params.push({name: elm.name, value: elm.value}); 224 }); 225 226 var url = fn_url('checkout.shipping_estimation.get_total'); 227 228 for (var i in params) { 229 url += '&' + params[i]['name'] + '=' + encodeURIComponent(params[i]['value']); 230 } 231 232 var suffix = parent.find('input[name="suffix"]').first().val(); 233 234 $.ceAjax('request', url, { 235 result_ids: 'shipping_estimation_total' + suffix, 236 data: { 237 additional_id: parent.find('input[name="additional_id"]').first().val() 238 }, 239 method: 'post' 240 }); 241 } 242} 243 244function fn_calculate_total_shipping_cost(is_hidden) 245{ 246 is_hidden = is_hidden || false; 247 248 var params = [], 249 $parents = Tygh.$('#shipping_rates_list'), 250 $radio = Tygh.$('input[type=radio]:checked', $parents), 251 $shippingInfo = Tygh.$('[data-ca-shipping-field]'), 252 url = fn_url('checkout.checkout'), 253 result_ids = 'shipping_rates_list,checkout_info_summary_*,checkout_info_order_info_*', 254 $additional_result_ids = Tygh.$('input[name="additional_result_ids[]"]', $parents); 255 256 Tygh.$.each($radio, function (id, elm) { 257 params.push({name: elm.name, value: elm.value}); 258 }); 259 260 Tygh.$.each($shippingInfo, function (id, elm) { 261 params.push({name: elm.name, value: elm.value}); 262 }); 263 264 Tygh.$.each($additional_result_ids, function (id, elm) { 265 result_ids += ',' + $(elm).val(); 266 }); 267 268 for (var i in params) { 269 url += '&' + params[i]['name'] + '=' + encodeURIComponent(params[i]['value']); 270 } 271 272 Tygh.$.ceAjax('request', url, { 273 result_ids: result_ids, 274 method: 'get', 275 full_render: true, 276 hidden: is_hidden, 277 callback: function (response) { 278 $.ceEvent('trigger', 'ce.total-shipping-cost.calculated', [response]); 279 } 280 }); 281}
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.