1$(document).ready(function() { 2 /** **/ 3 $("form input.phone").mask("+7 (999) 999-99-99"); 4 $("form input.date").mask("99.99.9999"); 5 if ($.isFunction($.fn.selectmenu)) { 6 $("form select").selectmenu(); 7 } 8 9 $('form .field-row.file input').on('change', function(){ 10 let file = this.files[0]; 11 $(this).closest('label').find('.btn-file span').html(file.name); 12 }); 13 14 /** Events **/ 15 $(document).on('change', 'form.web-form .rating_container .rating_btn_container input', function() { 16 let $input = $(this); 17 18 let $rating_container = $input.closest('.rating_container'); 19 let $inputs = $input.parent().find('input'); 20 let $labels = $input.parent().find('label'); 21 22 let clickedInputIndex = $inputs.index($input); 23 $labels.removeClass("active"); 24 25 if ($rating_container.hasClass('stars')) { 26 for (let i = 0; i <= clickedInputIndex; i++) { 27 $labels.eq(i).addClass('active'); 28 } 29 } else { 30 $labels.eq(clickedInputIndex).addClass('active'); 31 } 32 }); 33 34 let $inputs = $('form.web-form input[data-connected="Y"]'); 35 for (let i = 0; i < $inputs.length; i++) { 36 let $input = $inputs.eq(i); 37 let $fieldRow = $input.closest('.field-row'); 38 $fieldRow.next().hide(); 39 40 $fieldRow.on('change', 'input', function() { 41 let $input = $(this); 42 if ($input.is(":checked")) { 43 if ($input.data('connected') === "Y") { 44 $fieldRow.next().show(); 45 } else { 46 $fieldRow.next().hide(); 47 } 48 } 49 }); 50 } 51 52 $(document).on('click', 'form.web-form a.btn.add-product', function() { 53 let $btn = $(this); 54 55 56 let $allContainer = $btn.parent().find('.product_container'); 57 58 let $currProdContainer = $allContainer.eq(0); 59
60 let $productContainer = $('<div class="product_container"></div>'); 61 $productContainer.append($currProdContainer.find('select').clone()); 62 $productContainer.append($currProdContainer.find('input').clone().val('')); 63 64 $productContainer.html($productContainer[0].innerHTML.replaceAll('[0]', `[${$allContainer.length}]`)); 65 66 $productContainer.append( 67 '<a href="#" class="btn-transparent remove-product"><i>Ã</i></a>' 68 ); 69 70 $productContainer.css('padding-right', '2rem'); 71 72 $btn.before($productContainer); 73 74 $("form select").selectmenu(); 75 }); 76 77 $(document).on('click', 'form.web-form .remove-product', function(e) { 78 e.preventDefault(); 79 $(this).closest('.product_container').remove(); 80 }); 81 82 $(document).on('submit', 'form.web-form', function(e) { 83 e.preventDefault(); 84 85 let $form = $(this); 86 let $submitBtn = $form.find('.btn.submit'); 87 88 if ($submitBtn.hasClass('submitted')) { 89 return false; 90 } 91 92 let $successText = $form.parent().find('.success-text'); 93 94 let formData = new FormData(); 95 96 let formValidated = true; 97 98 let $inputs = $form.find('input[type=hidden], input[type=text], input[type=file], textarea'); 99 let $btnFile = $('.btn-file'); 100 for (let i = 0; i < $inputs.length; i++) { 101 let $input = $inputs.eq(i); 102 $input.removeClass('error'); 103 $btnFile.removeClass('error'); 104 105 let value = $input.val().trim(); 106 107 if ($input.hasClass('required') && !value) { 108 formValidated = false; 109 $input.addClass('error'); 110 if ($input.attr('type') === 'file'){ 111 $btnFile.addClass('error'); 112 } 113 } 114 115 if (value) { 116 if ($input.hasClass('email') && !(/^([a-zA-Z0-9_.+-])+\@(([a-zA-Z0-9-])+\.)+([a-zA-Z0-9]{2,4})+$/).test(value)) { 117 formValidated = false; 118 $input.addClass('error'); 119 } 120 } 121 122 if ($input.attr('type') === 'file') { 123 if ($input[0].files[0]) { 124 formData.append($input.attr('name'), $input[0].files[0]); 125 } 126 } else { 127 formData.append($input.attr('name'), value); 128 } 129 } 130 131 let $inputCheckboxes = $form.find('input[type=checkbox].required'); 132 for (let i = 0; i < $inputCheckboxes.length; i++) { 133 let $checkbox = $inputCheckboxes.eq(i); 134 $checkbox.removeClass('error'); 135 136 if (!$checkbox.is(':checked')) { 137 formValidated = false; 138 $checkbox.addClass('error'); 139 } else { 140 formData.append($checkbox.attr('name'), $checkbox.val()); 141 } 142 } 143 144 let $inputOthers = $form.find('input[type=radio]:checked, select'); 145 for (let i = 0; i < $inputOthers.length; i++) { 146 let $input = $inputOthers.eq(i); 147 $input.removeClass('error'); 148 149 let value = $input.val(); 150 151 if ($input.hasClass('required') && !value) { 152 formValidated = false; 153 $input.addClass('error'); 154 } 155 156 if (value) { 157 formData.append($input.attr('name'), value); 158 } 159 } 160 161 if (!formValidated) { 162 const $firstErr = $form.find('.error').first(); 163 if ($firstErr.length) { 164 $('html, body').animate({ 165 scrollTop: $firstErr.offset().top - ($(window).height() - $firstErr.outerHeight()) / 2 166 }, 500); 167 $firstErr.focus(); 168 } 169 return; 170 } 171 172 if (formValidated) { 173 $form.addClass('blocked'); 174 $submitBtn.addClass('submitted'); 175 176 $.ajax({ 177 method: "POST", 178 url: "/local/include/_common/forms/_ajax.php", 179 data: formData, 180 processData: false, 181 contentType: false, 182 success: function (data) { 183 $submitBtn.removeClass('submitted'); 184 $form.removeClass('blocked'); 185 186 data = JSON.parse(data); 187 if (data["SUCCESS"]) { 188 if ($form.data('on-submit-yandex-aim')) { 189 SendAim($form.data('on-submit-yandex-aim')); 190 } 191 192 if (data.DATA.TYPE === 'get_electronic_catalog' || data.DATA.TYPE === 'get_electronic_price') { 193 document.cookie = "electronic_catalog=true; path=/; max-age=" + (60 * 60 * 24 * 365); 194 updateCatalogLinks(); 195 } 196 197 $form.remove(); 198 $successText.show(); 199 200 $form.find('.error').removeClass('error'); 201 $('.success-popup').addClass('open'); 202 } else { 203 $submitBtn.removeClass('submitted'); 204 } 205 } 206 }); 207 } 208 }); 209 if (document.cookie.split(';').some(c => c.trim() === 'electronic_catalog=true')) { 210 updateCatalogLinks(); 211 } 212 function updateCatalogLinks() { 213 $('.btn-get_electronic_catalog').each(function() { 214 let $btn = $(this); 215 let file = $btn.data('entity-file'); 216 if (!file) return;
217 $btn.removeClass('btn-get_electronic_catalog btn-popup').attr('href', file).attr('target', '_blank').removeAttr('data-entity-file').removeAttr('data-entity-file-name'); 218 }); 219 $('.btn-get_electronic_price').each(function() { 220 let $btn = $(this); 221 let file = $btn.data('entity-file'); 222 if (!file) return; 223 $btn.removeClass('btn-get_electronic_price btn-popup').attr('href', file).attr('target', '_blank').removeAttr('data-entity-file').removeAttr('data-entity-file-name'); 224 }); 225 } 226});
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.