PageSourceSearch

https://knigarekordovrossii.ru/bitrix/templates/universe_s1/compon…atalog.product.subscribe/.default/script.js

js knigarekordovrossii.ru collected 2026-10-02 09:56:41 UTC 19,187 bytes, 673 lines download raw bytes

1(function (window) {
2
3	if (!!window.JCCatalogProductSubscribe)
4	{
5		return;
6	}
7
8	var subscribeButton = function(params)
9	{
10		subscribeButton.superclass.constructor.apply(this, arguments);
11		this.nameNode = BX.create('span', {
12			props : { id : this.id },
13			style: typeof(params.style) === 'object' ? params.style : {},
14			text: params.text
15		});
16		this.buttonNode = BX.create('span', {
17			attrs: { className: params.className },
18			style: { marginBottom: '0', borderBottom: '0 none transparent' },
19			children: [this.nameNode],
20			events : this.contextEvents
21		});
22		if (BX.browser.IsIE())
23		{
24			this.buttonNode.setAttribute("hideFocus", "hidefocus");
25		}
26	};
27	BX.extend(subscribeButton, BX.PopupWindowButton);
28
29	window.JCCatalogProductSubscribe = function(params)
30	{
31		this.buttonId = params.buttonId;
32		this.buttonClass = params.buttonClass;
33		this.jsObject = params.jsObject;
34		this.ajaxUrl = '/bitrix/components/bitrix/catalog.product.subscribe/ajax.php';
35		this.alreadySubscribed = params.alreadySubscribed;
36		this.listIdAlreadySubscribed = params.listIdAlreadySubscribed;
37		this.urlListSubscriptions = params.urlListSubscriptions;
38		this.listOldItemId = {};
39		this.landingId = params.landingId;
40
41		this.elemButtonSubscribe = null;
42		this.elemPopupWin = null;
43		this.defaultButtonClass = 'bx-catalog-subscribe-button';
44
45        this.iconUse = params.iconUse;
46        this.textShow = params.textShow;
47
48		this._elemButtonSubscribeClickHandler = BX.delegate(this.subscribe, this);
49		this._elemHiddenClickHandler = BX.delegate(this.checkSubscribe, this);
50
51		BX.ready(BX.delegate(this.init,this));
52	};
53
54	window.JCCatalogProductSubscribe.prototype.init = function()
55	{
56		if (!!this.buttonId)
57		{
58			this.elemButtonSubscribe = BX(this.buttonId);
59			this.elemHiddenSubscribe = BX(this.buttonId+'_hidden');
60		}
61
62		if (!!this.elemButtonSubscribe)
63		{
64			BX.bind(this.elemButtonSubscribe, 'click', this._elemButtonSubscribeClickHandler);
65		}
66
67		if (!!this.elemHiddenSubscribe)
68		{
69			BX.bind(this.elemHiddenSubscribe, 'click', this._elemHiddenClickHandler);
70		}
71
72		this.setButton(this.alreadySubscribed);
73		this.setIdAlreadySubscribed(this.listIdAlreadySubscribed);
74	};
75
76	window.JCCatalogProductSubscribe.prototype.checkSubscribe = function()
77	{
78		if(!this.elemHiddenSubscribe || !this.elemButtonSubscribe) return;
79
80		if(this.listOldItemId.hasOwnProperty(this.elemButtonSubscribe.dataset.item))
81		{
82			this.setButton(true);
83		}
84		else
85		{
86			BX.ajax({
87				method: 'POST',
88				dataType: 'json',
89				url: this.ajaxUrl,
90				data: {
91					sessid: BX.bitrix_sessid(),
92					checkSubscribe: 'Y',
93					itemId: this.elemButtonSubscribe.dataset.item
94				},
95				onsuccess: BX.delegate(function (result) {
96					if(result.subscribe)
97					{
98						this.setButton(true);
99						this.listOldItemId[this.elemButtonSubscribe.dataset.item] = true;
100					}
101					else
102					{
103						this.setButton(false);
104					}
105				}, this)
106			});
107		}
108	};
109
110	window.JCCatalogProductSubscribe.prototype.subscribe = function()
111	{
112		this.elemButtonSubscribe = BX.proxy_context;
113		if(!this.elemButtonSubscribe) return false;
114
115		BX.ajax({
116			method: 'POST',
117			dataType: 'json',
118			url: this.ajaxUrl,
119			data: {
120				sessid: BX.bitrix_sessid(),
121				subscribe: 'Y',
122				itemId: this.elemButtonSubscribe.dataset.item,
123				siteId: BX.message('SITE_ID'),
124				landingId: this.landingId
125			},
126			onsuccess: BX.delegate(function (result) {
127				if(result.success)
128				{
129					this.createSuccessPopup(result);
130					this.setButton(true);
131					this.listOldItemId[this.elemButtonSubscribe.dataset.item] = true;
132				}
133				else if(result.contactFormSubmit)
134				{
135					this.initPopupWindow();
136					this.elemPopupWin.setTitleBar(BX.message('CPST_SUBSCRIBE_POPUP_TITLE'));
137					var form = this.createContentForPopup(result);
138					this.elemPopupWin.setContent(form);
139					this.elemPopupWin.setButtons([
140						new subscribeButton({
141							text: BX.message('CPST_SUBSCRIBE_BUTTON_NAME'),
142							className : 'intec-ui intec-ui-control-button intec-ui-scheme-current',
143							events: {
144								click : BX.delegate(function() {
145									if(!this.validateContactField(result.contactTypeData))
146									{
147										return false;
148									}
149									BX.ajax.submitAjax(form, {
150										method : 'POST',
151										url: this.ajaxUrl,
152										processData : true,
153										onsuccess: BX.delegate(function (resultForm) {
154											resultForm = BX.parseJSON(resultForm, {});
155											if(resultForm.success)
156											{
157												this.createSuccessPopup(resultForm);
158												this.setButton(true);
159												this.listOldItemId[this.elemButtonSubscribe.dataset.item] = true;
160											}
161											else if(resultForm.error)
162											{
163												if(resultForm.hasOwnProperty('setButton'))
164												{
165													this.listOldItemId[this.elemButtonSubscribe.dataset.item] = true;
166													this.setButton(true);
167												}
168												var errorMessage = resultForm.message;
169												if(resultForm.hasOwnProperty('typeName'))
170												{
171													errorMessage = resultForm.message.replace('USER_CONTACT',
172														resultForm.typeName);
173												}
174												BX('bx-catalog-subscribe-form-notify').style.color = 'red';
175												BX('bx-catalog-subscribe-form-notify').innerHTML = errorMessage;
176											}
177										}, this)
178									});
179								}, this)
180							}
181						}),
182						new subscribeButton({
183							text : BX.message('CPST_SUBSCRIBE_BUTTON_CLOSE'),
184							className : 'intec-ui intec-ui-control-button intec-ui-scheme-current',
185							events : {
186								click : BX.delegate(function() {
187									this.elemPopupWin.destroy();
188								}, this)
189							}
190						})
191					]);
192					this.elemPopupWin.show();
193				}
194				else if(result.error)
195				{
196					if(result.hasOwnProperty('setButton'))
197					{
198						this.listOldItemId[this.elemButtonSubscribe.dataset.item] = true;
199						this.setButton(true);
200					}
201					this.showWindowWithAnswer({status: 'error', message: result.message});
202				}
203			}, this)
204		});
205	};
206
207	window.JCCatalogProductSubscribe.prototype.validateContactField = function(contactTypeData)
208	{
209		var inputFields = BX.findChildren(BX('bx-catalog-subscribe-form'),
210			{'tag': 'input', 'attribute': {id: 'userContact'}}, true);
211		if(!inputFields.length || typeof contactTypeData !== 'object')
212		{
213			BX('bx-catalog-subscribe-form-notify').style.color = 'red';
214			BX('bx-catalog-subscribe-form-notify').innerHTML = BX.message('CPST_SUBSCRIBE_VALIDATE_UNKNOW_ERROR');
215			return false;
216		}
217
218		var contactTypeId, contactValue, useContact, errors = [], useContactErrors = [];
219		for(var k = 0; k < inputFields.length; k++)
220		{
221			contactTypeId = inputFields[k].getAttribute('data-id');
222			contactValue = inputFields[k].value;
223			useContact = BX('bx-contact-use-'+contactTypeId);
224			if(useContact && useContact.value == 'N')
225			{
226				useContactErrors.push(true);
227				continue;
228			}
229			if(!contactValue.length)
230			{
231				errors.push(BX.message('CPST_SUBSCRIBE_VALIDATE_ERROR_EMPTY_FIELD').replace(
232					'#FIELD#', contactTypeData[contactTypeId].contactLable));
233			}
234		}
235
236		if(inputFields.length == useContactErrors.length)
237		{
238			BX('bx-catalog-subscribe-form-notify').style.color = 'red';
239			BX('bx-catalog-subscribe-form-notify').innerHTML = BX.message('CPST_SUBSCRIBE_VALIDATE_ERROR');
240			return false;
241		}
242
243		if(errors.length)
244		{
245			BX('bx-catalog-subscribe-form-notify').style.color = 'red';
246			for(var i = 0; i < errors.length; i++)
247			{
248				BX('bx-catalog-subscribe-form-notify').innerHTML = errors[i];
249			}
250			return false;
251		}
252
253		return true;
254	};
255
256	window.JCCatalogProductSubscribe.prototype.reloadCaptcha = function()
257	{
258		BX.ajax.get(this.ajaxUrl+'?reloadCaptcha=Y', '', function(captchaCode) {
259			BX('captcha_sid').value = captchaCode;
260			BX('captcha_img').src = '/bitrix/tools/captcha.php?captcha_sid='+captchaCode+'';
261		});
262	};
263
264	window.JCCatalogProductSubscribe.prototype.createContentForPopup = function(responseData)
265	{
266		if(!responseData.hasOwnProperty('contactTypeData'))
267		{
268			return null;
269		}
270
271		var contactTypeData = responseData.contactTypeData, contactCount = Object.keys(contactTypeData).length,
272			styleInputForm = '', manyContact = 'N', content = document.createDocumentFragment();
273
274		if(contactCount > 1)
275		{
276			manyContact = 'Y';
277			styleInputForm = 'display:none;';
278			content.appendChild(BX.create('p', {
279				text: BX.message('CPST_SUBSCRIBE_MANY_CONTACT_NOTIFY')
280			}));
281		}
282
283		content.appendChild(BX.create('p', {
284			props: {id: 'bx-catalog-subscribe-form-notify'}
285		}));
286
287		for(var k in contactTypeData)
288		{
289			if(contactCount > 1)
290			{
291				content.appendChild(BX.create('div', {
292					props: {
293						className: 'bx-catalog-subscribe-form-container'
294					},
295					children: [
296						BX.create('div', {
297							props: {
298								className: 'checkbox'
299							},
300							children: [
301								BX.create('lable', {
302									props: {
303										className: 'bx-filter-param-label'
304									},
305									attrs: {
306										onclick: this.jsObject+'.selectContactType('+k+', event);'
307									},
308									children: [
309										BX.create('input', {
310											props: {
311												type: 'hidden',
312												id: 'bx-contact-use-'+k,
313												name: 'contact['+k+'][use]',
314												value: 'N'
315											}
316										}),
317										BX.create('input', {
318											props: {
319												id: 'bx-contact-checkbox-'+k,
320												type: 'checkbox'
321											}
322										}),
323										BX.create('span', {
324											props: {
325												className: 'bx-filter-param-text'
326											},
327											text: contactTypeData[k].contactLable
328										})
329									]
330								})
331							]
332						})
333					]
334				}));
335			}
336			content.appendChild(BX.create('div', {
337				props: {
338					id: 'bx-catalog-subscribe-form-container-'+k,
339					className: 'bx-catalog-subscribe-form-container',
340					style: styleInputForm
341				},
342				children: [
343					BX.create('div', {
344						props: {
345							className: 'bx-catalog-subscribe-form-container-label'
346						},
347						text: BX.message('CPST_SUBSCRIBE_LABLE_CONTACT_INPUT').replace(
348							'#CONTACT#', contactTypeData[k].contactLable)
349					}),
350					BX.create('div', {
351						props: {
352							className: 'bx-catalog-subscribe-form-container-input'
353						},
354						children: [
355							BX.create('input', {
356								props: {
357									id: 'userContact',
358									className: 'inputtext intec-ui intec-ui-control-input intec-ui-mod-block intec-ui-mod-round-3',
359									type: 'text',
360									name: 'contact['+k+'][user]'
361								},
362								attrs: {'data-id': k}
363							})
364						]
365					})
366				]
367			}));
368		}
369		if(responseData.hasOwnProperty('captchaCode'))
370		{
371			content.appendChild(BX.create('div', {
372				props: {
373					className: 'bx-catalog-subscribe-form-container'
374				},
375				children: [
376					BX.create('span', {props: {className: 'bx-catalog-subscribe-form-star-required'}, text: '*'}),
377					BX.message('CPST_ENTER_WORD_PICTURE'),
378					BX.create('div', {
379						props: {className: 'bx-captcha'},
380						children: [
381							BX.create('input', {
382								props: {
383									type: 'hidden',
384									id: 'captcha_sid',
385									name: 'captcha_sid',
386									value: responseData.captchaCode
387								}
388							}),
389							BX.create('img', {
390								props: {
391									id: 'captcha_img',
392									src: '/bitrix/tools/captcha.php?captcha_sid='+responseData.captchaCode+''
393								},
394								attrs: {
395									width: '180',
396									height: '40',
397									alt: 'captcha',
398									onclick: this.jsObject+'.reloadCaptcha();'
399								}
400							})
401						]
402					}),
403					BX.create('div', {
404						props: {className: 'bx-catalog-subscribe-form-container-input'},
405						children: [
406							BX.create('input', {
407								props: {
408									id: 'captcha_word',
409									className: '',
410									type: 'text',
411									name: 'captcha_word'
412								},
413								attrs: {maxlength: '50'}
414							})
415						]
416					})
417				]
418			}));
419		}
420		var form = BX.create('form', {
421			props: {
422				id: 'bx-catalog-subscribe-form'
423			},
424			children: [
425				BX.create('input', {
426					props: {
427						type: 'hidden',
428						name: 'manyContact',
429						value: manyContact
430					}
431				}),
432				BX.create('input', {
433					props: {
434						type: 'hidden',
435						name: 'sessid',
436						value: BX.bitrix_sessid()
437					}
438				}),
439				BX.create('input', {
440					props: {
441						type: 'hidden',
442						name: 'itemId',
443						value: this.elemButtonSubscribe.dataset.item
444					}
445				}),
446				BX.create('input', {
447					props: {
448						type: 'hidden',
449						name: 'landingId',
450						value: this.landingId
451					}
452				}),
453				BX.create('input', {
454					props: {
455						type: 'hidden',
456						name: 'siteId',
457						value: BX.message('SITE_ID')
458					}
459				}),
460				BX.create('input', {
461					props: {
462						type: 'hidden',
463						name: 'contactFormSubmit',
464						value: 'Y'
465					}
466				})
467			]
468		});
469
470		form.appendChild(content);
471
472		return form;
473	};
474
475	window.JCCatalogProductSubscribe.prototype.selectContactType = function(contactTypeId, event)
476	{
477		var contactInput = BX('bx-catalog-subscribe-form-container-'+contactTypeId), visibility = '',
478			checkboxInput = BX('bx-contact-checkbox-'+contactTypeId);
479		if(!contactInput)
480		{
481			return false;
482		}
483
484		if(checkboxInput != event.target)
485		{
486			if(checkboxInput.checked)
487			{
488				checkboxInput.checked = false;
489			}
490			else
491			{
492				checkboxInput.checked = true;
493			}
494		}
495
496		if (contactInput.currentStyle)
497		{
498			visibility = contactInput.currentStyle.display;
499		}
500		else if (window.getComputedStyle)
501		{
502			var computedStyle = window.getComputedStyle(contactInput, null);
503			visibility = computedStyle.getPropertyValue('display');
504		}
505
506		if(visibility === 'none')
507		{
508			BX('bx-contact-use-'+contactTypeId).value = 'Y';
509			BX.style(contactInput, 'display', '');
510		}
511		else
512		{
513			BX('bx-contact-use-'+contactTypeId).value = 'N';
514			BX.style(contactInput, 'display', 'none');
515		}
516	};
517
518	window.JCCatalogProductSubscribe.prototype.createSuccessPopup = function(result)
519	{
520		this.initPopupWindow();
521		this.elemPopupWin.setTitleBar(BX.message('CPST_SUBSCRIBE_POPUP_TITLE'));
522		var content = BX.create('div', {
523			props:{
524				className: 'bx-catalog-popup-content'
525			},
526			children: [
527				BX.create('p', {
528					props: {
529						className: 'bx-catalog-popup-message'
530					},
531					text: result.message
532				})
533			]
534		});
535		this.elemPopupWin.setContent(content);
536		this.elemPopupWin.setButtons([
537			new subscribeButton({
538				text : BX.message('CPST_SUBSCRIBE_BUTTON_CLOSE'),
539				className : 'intec-ui intec-ui-control-button intec-ui-scheme-current',
540				events : {
541					click : BX.delegate(function() {
542						this.elemPopupWin.destroy();
543					}, this)
544				}
545			})
546		]);
547		this.elemPopupWin.show();
548	};
549
550	window.JCCatalogProductSubscribe.prototype.initPopupWindow = function()
551	{
552		this.elemPopupWin = BX.PopupWindowManager.create('CatalogSubscribe_'+this.buttonId, null, {
553			autoHide: false,
554			offsetLeft: 0,
555			offsetTop: 0,
556			overlay : true,
557			closeByEsc: true,
558			titleBar: true,
559			closeIcon: true,
560			contentColor: 'white',
561			className: 'popup-window-subscribe'
562		});
563	};
564
565	window.JCCatalogProductSubscribe.prototype.setButton = function(statusSubscription)
566	{
567		this.alreadySubscribed = Boolean(statusSubscription);
568		if(this.alreadySubscribed)
569		{
570			this.elemButtonSubscribe.className = this.buttonClass + ' ' + this.defaultButtonClass + ' disabled';
571			if (this.iconUse && this.textShow) {
572                this.elemButtonSubscribe.innerHTML = '<i class="far fa-bell"></i>' + '<span>' + BX.message('CPST_TITLE_ALREADY_SUBSCRIBED') + '</span>';
573			} else if (this.iconUse && !this.textShow) {
574                this.elemButtonSubscribe.innerHTML = '<i class="far fa-bell"></i>';
575			} else {
576                this.elemButtonSubscribe.innerHTML = '<span>' + BX.message('CPST_TITLE_ALREADY_SUBSCRIBED') + '</span>';
577			}
578			BX.unbind(this.elemButtonSubscribe, 'click', this._elemButtonSubscribeClickHandler);
579		}
580		else
581		{
582			this.elemButtonSubscribe.className = this.buttonClass + ' ' + this.defaultButtonClass;
583            if (this.iconUse && this.textShow) {
584                this.elemButtonSubscribe.innerHTML = '<i class="far fa-bell"></i>' + '<span>' + BX.message('CPST_SUBSCRIBE_BUTTON_NAME') + '</span>';
585            } else if (this.iconUse && !this.textShow) {
586                this.elemButtonSubscribe.innerHTML = '<i class="far fa-bell"></i>';
587            } else {
588                this.elemButtonSubscribe.innerHTML = '<span>' + BX.message('CPST_SUBSCRIBE_BUTTON_NAME') + '</span>';
589            }
590			BX.bind(this.elemButtonSubscribe, 'click', this._elemButtonSubscribeClickHandler);
591		}
592	};
593
594	window.JCCatalogProductSubscribe.prototype.setIdAlreadySubscribed = function(listIdAlreadySubscribed)
595	{
596		if (BX.type.isPlainObject(listIdAlreadySubscribed))
597		{
598			this.listOldItemId = listIdAlreadySubscribed;
599		}
600	};
601
602	window.JCCatalogProductSubscribe.prototype.showWindowWithAnswer = function(answer)
603	{
604		answer = answer || {};
605		if (!answer.message) {
606			if (answer.status == 'success') {
607				answer.message = BX.message('CPST_STATUS_SUCCESS');
608			} else {
609				answer.message = BX.message('CPST_STATUS_ERROR');
610			}
611		}
612		var messageBox = BX.create('div', {
613			props: {
614				className: 'bx-catalog-subscribe-alert'
615			},
616			children: [
617				BX.create('span', {
618					props: {
619						className: 'bx-catalog-subscribe-aligner'
620					}
621				}),
622				BX.create('span', {
623					props: {
624						className: 'bx-catalog-subscribe-alert-text'
625					},
626					text: answer.message
627				}),
628				BX.create('div', {
629					props: {
630						className: 'bx-catalog-subscribe-alert-footer'
631					}
632				})
633			]
634		});
635		var currentPopup = BX.PopupWindowManager.getCurrentPopup();
636		if(currentPopup) {
637			currentPopup.destroy();
638		}
639		var idTimeout = setTimeout(function () {
640			var w = BX.PopupWindowManager.getCurrentPopup();
641			if (!w || w.uniquePopupId != 'bx-catalog-subscribe-status-action') {
642				return;
643			}
644			w.close();
645			w.destroy();
646		}, 3500);
647		var popupConfirm = BX.PopupWindowManager.create('bx-catalog-subscribe-status-action', null, {
648			content: messageBox,
649			onPopupClose: function () {
650				this.destroy();
651				clearTimeout(idTimeout);
652			},
653			autoHide: true,
654			zIndex: 2000,
655			className: 'bx-catalog-subscribe-alert-popup'
656		});
657		popupConfirm.show();
658		BX('bx-catalog-subscribe-status-action').onmouseover = function (e) {
659			clearTimeout(idTimeout);
660		};
661		BX('bx-catalog-subscribe-status-action').onmouseout = function (e) {
662			idTimeout = setTimeout(function () {
663				var w = BX.PopupWindowManager.getCurrentPopup();
664				if (!w || w.uniquePopupId != 'bx-catalog-subscribe-status-action') {
665					return;
666				}
667				w.close();
668				w.destroy();
669			}, 3500);
670		};
671	};
672
673})(window);

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.