1jQuery(function ($) { 2 3 function calc_sum_amount(wrapper) { 4 let amount = 0; 5 wrapper.find('input[type="number"]').each(function () { 6 amount += parseInt($(this).val()); 7 }); 8 wrapper.find('input[type="checkbox"]').each(function () { 9 if ($(this).is(':checked')) { 10 amount += 1; 11 } 12 }); 13 return amount; 14 } 15 16 $.fn.calc_sum_amount = function () { 17 return calc_sum_amount($(this)); 18 } 19 20 function render_modal(title, subtitle, content) { 21 title = '<h3 class="md-modal-title">' + title + '</h3>'; 22 $('body').append('<div class="md-modal medium md-effect-12 md-show">' + 23 '<div class="md-content">' + 24 '<a class="md-close"><svg width="800px" height="800px" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg"><g id="clsose"><path id="Vector" d="M18 18L12 12M12 12L6 6M12 12L18 6M12 12L6 18" stroke="#000000" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/></g></svg></a>' + 25 title + '<p class="md-modal-subtitle">' + subtitle + '</p>' + 26 '<br><div class="md-body">' + content + '</div>' + 27 '</div></div><div class="md-overlay"></div>'); 28 29 $('.md-close').on('click', function () { 30 $('.md-modal').removeClass('md-show'); 31 }); 32 } 33 34 $.fn.render_modal = function (title, subtitle, content) { 35 return render_modal(title, subtitle, content); 36 } 37}); 38 39jQuery(function ($) { 40 let price_html; 41 42 let customer_note = $('.accordion-item-title'); 43 let single_modifier = $('.iiko-qty'); 44 let group_modifier; 45 46 if (0 === single_modifier.length) { 47 single_modifier = $('.iiko-checkbox') 48 } 49 50 if (0 !== $('.iiko_select').length) { 51 group_modifier = $('.iiko_select'); 52 } else { 53 group_modifier = $('.iiko_radio'); 54 } 55 56 // customer note 57 customer_note.click(function () { 58 let $item = $(this).parents('.accordion-item'); 59 $item.toggleClass('accordion-item--active').siblings('.accordion-item--active').removeClass('accordion-item--active'); 60 }); 61 62 // single mods price 63 if (0 !== single_modifier.length) { 64 single_modifier.each(function () { 65 if(undefined !== $(this).attr('disabled')){ 66 ajax_get_price($(this).attr('data-product')); 67 let clone = $(this).clone(); 68 clone.attr('type', 'hidden').val('1').removeAttr('checked').removeAttr('disabled'); 69 $(this).before(clone); 70 } 71 72 // initial 73 $(this).change(function () { 74 ajax_get_price($(this).attr('data-product')); 75 }); 76 }); 77 } 78 79 // group mods price 80 if (0 !== group_modifier.length) { 81 group_modifier.change(function () { 82 if ($(this).hasClass('iiko_select')) { 83 group_modifier = $(this).find(":selected"); 84 ajax_get_price(group_modifier.attr('data-product')); 85 } else { 86 ajax_get_price($(this).attr('data-product')); 87 } 88 }); 89 } 90 91 // qty field 92 $('form.cart [name="quantity"]').change(function () { 93 let cls = $(this).attr('class').split(/iiko-post-/); 94 if (undefined !== cls[1]) { 95 let post_id = cls[1]; 96 ajax_get_price(post_id); 97 } 98 }); 99 100 // ajax price calc and format request 101 function ajax_get_price(product_id) { 102 //console.log(calc_all_input_prices(product_id)); 103 if (undefined === product_id) { 104 return; 105 } 106 107 price_html = $.ajax({ 108 url: iikoModifiers.ajax_url, 109 type: 'POST', 110 data: { 111 'action': 'iiko_change_price', // php action 112 'data': calc_all_input_prices(product_id) 113 }, 114 beforeSend: function (xhr) { 115 console.log('price calculating..') 116 if (undefined !== iikoModifiers.calculating) { 117 find_price_selector(product_id).addClass('bg-load'); 118 } 119 }, 120 success: function (price_html) { 121 // console.log(product_id, price_html); 122 if (false === price_html.success) { 123 find_price_selector(product_id).html(price_html.data).removeClass('bg-load'); 124 } else { 125 find_price_selector(product_id).html(price_html).removeClass('bg-load'); 126 } 127 } 128 }); 129 } 130 131 // ÐÑÐ±Ð¾Ñ ÑелекÑоÑа блока ÑÐµÐ½Ñ 132 function find_price_selector(product_id) { 133 let selector; 134 product_id = product_id.replace(/\s+/g, ''); 135 if (0 !== $('form[data-product_id="' + product_id + '"]').length) { // variation 136 selector = $('[data-product_id="' + product_id + '"]'); 137 } else if (0 !== $('#product-' + product_id).length) { // single 138 selector = $('#product-' + product_id); 139 } else if (0 !== $('.postid-' + product_id).length) { 140 selector = $('.postid-' + product_id); // elementor 141 } else { 142 // console.log('else'); 143 selector = $('.post-' + product_id); // catalog item 144 // build get params 145 let product_link = selector.find('a[data-product_id="' + product_id + '"]'); 146 let href = product_link.attr('href'); 147 if (undefined !== href) { 148 product_link.attr('href', href.split("?")[0] + '?' + build_params(product_id)); 149 } 150 } 151 152 return selector.find('.price').first(); 153 } 154 155 function build_params(product_id) { 156 let params = {}; 157 let selector = $('.post-' + product_id); 158 if (0 < $('#product-' + product_id).length) { 159 selector = $('#product-' + product_id); 160 } 161 if (0 !== group_modifier.length) { 162 selector.find(group_modifier).each(function () { 163 if (product_id === $(this).attr('data-product')) { 164 if ($(this).is(":checked")) { 165 params = $(this).attr('name') + '=' + $(this).val(); 166 } 167 } 168 }); 169 } 170 return params; 171 } 172 173 // calc price value for showing 174 function calc_all_input_prices(product_id) { 175 let variations_data = []; 176 let modifiers_price = 0; 177 let selector = $('.post-' + product_id); 178 179 if (0 < $('#product-' + product_id).length) { 180 selector = $('#product-' + product_id); 181 } 182 // add selected variation data if variable product 183 if (0 < $('form[data-product_id="' + product_id + '"]').length) { 184 let variation_inputs = $('form[data-product_id="' + product_id + '"]').find('[data-attribute_name]'); 185 variation_inputs.each(function (i, val) { 186 let value = $(this).val(); 187 if ('' === value) { 188 let radio = $(this).find('input');// radio 189 radio.each(function () { 190 if ($(this).is(":checked")) { 191 value = $(this).val(); 192 } 193 }) 194 } 195 //console.log(value); 196 let obj = { 197 name: $(this).data('attribute_name'), 198 value: value 199 }; 200 variations_data.push(obj); 201 }); 202 } 203 204 if (0 !== single_modifier.length) { 205 single_modifier.each(function () {
206 if ('checkbox' === $(this).attr('type') && $(this).is(":checked")) { 207 modifiers_price += 1 * $(this).attr('data-price'); 208 } 209 if ('number' === $(this).attr('type') && $(this).val() > 0) { 210 modifiers_price += $(this).val() * $(this).attr('data-price'); 211 } 212 }); 213 } 214 215 if (0 !== group_modifier.length) { 216 selector.find(group_modifier).each(function () { 217 if (product_id === $(this).attr('data-product')) { 218 if ($(this).is(":checked")) { 219 modifiers_price += 1 * $(this).attr('data-price'); 220 //params[$(this).attr('id')] = $(this).val(); 221 } 222 } 223 }); 224 } 225 226 selector.find('form.cart input[name="quantity"]').each(function () { 227 let qty = $(this).val(); 228 modifiers_price = modifiers_price * qty 229 }); 230 231 return { 232 'price': modifiers_price, 233 'product_id': product_id, 234 'variations_data': variations_data 235 } 236 } 237 238 239 if (0 >= $('form.cart').length) { 240 return; 241 } 242 243 // min-max amount 244 $('form.cart').each(function () { 245 246 let form = $(this); 247 let group_wrapper = $(this).find('.iiko_group_mod.with-children'); 248 249 // only for group modifier 250 if (group_wrapper.length <= 0) { 251 return; 252 } 253 254 // ÐÑовеÑка знаÑений по-ÑмолÑÐ°Ð½Ð¸Ñ 255 group_wrapper.each(function () { 256 257 let this_wrapper = $(this); 258 let data = JSON.parse($(this).attr('data')); 259 260 let amount = 0; 261 $(this).find('input[type="number"]').each(function () { 262 $(this).data('val', $(this).val()); 263 264 $(this).change(function () { 265 amount = $(this_wrapper).calc_sum_amount(); 266 if (amount > data.maxAmount) { 267 268 let message = iikoModifiers.max + '<br> ' + iikoModifiers.kolvo + ' ' + data.maxAmount + '. ' + iikoModifiers.choose + ' ' + amount + '.'; 269 $().render_modal('Ðнимание!', '', message); 270 271 let val = $(this).data('val'); 272 $(this).val(val).trigger('change'); 273 } else { 274 $(this).data('val', $(this).val()); 275 } 276 }); 277 }); 278 279 if (data.maxAmount === 1) { 280 this_wrapper.find('input[type="checkbox"]').each(function () { 281 $(this).on('click', function () { 282 if (false === $(this).prop('checked') && 0 === data.minAmount) { 283 $(this).prop('checked', false); 284 return; 285 } 286 this_wrapper.find('input[type="checkbox"]').each(function () { 287 $(this).prop('checked', false); 288 }); 289 $(this).prop('checked', true); 290 }); 291 }); 292 } 293 }); 294 295 // ÐÑовеÑка огÑаниÑений 296 $(this).find('button[type="submit"]').each(function () { 297 $(this).on('click', function (e) { 298 let messages = []; 299 let fields = form.find('.iiko_group_mod.with-children.child-required'); 300 301 fields.each(function () { 302 303 let data = JSON.parse($(this).attr('data')); 304 let amount = $(this).calc_sum_amount(); 305 let title = $(this).find('.iiko-title.with-child').text(); 306 307 if (amount < data.minAmount) { 308 messages.push('<b>' + title + '</b><br>' + iikoModifiers.min + ': ' + data.minAmount + '. ' + iikoModifiers.choose + ' ' + amount + '.'); 309 } 310 if (amount > data.maxAmount) { 311 messages.push('<b>' + title + '</b><br>' + iikoModifiers.max + ' ' + iikoModifiers.kolvo + ' ' + data.maxAmount + '. ' + iikoModifiers.cho
311ose + ' ' + amount + '.'); 312 } 313 return null; 314 }); 315 316 if (messages && messages.length) { 317 e.preventDefault(); 318 $().render_modal('УкажиÑе паÑамеÑÑÑ ÑоваÑа', '', messages.join('<br>')); 319 } 320 }); 321 }); 322 }); 323 324});
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.