PageSourceSearch

https://okoptica.ru/bitrix/components/bitrix/sale.gift.main.products/templates/bootstrap_v4/script.js

js okoptica.ru collected 2026-10-07 16:34:43 UTC 3,763 bytes, 160 lines download raw bytes

1BX.namespace("BX.Sale");
2BX.Sale.GiftMainProductsClass = (function ()
3{
4	var GiftMainProductsClass = function (parameters)
5	{
6		this.ajaxUrl = '/bitrix/components/bitrix/sale.gift.main.products/ajax.php';
7		this.contextAjaxData = parameters.contextAjaxData || {};
8		this.mainProductState = parameters.mainProductState || null;
9		this.injectId = parameters.injectId || null;
10		this.isGift = !!parameters.isGift;
11		this.productId = parameters.productId;
12		this.offerId = parameters.offerId;
13		this.offers = parameters.offers || [];
14
15		this.setEvents();
16
17		//detect #as_gift
18		if(document.location.hash.match(/as_gift/g))
19		{
20			if(this.isGift)
21			{
22				this.enableGift();
23			}
24			else
25			{
26				this.raiseNonGiftEvent();
27			}
28		}
29
30		BX.bindDelegate(BX(this.injectId), "click", {tagName: 'a'}, BX.proxy(this.clickNavLink, this));
31	};
32
33	GiftMainProductsClass.prototype.clickNavLink = function(e)
34	{
35		if(this.onPageNavigationByLink(BX.proxy_context))
36		{
37			return BX.PreventDefault(e);
38		}
39	};
40
41	GiftMainProductsClass.prototype.setEvents = function()
42	{
43		BX.addCustomEvent('onCatalogStoreProductChange', BX.proxy(this.onCatalogStoreProductChange, this));
44		BX.addCustomEvent('onAddToBasketMainProduct', BX.proxy(this.onAddToBasketMainProduct, this));
45	};
46
47	GiftMainProductsClass.prototype.unsubscribeEvents = function()
48	{
49		BX.removeCustomEvent('onCatalogStoreProductChange', BX.proxy(this.onCatalogStoreProductChange, this));
50	};
51
52	GiftMainProductsClass.prototype.onAddToBasketMainProduct = function(productObject)
53	{
54		this.enableGift();
55	};
56
57	GiftMainProductsClass.prototype.onCatalogStoreProductChange = function(offerId)
58	{
59		if(offerId == this.offerId)
60		{
61			return;
62		}
63		BX.ajax({
64			url: this.ajaxUrl,
65			method: 'POST',
66			data: BX.merge(this.contextAjaxData, {offerId: offerId, mainProductState: this.mainProductState, SITE_ID: BX.message('SITE_ID')}),
67			dataType: 'html',
68			processData: false,
69			start: true,
70			onsuccess: BX.delegate(function (html) {
71				this.offerId = offerId;
72				var ob = BX.processHTML(html);
73				if(!ob.HTML)
74				{
75					if(document.location.hash.match(/as_gift/g))
76					{
77						//raise event from previous state. It's trick.
78						if(this.isGift)
79						{
80							this.raiseGiftEvent();
81						}
82						else
83						{
84							this.raiseNonGiftEvent();
85						}
86					}
87
88					return;
89				}
90				this.unsubscribeEvents();
91
92				BX(this.injectId).innerHTML = ob.HTML;
93				BX.ajax.processScripts(ob.SCRIPT);
94			}, this)
95		});
96
97	};
98
99	GiftMainProductsClass.prototype.onPageNavigationByLink = function(link)
100	{
101		var isValidNavigationLink = BX.delegate(function(link)
102		{
103			if(!BX.type.isElementNode(link) || !link.href)
104			{
105				return false;
106			}
107			if(link.href.indexOf(this.ajaxUrl) >= 0)
108			{
109				return true;
110			}
111			return link.href.indexOf('PAGEN_') !== -1;
112		}, this);
113
114		if(!isValidNavigationLink(link))
115		{
116			return false;
117		}
118
119		BX.ajax({
120			url: link.href,
121			method: 'POST',
122			data: BX.merge(this.contextAjaxData, {SITE_ID: BX.message('SITE_ID')}),
123			dataType: 'html',
124			processData: false,
125			start: true,
126			onsuccess: BX.delegate(function (html) {
127				var ob = BX.processHTML(html);
128				if(!ob.HTML)
129				{
130					return;
131				}
132				this.unsubscribeEvents();
133
134				BX(this.injectId).innerHTML = ob.HTML;
135				BX.ajax.processScripts(ob.SCRIPT);
136			}, this)
137		});
138
139		return true;
140	};
141
142	GiftMainProductsClass.prototype.enableGift = function()
143	{
144		this.isGift = true;
145		this.raiseGiftEvent();
146	};
147
148	GiftMainProductsClass.prototype.raiseGiftEvent = function()
149	{
150		BX.onCustomEvent('onSaleProductIsGift', [this.productId, this.offerId]);
151	};
152
153	GiftMainProductsClass.prototype.raiseNonGiftEvent = function()
154	{
155		BX.onCustomEvent('onSaleProductIsNotGift', [this.productId, this.offerId]);
156	};
157
158	return GiftMainProductsClass;
159})();
160

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.