PageSourceSearch

https://xn-----dlccfbfdksbbn6ccdrcazo.xn--p1ai/bitrix/cache/js/s1/…fc51ce947061c86274ffd7_v1.js?17870703347864

js xn-----dlccfbfdksbbn6ccdrcazo.xn--p1ai collected 2026-10-04 23:53:17 UTC 7,864 bytes, 295 lines download raw bytes

1
2; /* Start:"a:4:{s:4:"full";s:59:"/local/components/project/webform/webform.js?17858987467585";s:6:"source";s:44:"/local/components/project/webform/webform.js";s:3:"min";s:0:"";s:3:"map";s:0:"";}"*/
3if(!window.Project)
4    window.Project = {};
5
6window.Project.Ajax = function(component, method, data)
7{
8    let params = {
9        mode: 'class',
10        data: {post: data}
11    };
12    let bx_promise = BX.ajax.runComponentAction(component, method, params);
13    return new Promise(function(resolve, reject){
14        bx_promise.then(function(response) {
15            if (response.status === 'success')
16            {
17                resolve(response);
18            }
19            else
20            {
21                reject();
22            }
23        });
24    });
25}
26
27window.Project.Validity = {
28    email: function(email) {
29        let re = /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
30        return re.test(email);
31    },
32    input: function(input)
33    {
34        if(input.required && !input.value) return "Это поле должно быть заполнено";
35        if(input.type === 'email' && !window.Project.Validity.email(input.value)) return "Некорректный email";
36        if(input.type === 'checkbox' && input.classList.contains('visually-hidden') && !input.checked) return "Необходимо согласиться с условиями оферты";
37
38        if(input.pattern)
39        {
40            const pa = new RegExp(".{18,18}")
41            if(!pa.test(input.value)) return "Это поле заполненно некорректно";
42        }
43
44        console.log("[validity]", input);
45
46        return false;
47    }
48};
49
50window.Project.Webform = function(form_name, arParams)
51{
52    this.form_name = form_name;
53    this.arParams = arParams;
54    let self = this;
55    this.ajax = function(data)
56    {
57        return window.Project.Ajax('project:webform', 'send', {
58            fields: data,
59            arParams: self.arParams
60        })
61    }
62}
63
64window.Project.Webform.prototype = {
65    constructor: window.Project.Webform,
66    find: function(selector)
67    {
68        return this.findContainer().querySelector(selector)
69    },
70
71    findAll: function(selector)
72    {
73        return this.findContainer().querySelectorAll(selector)
74    },
75
76    findInputs: function()
77    {
78        return this.findAll('input, select, textarea');
79    },
80
81    findContainer: function()
82    {
83        return document.forms[this.form_name];
84    },
85
86    findSubmiters: function()
87    {
88        return this.findAll('button.btn');
89    },
90
91
92    bind: function()
93    {
94        let self = this;
95        this.findSubmiters().forEach(function(btn){
96            btn.addEventListener('click', self.submit.bind(self, btn));
97        });
98        this.findAll('input[type=file]').forEach(function(file_input){
99            let hidden = self.find("[name="+file_input.dataset.name+"]");
100            if(hidden)
101            {
102                self.bindFile(new window.Project.WebformFile(file_input, hidden));
103            }
104        })
105
106        this.bindCustom();
107    },
108
109    bindFile: function(webform_file)
110    {
111
112    },
113
114    bindCustom: function()
115    {
116
117    },
118
119    //////////////////////////////
120
121    createHint(is_error, msg)
122    {
123        let hint = document.createElement('p');
124        if(is_error)
125        {
126            hint.classList.add('form_error');
127            hint.style.color = '#f00';
128        }
129        else
130        {
131            hint.classList.add('form_success');
132            hint.style.color = 'rgb(5 154 5)';
133        }
134
135        hint.innerText = msg;
136        return hint;
137    },
138
139
140
141    clearHints: function()
142    {
143        this.findAll('.form_error').forEach(function(ep){
144            ep.parentNode.removeChild(ep);
145        })
146
147        this.findAll('.form_success').forEach(function(ep){
148            ep.parentNode.removeChild(ep);
149        })
150    },
151
152    attachHint(target, hint)
153    {
154        target.after(hint);
155    },
156
157    /////////////////////////
158
159    collectAll: function()
160    {
161        let collect = {form: {}, js: []};
162        this.findInputs().forEach(function(input){
163            if(input.type === 'checkbox' || input.type === 'radio')
164            {
165                if(input.checked)collect.form[input.name] = input.value;
166            }
167            else
168            {
169                collect.form[input.name] = input.value;
170            }
171            collect.js.push(input);
172        });
173
174        return collect;
175    },
176
177    checkState: function()
178    {
179        let success = true;
180        let self = this;
181
182        this.collectAll().js.forEach(function(input){
183            let error = window.Project.Validity.input(input);
184            if(error) {
185                self.attachHint(input, self.createHint(true, error));
186                success = false;
187            }
188        });
189
190        return success;
191    },
192
193    submit: function(btn, e)
194    {
195        e.preventDefault();
196        this.clearHints();
197        if(this.checkState())
198        {
199            let self = this;
200            this.ajax(this.collectAll().form).then(function(response){
201                if(response.data.status)
202                {
203                    document.dispatchEvent(new CustomEvent('project:webform:success', {
204                        detail: {
205                            form: self.findContainer(),
206                            button: btn,
207                            formCode: self.arParams && self.arParams.CODE ? self.arParams.CODE : ''
208                        }
209                    }));
210                    self.OnSuccess(btn);
211                }
212                else
213                {
214                    for (let i in response.data.errors)
215                    {
216                        let error = response.data.errors[i];
217                        self.attachHint(btn, self.createHint(true, error));
218                    }
219                }
220            })
221        }
222    },
223
224    OnSuccess: function(btn)
225    {
226        this.attachHint(btn, this.createHint(false, 'Форма успешно отправлена'));
227        this.findContainer().reset();
228    }
229};
230
231
232window.Project.WebformFile = function(input, hidden)
233{
234    this.input = input;
235    this.hidden = hidden;
236    this.proxy = new window.Project.Proxy();
237
238    this.bind();
239}
240
241window.Project.WebformFile.prototype = {
242    constructor: window.Project.WebformFile,
243    bind: function()
244    {
245        this.input.addEventListener('change', this.update.bind(this));
246    },
247
248    update: function()
249    {
250        console.log("[file] update", this.input.files[0])
251        let self = this;
252        if(this.input.files && this.input.files[0])
253        {
254            let file = this.input.files[0];
255            let reader = new FileReader();
256            reader.onload = function(e)
257            {
258                self.hidden.value = JSON.stringify({
259                    name: file.name,
260                    value: btoa(e.target.result)
261                });
262
263                self.proxy.release(file.name);
264            }
265
266            reader.readAsBinaryString(file);
267        }
268        else
269        {
270            self.hidden.value = '';
271        }
272    },
273}
274
275window.Project.Proxy = function()
276{
277    this.handlers = [];
278}
279
280window.Project.Proxy.prototype = {
281    assign: function(callback)
282    {
283        this.handlers.push(callback);
284    },
285
286    release: function(value)
287    {
288        this.handlers.forEach(function(handler){
289            handler(value);
290        })
291    }
292}
293
294/* End */
295;; /* /local/components/project/webform/webform.js?17858987467585*/

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.