1jQuery(document).ready(function ($) { 2 3 const RU_PHONE_ERROR = 'ÐÐ¾Ð¼ÐµÑ ÑелеÑона должен бÑÑÑ ÑоÑÑийÑким'; 4 5 const normalizePhone = (value) => { 6 let digits = String(value).replace(/\D/g, ''); 7 if (digits.length === 11 && digits.startsWith('8')) { 8 digits = '7' + digits.slice(1); 9 } 10 if (digits.length === 10 && (digits.startsWith('9') || digits.startsWith('3'))) { 11 digits = '7' + digits; 12 } 13 return digits.length === 11 ? digits : null; 14 }; 15 16 const isRussianPhone = (value) => { 17 const normalized = normalizePhone(value); 18 if (!normalized || normalized[0] !== '7') { 19 return false; 20 } 21 const secondDigit = normalized[1]; 22 return secondDigit === '9' || secondDigit === '3'; 23 }; 24 25 const formatRussianPhone = (digits) => { 26 return `+7 (${digits.slice(1, 4)}) ${digits.slice(4, 7)}-${digits.slice(7, 9)}-${digits.slice(9, 11)}`; 27 }; 28 29 const initRussianPhoneMask = () => { 30 const $inputs = $('.js-rfPhoneMask'); 31 if (!$inputs.length || typeof $.fn.inputmask !== 'function') { 32 return; 33 } 34 35 $inputs.inputmask({ 36 mask: '+7 (r99) 999-99-99', 37 definitions: { 38 r: { 39 validator: '[39]', 40 cardinality: 1, 41 }, 42 }, 43 clearIncomplete: true, 44 showMaskOnHover: false, 45 onBeforePaste: (pastedValue) => { 46 const normalized = normalizePhone(pastedValue); 47 if (!normalized || !isRussianPhone(normalized)) { 48 return ''; 49 } 50 return formatRussianPhone(normalized); 51 }, 52 }).each(function () { 53 $(this).on('focus', function () { 54 if ($(this).val().trim() === '') { 55 $(this).val('+7 ('); 56 } 57 }); 58 }); 59 }; 60 61 initRussianPhoneMask(); 62 63 const getPayload = (form) => $(form).serializeArray().filter(i => ['phone', 'sessid'].includes(i.name)).reduce((acc, i) => ({ ...acc, [i.name]: i.value }), {}) 64 65 const showError = (message, selector = '.new-auth__error-code') => { 66 const errorEl = document.querySelector(selector) 67 if (message && errorEl) { 68 errorEl.innerHTML = message 69 errorEl.style.display = 'block' 70 } else { 71 errorEl.innerHTML = '' 72 errorEl.style.display = 'none' 73 } 74 } 75 76 const disabledCode = (value) => { 77 const inputs = document.querySelectorAll(`.new-auth__code input`); 78 inputs.forEach((input) => { 79 input.disabled = value 80 }); 81 } 82 83 const pasteCode = (code) => { 84 const inputs = document.querySelectorAll(`.new-auth__code input`); 85 inputs.forEach((input, i) => { 86 input.value = code[i] 87 }); 88 } 89 90 const onFocusFirstInput = () => { 91 const input = document.querySelector(`.new-auth__code input`); 92 if (input) { 93 input.focus() 94 } 95 } 96 97 const sendCode = (code,) => { 98 const form = document.querySelector('.js-authForm') 99 const payload = getPayload(form) 100 disabledCode(true) 101 $.ajax({ 102 url: '/ajax/confirm_code.php', 103 method: 'POST', 104 data: { ...payload, code }, 105 dataType: 'json', 106 success: function (data) { 107 if (typeof data['status'] !== 'undefined' && data['status'] === 'OK') { 108 location.reload(); 109 } else { 110 showError(data?.message) 111 } 112 disabledCode(false) 113 }, 114 error: function (response, status) { 115 disabledCode(false) 116 } 117 }); 118 } 119 120 window.pincode = () => ({ 121 length: 6, 122 input: [], 123 onlyCheckOnLastFieldInput: true, 124 keydown(e, i) { 125 const keyName = e.key; 126 if (e.ctrlKey && keyName === "v") { 127 paste(e) 128 return; 129 } 130 if (keyName === "ArrowRight") { 131 this.goto(i + 1) 132 return; 133 } 134 if (keyName === "ArrowLeft") { 135 this.goto(i - 1) 136 return; 137 } 138 if (keyName === "Backspace") { 139 this.erase(e, i) 140 this.goto(i - 1) 141 return; 142 } 143 if (keyName === "Delete") { 144 this.erase(e, i) 145 return; 146 } 147 this.type(e, i) 148 }, 149 paste(event) { 150 let pasted = event.clipboardData.getData("text"); 151 pasted = pasted.replace(/\D/g, ""); 152 pasted = pasted.substring(0, this.length); 153 154 if (pasted) { 155 this.input = pasted.split(""); 156 pasteCode(this.input) 157 this.check(); 158 } 159 }, 160 type(event, index) { 161 event.stopPropagation(); 162 event.preventDefault(); 163 164 let key = +event.key 165 if ([0, 1, 2, 3, 4, 5, 6, 7, 8, 9].includes(key)) { 166 event.target.value = key 167 this.input[index - 1] = key; 168 if (this.validate()) { 169 this.check(); 170 } else { 171 this.goto(index + 1); 172 } 173 } 174 }, 175 validate() { 176 return this.input.filter(i => Number.isInteger(i)).length === this.length 177 }, 178 erase(event, index) { 179 event.stopPropagation(); 180 event.preventDefault(); 181 event.target.value = '' 182 this.input[index - 1] = ''; 183 }, 184 goto(n) { 185 if (!n || n > this.length) { 186 n = 1; 187 } 188 const el = document.querySelector(`input[name=pin${n}]`); 189 if (el) { 190 el.focus(); 191 } 192 193 }, 194 clear() { 195 this.input = [] 196 const inputs = document.querySelectorAll(`.new-auth__code input`);
197 inputs.forEach((input) => { 198 input.value = '' 199 }); 200 }, 201 check() { 202 sendCode(this.input.join("")) 203 } 204 205 }) 206 207 window.pincode = window.pincode() 208 209 const secToTime = (time) => { 210 const min = Math.floor(time / 60); 211 let sec = time % 60; 212 if (sec < 10) { 213 sec = `0${sec}`; 214 } 215 return `${min}:${sec}`; 216 } 217 218 const onTimer = (time) => { 219 const el = document.querySelector(`.new-auth__timer`); 220 const confirm = document.querySelector(`.new-auth--confirm`); 221 if (el && confirm) { 222 if (time > 0) { 223 el.innerHTML = `ÐолÑÑиÑÑ ÐºÐ¾Ð´ еÑе Ñаз ÑеÑез ${secToTime(time)}` 224 el.setAttribute("disabled", ""); 225 } else { 226 el.innerHTML = 'ÐолÑÑиÑÑ Ð½Ð¾Ð²Ñй код' 227 el.removeAttribute("disabled"); 228 } 229 if (time > 0) { 230 setTimeout(() => { 231 onTimer(time - 1) 232 }, 1000); 233 } 234 } 235 } 236 237 const clearCode = () => { 238 showError('') 239 showError('', '.new-auth__error-phone'); 240 if (window?.pincode?.clear) { 241 window.pincode.clear() 242 } 243 } 244 245 $(document).on('click', '.recoveryLink', function (e) { 246 const el = document.querySelector(`.new-auth `); 247 if (el) { 248 el.classList.remove('new-auth--confirm') 249 clearCode() 250 } 251 }) 252 253 $(document).on('submit', '.js-authForm', function (e) { 254 if (!this.querySelector('[name="phone"]')) { 255 return; 256 } 257 258 e.preventDefault(); 259 const payload = getPayload(this) 260 clearCode() 261 262 if (!payload.phone || !isRussianPhone(payload.phone)) { 263 showError(RU_PHONE_ERROR, '.new-auth__error-phone'); 264 return; 265 } 266 267 $('.js-successfulSend_dynamic').remove(); 268 $.ajax({ 269 url: '/ajax/auth.php', 270 method: 'POST', 271 data: payload, 272 dataType: 'json', 273 success: function (data) { 274 if (typeof data['status'] !== 'undefined' && data['status'] === 'OK') { 275 // location.reload(); 276 const el = document.querySelector(`.new-auth`); 277 if (el) { 278 el.classList.add('new-auth--confirm'); 279 setTimeout(()=>{ 280 onFocusFirstInput(); 281 },500) 282 } 283 const phone = document.querySelector(`.new-auth__phone`); 284 if (phone) { 285 phone.innerHTML = payload.phone; 286 } 287 onTimer(data?.time || 59); 288 } else { 289 showError(data.message, '.new-auth__error-phone'); 290 } 291 }, 292 error: function (response, status) { 293 showError(response, '.new-auth__error-phone'); 294 } 295 }); 296 297 }) 298});
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.