PageSourceSearch

https://aurora-pack.ru/local/templates/aurora/js/forms.js

js aurora-pack.ru collected 2026-10-04 13:26:18 UTC 3,967 bytes, 103 lines download raw bytes

1(function () {
2  if (window.__auroraFormsBound) return;
3  window.__auroraFormsBound = true;
4
5  var ENDPOINT = '/local/ajax/lead.php';
6
7  function isSearch(form) {
8    return !!(form.querySelector('input[name="q"]') || form.getAttribute('role') === 'search');
9  }
10
11  function labelFor(el) {
12    var lab = el.closest('label');
13    if (lab) {
14      var txt = (lab.querySelector('span') || lab).textContent || '';
15      txt = txt.replace(/\s+/g, ' ').trim().replace(/\s*\*$/, '');
16      if (txt) return txt;
17    }
18    if (el.id) {
19      var byFor = document.querySelector('label[for="' + el.id + '"]');
20      if (byFor) {
21        var t = (byFor.textContent || '').replace(/\s+/g, ' ').trim().replace(/\s*\*$/, '');
22        if (t) return t;
23      }
24    }
25    return (el.getAttribute('placeholder') || el.getAttribute('name') || el.getAttribute('aria-label') || 'Поле').trim();
26  }
27
28  function formTitle(form) {
29    var explicit = (form.getAttribute('data-form-name') || '').replace(/\s+/g, ' ').trim();
30    if (explicit) return explicit;
31    var node = form;
32    for (var i = 0; i < 6 && node; i++) {
33      var h = node.querySelector ? node.querySelector('h1, h2, h3') : null;
34      if (h && h.textContent.trim()) return h.textContent.replace(/\s+/g, ' ').trim();
35      node = node.parentElement;
36    }
37    return (document.title || 'Форма').trim();
38  }
39
40  function isConsent(el) {
41    var nm = (el.name || '').toLowerCase();
42    if (/soglas|consent|agree|personal|politic/.test(nm)) return true;
43    var lbl = (labelFor(el) || '').toLowerCase();
44    return /соглас|обработк|персональн|политик/.test(lbl);
45  }
46
47  function collect(form) {
48    var fields = {};
49    var controls = form.querySelectorAll('input, textarea, select');
50    for (var i = 0; i < controls.length; i++) {
51      var el = controls[i];
52      var type = (el.type || '').toLowerCase();
53      if (type === 'submit' || type === 'button' || type === 'reset' || type === 'hidden' || type === 'file') continue;
54      if ((type === 'checkbox' || type === 'radio') && !el.checked) continue;
55      if ((type === 'checkbox' || type === 'radio') && isConsent(el)) continue;
56      var val = (el.value || '').trim();
57      if (!val) continue;
58      if (type === 'checkbox' || type === 'radio') val = el.value && el.value !== 'on' ? el.value : 'да';
59      fields[labelFor(el)] = val;
60    }
61    return fields;
62  }
63
64  function filesWith(form) {
65    var out = [], ins = form.querySelectorAll('input[type="file"]');
66    for (var i = 0; i < ins.length; i++) if (ins[i].files && ins[i].files.length) out.push(ins[i]);
67    return out;
68  }
69
70  function onSubmit(e) {
71    var form = e.target;
72    if (!form || form.tagName !== 'FORM' || isSearch(form)) return;
73
74    var fields = collect(form);
75    var files = filesWith(form);
76    if (!Object.keys(fields).length && !files.length) return;
77
78    try {
79      if (files.length) {
80        var fd = new FormData();
81        fd.append('form', formTitle(form));
82        fd.append('code', form.getAttribute('data-form-code') || '');
83        fd.append('page', location.pathname);
84        for (var k in fields) if (Object.prototype.hasOwnProperty.call(fields, k)) fd.append('fields[' + k + ']', fields[k]);
85        for (var i = 0; i < files.length; i++) {
86          var fl = files[i].files;
87          for (var j = 0; j < fl.length; j++) fd.append('files[]', fl[j]);
88        }
89        fetch(ENDPOINT, { method: 'POST', body: fd, credentials: 'same-origin' }).catch(function () {});
90      } else {
91        fetch(ENDPOINT, {
92          method: 'POST',
93          headers: { 'Content-Type': 'application/json' },
94          body: JSON.stringify({ form: formTitle(form), code: form.getAttribute('data-form-code') || '', page: location.pathname, fields: fields }),
95          keepalive: true,
96          credentials: 'same-origin'
97        }).catch(function () {});
98      }
99    } catch (err) {}
100  }
101
102  document.addEventListener('submit', onSubmit, true);
103})();

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.