1/** 2 * ÐбÑабоÑка ÑоÑÐ¼Ñ Ð²Ð¾ÑÑÑÐ°Ð½Ð¾Ð²Ð»ÐµÐ½Ð¸Ñ Ð¿Ð°ÑÐ¾Ð»Ñ 3 */ 4document.addEventListener('DOMContentLoaded', function() { 5 const recoveryForm = document.querySelector('.js-recovery-form'); 6 const resendButton = document.querySelector('.js-recovery-form-resend'); 7 const submitButton = document.querySelector('.js-recovery-form-submit'); 8 const emailInput = document.querySelector('.js-recovery-form-email'); 9 const messageElement = document.querySelector('.modal-recovery-form__message'); 10 const mainTextElement = document.querySelector('.modal-recovery-form__main-text'); 11 12 if (!recoveryForm) return; 13 14 // ÐбÑабоÑка оÑпÑавки ÑоÑÐ¼Ñ 15 recoveryForm.addEventListener('submit', function(e) { 16 e.preventDefault(); 17 18 const email = emailInput.value.trim(); 19 20 if (!email) { 21 showError('ÐведиÑе email'); 22 return; 23 } 24 25 if (!isValidEmail(email)) { 26 showError('ÐведиÑе коÑÑекÑнÑй email'); 27 return; 28 } 29 30 // ÐоказÑваем загÑÑÐ·ÐºÑ Ð±ÐµÐ· завиÑимоÑÑи Ð¾Ñ SITE_TEMPLATE_PATH 31 submitButton.disabled = true; 32 const originalHtml = submitButton.innerHTML; 33 submitButton.dataset.originalHtml = originalHtml; 34 submitButton.innerHTML = '<span class="ui-button__text">ÐÑпÑавка...</span>'; 35 36 // ÐÑпÑавлÑем запÑÐ¾Ñ 37 const formData = new FormData(); 38 formData.append('email', email); 39 if (typeof BX !== 'undefined' && BX.bitrix_sessid) { 40 formData.append('sessid', BX.bitrix_sessid()); 41 } 42 43 fetch('/local/scripts/auth/password_recovery.php', { 44 method: 'POST', 45 body: formData 46 }) 47 .then(response => response.json()) 48 .then(data => { 49 if (data.success) { 50 showSuccess(data.message); 51 hideMainText(); 52 showMessage(); 53 } else { 54 showError(data.error || 'ÐÑоизоÑла оÑибка'); 55 } 56 }) 57 .catch(error => { 58 console.error('Error:', error); 59 showError('ÐÑоизоÑла оÑибка пÑи оÑпÑавке запÑоÑа'); 60 }) 61 .finally(() => { 62 // ÐоÑÑÑанавливаем ÐºÐ½Ð¾Ð¿ÐºÑ 63 submitButton.disabled = false; 64 submitButton.innerHTML = submitButton.dataset.originalHtml || '<span class="ui-button__text">ÐоÑÑÑановиÑÑ</span>'; 65 }); 66 }); 67 68 // ÐбÑабоÑка повÑоÑной оÑпÑавки 69 if (resendButton) { 70 resendButton.addEventListener('click', function() { 71 recoveryForm.dispatchEvent(new Event('submit')); 72 }); 73 } 74 75 // ФÑнкÑии Ð´Ð»Ñ Ð¾ÑобÑÐ°Ð¶ÐµÐ½Ð¸Ñ ÑообÑений 76 function showError(message) { 77 hideMessage(); 78 const errorDiv = document.createElement('div'); 79 errorDiv.className = 'modal__form-error'; 80 errorDiv.textContent = message; 81 recoveryForm.insertBefore(errorDiv, recoveryForm.firstChild); 82 83 // УбиÑаем оÑÐ¸Ð±ÐºÑ ÑеÑез 5 ÑекÑнд 84 setTimeout(() => { 85 if (errorDiv.parentNode) { 86 errorDiv.parentNode.removeChild(errorDiv); 87 } 88 }, 5000); 89 } 90 91 function showSuccess(message) { 92 hideMessage(); 93 messageElement.textContent = message; 94 showMessage(); 95 } 96 97 function showMessage() { 98 messageElement.style.display = 'block'; 99 if (resendButton) { 100 resendButton.style.display = 'inline-flex'; 101 } 102 submitButton.style.display = 'none'; 103 } 104 105 function hideMessage() { 106 messageElement.style.display = 'none'; 107 if (resendButton) { 108 resendButton.style.display = 'none'; 109 } 110 submitButton.style.display = 'inline-flex'; 111 } 112 113 function hideMainText() { 114 if (mainTextElement) { 115 mainTextElement.style.display = 'none'; 116 } 117 } 118 119 function isValidEmail(email) { 120 const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/; 121 return emailRegex.test(email); 122 } 123});
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.