1(function () { 2 'use strict'; 3 4 var refreshEndpoint = '/local/ajax-files/captcha_refresh.php'; 5 6 function findParentByClass(node, className) { 7 while (node && node !== document) { 8 if (node.classList && node.classList.contains(className)) { 9 return node; 10 } 11 12 node = node.parentNode; 13 } 14 15 return null; 16 } 17 18 function setLoading(button, isLoading) { 19 button.disabled = isLoading; 20 button.setAttribute('aria-busy', isLoading ? 'true' : 'false'); 21 22 if (isLoading) { 23 button.classList.add('is-loading'); 24 } else { 25 button.classList.remove('is-loading'); 26 } 27 } 28 29 function showError(control, button) { 30 var status = control.querySelector('.js-captcha-status'); 31 var message = button.getAttribute('data-error-message') || 'Ðе ÑдалоÑÑ Ð¾Ð±Ð½Ð¾Ð²Ð¸ÑÑ CAPTCHA.'; 32 33 if (status) { 34 status.textContent = message; 35 } 36 } 37 38 function refreshCaptcha(button) { 39 var control = findParentByClass(button, 'js-captcha-control'); 40 41 if (!control || button.disabled) { 42 return; 43 } 44 45 var sidInput = control.querySelector('input[name="captcha_sid"]'); 46 var wordInput = control.querySelector('input[name="captcha_word"]'); 47 var image = control.querySelector('.js-captcha-image'); 48 var status = control.querySelector('.js-captcha-status'); 49 50 if (!sidInput || !image) { 51 return; 52 } 53 54 setLoading(button, true); 55 56 if (status) { 57 status.textContent = ''; 58 } 59 60 var request = new XMLHttpRequest(); 61 request.open('GET', refreshEndpoint + '?_=' + new Date().getTime(), true); 62 request.setRequestHeader('X-Requested-With', 'XMLHttpRequest'); 63 64 request.onreadystatechange = function () { 65 if (request.readyState !== 4) { 66 return; 67 } 68 69 setLoading(button, false); 70 71 if (request.status < 200 || request.status >= 300) { 72 showError(control, button); 73 return; 74 } 75 76 var response; 77 78 try { 79 response = JSON.parse(request.responseText); 80 } catch (error) { 81 showError(control, button); 82 return; 83 } 84 85 if (!response.success || !response.captchaSid) { 86 showError(control, button); 87 return; 88 } 89 90 sidInput.value = response.captchaSid; 91 image.src = '/bitrix/tools/captcha.php?captcha_sid=' 92 + encodeURIComponent(response.captchaSid) 93 + '&_=' 94 + new Date().getTime(); 95 96 if (wordInput) { 97 wordInput.value = ''; 98 wordInput.focus(); 99 } 100 }; 101 102 request.onerror = function () { 103 setLoading(button, false); 104 showError(control, button); 105 }; 106 107 request.send(); 108 } 109 110 document.addEventListener('click', function (event) { 111 var button = findParentByClass(event.target, 'js-captcha-refresh'); 112 113 if (!button) { 114 return; 115 } 116 117 event.preventDefault(); 118 refreshCaptcha(button); 119 }); 120}());
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.