1(function ($) { 2 $.instantorder = { 3 options: {}, 4 init: function (options) { 5 this.options = options; 6 this.initModal(); 7 }, 8 initModal: function () { 9 if (!this.options.instantorder_btn_selector) { 10 console.log('Ðе задан ÑелекÑÐ¾Ñ ÐºÐ½Ð¾Ð¿ÐºÐ¸ бÑÑÑÑого заказа'); 11 return false; 12 } 13 self = this; 14 $(document).off('click', this.options.instantorder_btn_selector).on('click', this.options.instantorder_btn_selector, function () { 15 var btn = $(this); 16 var mode = btn.data('mode'); 17 var form = btn.closest('form'); 18 if (!mode) { 19 console.log('У кнопки бÑÑÑÑого заказа не Ñказан аÑÑибÑÑ data-mode: product, products-list, cart'); 20 return false; 21 } 22 var post_data = null 23 if (mode == 'product') { 24 if (!self.options.product_form_selector) { 25 console.log('Ðе Ñказан ÑелекÑÐ¾Ñ ÑоÑÐ¼Ñ Ð´Ð¾Ð±Ð°Ð²Ð»ÐµÐ½Ð¸Ñ ÑоваÑа в коÑзинÑ'); 26 return false; 27 } 28 if(!form.length){ 29 if (!$(self.options.product_form_selector).length) { 30 console.log('СелекÑÐ¾Ñ ÑоÑÐ¼Ñ Ð´Ð¾Ð±Ð°Ð²Ð»ÐµÐ½Ð¸Ñ ÑоваÑа в коÑÐ·Ð¸Ð½Ñ Ñказан невеÑно'); 31 return false; 32 } 33 form = $(self.options.product_form_selector); 34 } 35 36 37 post_data = form.serialize(); 38 } else if (mode == 'products-list') { 39 if (!btn.data('product-id')) { 40 console.log('Ðе Ñказан иденÑиÑикаÑÐ¾Ñ ÑоваÑа'); 41 return false; 42 } 43 post_data = 'product_id=' + btn.data('product-id'); 44 if (btn.data('sku-id')) { 45 post_data += '&sku_id=' + btn.data('sku-id'); 46 } 47 } else if (mode == 'cart') { 48 post_data = 'cart=1'; 49 } 50 modal({ 51 animate: true, 52 type: 'confirm', 53 title: self.options.modal_title, 54 text: '<i class="icon16 loading"></i> ÐожалÑйÑÑа, подождиÑе...', 55 buttons: [ 56 { 57 addClass: '' 58 }, 59 { 60 addClass: self.options.order_btn_class 61 } 62 ], 63 buttonText: { 64 yes: self.options.order_btn_text, 65 cancel: self.options.close_btn_text 66 }, 67 onShow: function (r) { 68 var u = r.getModal(); 69 var order_btn = u.find('.modal-buttons .modal-btn:eq(1)'); 70 order_btn.addClass('btn-disabled'); 71 $.ajax({ 72 type: 'POST', 73 url: self.options.url, 74 dataType: 'html', 75 data: post_data, 76 success: function (html, textStatus, jqXHR) { 77 if ($('<div></div>').append(html).find('[name=action][value=selectSku]').length) { 78 self.selectSkuAction(r, html); 79 } else { 80 self.cartAction(r, html); 81 } 82 }, 83 error: function (jqXHR, errorText) { 84 r.setContent('<div class="errors">' + jqXHR.responseText + '</div>'); 85 $(window).resize(); 86 } 87 }); 88 }, 89 callback: function (a, u, r) { 90 if (a) { 91 self.order(r); 92 return false;
93 } 94 if (u.find('.instantorder-content.success').length && u.find('input[name=cart_mode][value=1]').length) { 95 window.location.reload(); 96 } 97 } 98 }); 99 return false; 100 }); 101 }, 102 selectSkuAction: function (r, html) { 103 var u = r.getModal(); 104 var order_btn = u.find('.modal-buttons .modal-btn:eq(1)'); 105 order_btn.text(this.options.select_btn_text); 106 if (!$(html).find('.errors').length) { 107 order_btn.removeClass('btn-disabled'); 108 } 109 r.setContent(html); 110 $(window).resize(); 111 }, 112 cartAction: function (r, html) { 113 var u = r.getModal(); 114 var order_btn = u.find('.modal-buttons .modal-btn:eq(1)'); 115 order_btn.text(this.options.order_btn_text); 116 if (!$(html).find('.errors').length) { 117 order_btn.removeClass('btn-disabled'); 118 } 119 r.setContent(html); 120 $(window).resize(); 121 this.initQuantity(u); 122 this.initServices(u); 123 this.initValide(u); 124 this.initMaskedInput(u); 125 this.checkItems(u); 126 this.initCaptcha(u); 127 }, 128 initCaptcha: function (u) { 129 if (!u.find('.wa-field-captcha').length) { 130 return; 131 } 132 u.find('.wa-captcha-img').click(function () { 133 $(this).attr('src', $(this).attr('src').replace(/\?.*$/, '?rid=' + Math.random())); 134 $(this).one('load', function () { 135 u.find('.wa-captcha-input').focus(); 136 }); 137 return false; 138 }); 139 }, 140 checkItems: function (u) { 141 u.find('.instantorder-items-table .qty_block .quantity').each(function () { 142 if (parseInt($(this).val()) < 1) { 143 var tr = $(this).closest('tr'); 144 tr.addClass('disabled'); 145 tr.find('input,select').attr('disabled', true); 146 tr.find('.minus,.plus').addClass('btn-disabled'); 147 } 148 }); 149 if (!u.find('.instantorder-items-table tbody tr:not(.disabled)').length) { 150 u.find('.modal-buttons .modal-btn:eq(1)').addClass('btn-disabled'); 151 } 152 }, 153 initMaskedInput: function (u) { 154 if (this.options.phone_mask.length) { 155 u.find('#instantorder-order-form input[name="customer[phone]"]').mask(this.options.phone_mask); 156 } 157 }, 158 initValide: function (u) { 159 u.find('#instantorder-order-form').validate({ 160 errorPlacement: function (error, element) { 161 if ($(element).closest('label').length) { 162 $(element).closest('label').after(error); 163 } else { 164 $(element).after(error); 165 } 166 }, 167 errorElement: "div", 168 rules: { 169 terms: { 170 required: true 171 } 172 }, 173 messages: { 174 terms: "ÐÑо поле обÑзаÑелÑное Ð´Ð»Ñ Ð·Ð°Ð¿Ð¾Ð»Ð½ÐµÐ½Ð¸Ñ" 175 } 176 }); 177 u.find('#instantorder-order-form .wa-required, #instantorder-order-form .wa-field-captcha').find('input:visible, textarea:visible').each(function () { 178 $(this).rules('add', { 179 required: true, 180 messages: { 181 required: "ÐÑо поле обÑзаÑелÑное Ð´Ð»Ñ Ð·Ð°Ð¿Ð¾Ð»Ð½ÐµÐ½Ð¸Ñ" 182 } 183 }); 184 }); 185 }, 186 initServices: function (u) { 187 var self = this; 188 u.on('change', '.services input:checkbox', function () { 189 if ($(this).is(':checked')) { 190 $(this).closest('.service').find('.service-data').removeAttr('disabled'); 191 } else { 192 $(this).closest('.service').find('.service-data').attr('disabled', 'disabled'); 193 } 194 if ($(this).closest('.service').find('select').length) { 195 if ($(this).is(':checked')) { 196 $(this).closest('.service').find('select').removeAttr('disabled'); 197 } else { 198 $(this).closest('.service').find('select').attr('disabled', 'disabled'); 199 } 200 } 201 self.recalculate(u); 202 }); 203 204 u.on('change', '.services select', function () { 205 self.recalculate(u); 206 }); 207 }, 208 initQuantity: function (u) { 209 var self = this; 210 u.on('click', '.minus', function () { 211 var input = $(this).siblings('.quantity'); 212 var quantity = parseInt(input.val()); 213 if (quantity < 2) { 214 return false;
215 } 216 $(this).closest('tr').find('.quantity').val(quantity - 1); 217 self.recalculate(u); 218 return false; 219 }); 220 u.on('click', '.plus', function () { 221 var input = $(this).siblings('.quantity'); 222 var quantity = parseInt(input.val()); 223 $(this).closest('tr').find('.quantity').val(quantity + 1); 224 self.recalculate(u); 225 return false; 226 }); 227 u.on('change', '.quantity', function () { 228 var input = $(this); 229 var quantity = parseInt(input.val()); 230 $(this).closest('tr').find('.quantity').val(quantity); 231 if (isNaN(quantity) || quantity < 1) { 232 $(this).closest('tr').find('.quantity').val(1); 233 } 234 self.recalculate(u); 235 }); 236 u.on('click', '.delete', function () { 237 $(this).closest('tr').remove(); 238 if (u.find('.instantorder-items-table tbody tr').length < 2) { 239 u.find('.instantorder-items-table tbody tr .delete').hide(); 240 } 241 self.recalculate(u); 242 return false; 243 }); 244 }, 245 recalculate: function (u) { 246 var loading = $('<i class="icon16 loading"></i>'); 247 u.find('.instantorder-items-table .total td:first').prepend(loading); 248 var f = $('#instantorder-order-form'); 249 $.ajax({ 250 type: 'POST', 251 url: this.options.recalculate_url, 252 dataType: 'json', 253 data: f.serialize(), 254 success: function (data, textStatus, jqXHR) { 255 loading.remove(); 256 if (data.status == 'ok') { 257 u.find('.instantorder-items-table .cart-total').html(data.data.total); 258 u.find('.instantorder-items-table .cart-discount').html(data.data.discount); 259 for (var item_id in data.data.order.items) { 260 var item = data.data.order.items[item_id]; 261 if (item.error) { 262 alert(item.error); 263 } 264 u.find('.instantorder-items-table tr[data-id=' + item.id + '] .quantity').val(item.quantity); 265 u.find('.instantorder-items-table tr[data-id=' + item.id + '] .item-full-price').html(item.full_price_html); 266 if (item.quantity < 1) { 267 var tr = u.find('.instantorder-items-table tr[data-id=' + item.id + ']'); 268 tr.addClass('disabled'); 269 tr.find('input,select').attr('disabled', true); 270 tr.find('.minus,.plus').addClass('btn-disabled'); 271 } 272 if (!u.find('.instantorder-items-table tbody tr:not(.disabled)').length) { 273 u.find('.modal-buttons .modal-btn:eq(1)').addClass('btn-disabled'); 274 } 275 } 276 } else { 277 alert(data.errors.join(', ')); 278 } 279 }, 280 error: function (jqXHR, errorText) { 281 loading.remove(); 282 console.log(jqXHR.responseText); 283 } 284 }); 285 }, 286 order: function (r) { 287 var self = this; 288 var u = r.getModal(); 289 if (u.find('[name=action][value=selectSku]').length) { 290 var post_data = u.find('#cart-form-dialog').serialize(); 291 $.ajax({ 292 type: 'POST', 293 url: self.options.url, 294 dataType: 'html', 295 data: post_data, 296 success: function (html, textStatus, jqXHR) { 297 self.cartAction(r, html); 298 }, 299 error: function (jqXHR, errorText) { 300 r.setContent('<div class="errors">' + jqXHR.responseText + '</div>'); 301 $(window).resize(); 302 } 303 }); 304 } else { 305 var f = $('#instantorder-order-form');
306 var order_btn = u.find('.modal-buttons .modal-btn:eq(1)'); 307 if (!f.valid()) { 308 return false; 309 } 310 order_btn.addClass('btn-disabled'); 311 $.ajax({ 312 type: 'POST', 313 url: this.options.order_url, 314 dataType: 'json', 315 data: f.serialize(), 316 success: function (data, textStatus, jqXHR) { 317 if (data.status == 'ok') { 318 r.setContent(data.data.html); 319 $(window).resize(); 320 order_btn.hide(); 321 } else { 322 alert(data.errors.join(', ')); 323 order_btn.removeClass('btn-disabled'); 324 } 325 }, 326 error: function (jqXHR, errorText) { 327 alert(jqXHR.responseText); 328 console.log(jqXHR.responseText); 329 order_btn.removeClass('btn-disabled'); 330 } 331 }); 332 } 333 } 334 }; 335})(jQuery);
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.