PageSourceSearch

https://mebelart.by/local/components/slam/subscribe/script.js?17122322969431

js mebelart.by collected 2026-10-09 00:39:41 UTC 9,431 bytes, 323 lines download raw bytes

1if (typeof JCslamSubscribeForm !== 'undefined') {
2
3	console.log('reconnection attempt JCslamSubscribeForm');
4
5} else {
6
7
8	window.JCslamSubscribeForm = class JCslamSubscribeForm {
9		constructor(arParams) {
10			if (typeof arParams === 'object') {
11				this.form = document.querySelector('#subscribe_form_' + arParams.FORM_ID);
12				this.form_confirm = document.querySelector('#confirm_form_' + arParams.FORM_ID);
13				this.form_id = arParams.FORM_ID;
14				this.text_success = arParams.OK_TEXT;
15				this.text_unsubscribe = arParams.CANCEL_TEXT;
16				this.check_confirm = arParams.USE_CONFIRM;
17				this.modalForm = document.querySelector('#frm-modal-' + arParams.FORM_ID);
18				this.params = arParams;
19				this.init();
20			}
21		}
22		init() {
23			if (!this.form) {
24				console.log('Form error: ID form no search. Specify the form ID in the subscribe form.');
25				return false;
26			}
27
28
29			if ((this.params.USE_SLAM_VALIDATOR_FROM_THIS_COMPONENT === 'Y')) {
30				this.validator = new SlamValidator(this.form);
31				if (this.form_confirm) {
32					new SlamValidator(this.form_confirm);
33				}
34			}
35
36
37			this.form.addEventListener((this.params.USE_SLAM_VALIDATOR_FROM_THIS_COMPONENT === 'Y') ? 'success.slam.validator' : 'submit', async (e) => {
38				e.preventDefault();
39
40				try {
41
42					this.form.querySelector('.submit_subscribe')?.classList.add('spinner');
43					this.form.querySelector('.submit_subscribe')?.setAttribute('disabled', true);
44
45					const response = await JCslamSubscribeForm.ajax(this.form, this.params);
46
47					if (response.status === 200) {
48
49						const data = await response.json();
50
51						if (data.result === 'ok') {
52							try {
53								var funcName = this.params._CALLBACKS;
54								if (funcName) {
55									eval(funcName)(data);
56								} else {
57									this.showMessage(true, data.message);
58								}
59							} catch (e) {
60								this.showMessage(true, data.message);
61							}
62							this.resetForm();
63						} else {
64							this.showMessage('error', data.message);
65						}
66						this.form.querySelector('.submit_subscribe')?.classList.remove('spinner');
67						setTimeout(() => {
68							this.form.querySelector('.submit_subscribe')?.removeAttribute('disabled');
69						}, 500);
70
71
72					}
73
74					return;
75
76				} catch (e) {
77					console.log('error', e);
78				}
79
80				return false;
81
82			});
83
84			this.form_confirm?.addEventListener((this.params.USE_SLAM_VALIDATOR_FROM_THIS_COMPONENT === 'Y') ? 'success.slam.validator' : 'submit', async (e) => {
85
86				e.preventDefault();
87
88				try {
89
90					this.form_confirm.querySelector('.submit_subscribe')?.classList.add('spinner');
91					this.form_confirm.querySelector('.submit_subscribe')?.setAttribute('disabled', true);
92
93					const response = await JCslamSubscribeForm.ajax(this.form_confirm, this.params);
94
95					if (response.status === 200) {
96
97						const data = await response.json();
98
99						if (data.result === 'ok') {
100							this.showMessage(true, data.message);
101							this.resetForm();
102						} else {
103							this.showMessage('error', data.message);
104							this.resetForm();
105						}
106						this.form_confirm.querySelector('.submit_subscribe')?.classList.remove('spinner');
107						setTimeout(() => {
108							this.form_confirm.querySelector('.submit_subscribe').removeAttribute("disabled");
109						}, 500);
110					}
111
112				} catch (e) {
113					console.log('error', e);
114				}
115
116				return;
117			});
118
119			//unsubscribe
120			(async () => {
121				// если пользователь перешел по прямой ссылке
122				var get_email = this.getUrlParameter('email');
123				var get_code = this.getUrlParameter('CONFIRM_CODE');
124				var get_action = this.getUrlParameter('action');
125
126				if (get_email && get_code && (get_action === 'unsubscribe' || get_action ==='confirm_subscribe')) {
127
128					const dataParams = [];
129					dataParams.push({ name: 'action', value: get_action });
130					dataParams.push({ name: 'CONFIRM_CODE', value: get_code });
131					dataParams.push({ name: 'email', value: get_email });
132
133					try {
134						const response = await JCslamSubscribeForm.ajax(undefined, this.params, dataParams);
135
136						if (response.status === 200) {
137
138							const data = await response.json();
139
140							if (data.result === 'ok') {
141								this.showMessage(true, data.message);
142								window.history.replaceState(null, null, window.location.pathname);
143								this.resetForm();
144							} else {
145								this.showMessage('error',  data.message);
146								window.history.replaceState(null, null, window.location.pathname);
147								this.resetForm();
148							}
149
150						}
151					} catch (e) {
152						console.log('error', e);
153					}
154
155					return false;
156
157				}
158
159			})();
160
161
162		}
163		showMessage(status, message) {
164
165			var alert, confirm_block;
166
167			alert = this.modalForm?.querySelector('.alert');
168			confirm_block = this.modalForm?.querySelector('.confirm_block');
169
170			if (status === undefined || !alert) {
171				return false;
172			}
173
174			if (status !== 'error') {
175
176				if (message === 'subscribe') {//если мы удачно подписались
177
178					if (this.check_confirm === 'Y') {//если установлен параметр "Подтверждать подписку"
179
180						//проставляем email в форму подтверждения подписки
181						const email = document.getElementById('email_' + this.form_id)?.value;
182						document.getElementById('confirm_email_' + this.form_id).value = email;
183						confirm_block?.classList.remove('hidden');
184						alert.innerHTML = '';
185						alert?.classList.add('hidden');
186
187						if (window.jQuery && window.jQuery().modal) {
188							$(this.modalForm).modal();
189						} else {
190							this.modalForm.modal();
191						}
192
193
194					} else {
195
196						alert.innerHTML = this.text_success;
197						alert?.classList.remove('error_subscribe');
198						alert?.classList.remove('hidden');
199						if (window.jQuery && window.jQuery().modal) {
200							$(this.modalForm).modal();
201						} else {
202							this.modalForm.modal();
203						}
204
205					}
206				} else if (message === 'confirm_subscribe') {//если мы удачно подтвердили подписку
207
208					alert.innerHTML = this.text_success;
209					alert?.classList.remove('hidden');
210					alert?.classList.remove('error_subscribe');
211					confirm_block?.classList.add('hidden');
212					if (window.jQuery && window.jQuery().modal) {
213						$(this.modalForm).modal();
214					} else {
215						this.modalForm.modal();
216					}
217
218				} else if (message === 'unsubscribe') {//если мы удачно отписались от рассылки
219
220					alert.innerHTML = this.text_unsubscribe;
221					alert?.classList.remove('hidden');
222					alert?.classList.remove('error_subscribe');
223					confirm_block?.classList.add('hidden');
224					if (window.jQuery && window.jQuery().modal) {
225						$(this.modalForm).modal();
226					} else {
227						this.modalForm.modal();
228					}
229
230				}
231			} else if (status === 'error') {
232
233				alert.innerHTML = '';
234				alert?.classList.add('error_subscribe');
235				alert?.classList.remove('hidden');
236				confirm_block?.classList.add('hidden');
237				if (this.modalForm?.classList.contains('in')) {
238					setTimeout(() => {
239						alert.innerHTML = message;
240					}, 500);
241				} else {
242					alert.innerHTML = message;
243					if (window.jQuery && window.jQuery().modal) {
244						console.log('-------->111111111111');
245						console.log(message);
246						console.log('-------->1111111111');
247						$(this.modalForm).modal();
248					} else {
249						console.log('-------->22222222');
250						console.log(this.modalForm);
251						console.log('-------->222222222');
252
253						setTimeout(() => {
254							this.modalForm.modal();
255						}, 1000);
256
257
258					}
259				}
260			} else {
261				return false;
262			}
263
264		}
265		resetForm() {
266			setTimeout(() => {
267				this.form.reset();
268				this.form_confirm.reset();
269			}, 500);
270		}
271		getUrlParameter(sParam) {
272			var sPageURL = window.location.search.substring(1),
273				sURLVariables = sPageURL.split('&'),
274				sParameterName,
275				i;
276
277			for (i = 0; i < sURLVariables.length; i++) {
278				sParameterName = sURLVariables[i].split('=');
279				if (sParameterName[0] === sParam) {
280					return sParameterName[1] === undefined ? true : decodeURIComponent(sParameterName[1]);
281				}
282			}
283		}
284	}
285
286
287	JCslamSubscribeForm.serializeArray = (form) => {
288
289		// Create a new FormData object
290		const formData = new FormData(form);
291
292		// Create an array to hold the name/value pairs
293		const pairs = [];
294
295		// Add each name/value pair to the array
296		for (const [name, value] of formData) {
297			pairs.push({ name, value });
298		}
299
300		// Return the array
301		return pairs;
302	}
303
304	JCslamSubscribeForm.ajax = async (form, params, dataParams = undefined) => {
305		if (form) {
306			dataParams = JCslamSubscribeForm.serializeArray(form);
307		}
308		var oldParams = params['OLD_PARAMS'];
309		for (var i in oldParams) {
310			dataParams.push({ name: 'arParams[' + i + ']', value: oldParams[i] });
311		}
312		var sessid = SLAM.message.sessid;
313		dataParams.push({name: 'sessid', value: sessid});
314		const paramsEncoded = dataParams.map(x => `${encodeURI(x.name)}=${encodeURI(x.value)}`).join('&');
315		return await fetch(params.TEMPLATE_FOLDER, {
316			method: 'POST',
317			headers: {
318				'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8',
319			},
320			body: paramsEncoded
321		})
322	}
323}

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.