PageSourceSearch

https://sophie-decor.com.ua/bitrix/mst/js/Shop.js?version=0.1

js sophie-decor.com.ua collected 2026-10-03 23:30:07 UTC 13,777 bytes, 422 lines download raw bytes

1MstBase.Shop = newClass(null, {
2	templateName : "basket",
3
4	constructor : function(options)
5	{
6		options = options || {};
7		$.extend(this, options);
8	},
9
10	AddToBasket : function(ob, elemId, priceCode)
11	{
12		if (!priceCode) priceCode = "RETAIL";
13		$.ajax({
14			context: this,
15			type: "POST",
16			dataType: "html",
17			url: "/bitrix/mst/ajax.php",
18			data: {"comp": "mst:catalog.cart.small", "action" : "addtobasket", "template" : this.templateName, "elementId" : elemId, "price" : priceCode},
19			complete :function() { window.Mst.Functions && Mst.Functions.Loader(false); },
20			beforeSend:function() { window.Mst.Functions && Mst.Functions.Loader(true); },
21			success: function(data)
22			{
23				this.OnBasketAddSuccess(data, {object: ob});
24			}
25		});
26	},
27
28	OnBasketAddSuccess : function(data, params) {},
29
30	UpdateBasket : function(ob, elemId, quantity)
31	{
32		$.ajax({
33			context: this,
34			type: "POST",
35			dataType: "html",
36			url: "/bitrix/mst/ajax.php",
37			data: {"comp": "mst:catalog.cart.small", "action" : "change", "quantity" : quantity, "template" : this.templateName, "elementId" : elemId},
38			complete :function() { Mst.Functions.Loader(false); },
39			beforeSend:function() { Mst.Functions.Loader(true); },
40			success: function(data)
41			{
42				this.OnBasketUpdateSuccess(data);
43			}
44		});
45	},
46
47	OnBasketUpdateSuccess : function(data, params) {},
48
49	DeleteFromBasket : function(ob, elemId)
50	{
51		$.ajax({
52			context: this,
53			type: "POST",
54			dataType: "html",
55			url: "/bitrix/mst/ajax.php",
56			data: {"comp": "mst:catalog.cart.small", "action" : "delete", "template" : this.templateName, "elementId" : elemId},
57			complete :function() { Mst.Functions.Loader(false); },
58			beforeSend:function() { Mst.Functions.Loader(true); },
59			success: function(data)
60			{
61				this.OnBasketDeleteSuccess(data, {object: ob});
62			}
63		});
64	},
65
66	OnBasketDeleteSuccess : function(data, params) {},
67
68	ChangeQuantity : function(ob, elemId){
69		var curVal = parseInt($(ob).val());
70		if (curVal != 0)
71		{
72			if (isNaN(curVal) || curVal < 1)
73			{
74				curVal = 1;
75			}
76			$(ob).val(curVal);
77
78			this.UpdateBasket(ob, elemId, curVal);
79		}
80		else
81		{
82			this.DeleteFromBasket(ob, elemId);
83		}
84	},
85
86	ShowBasket : function() {
87		$.ajax({
88			context: this,
89			type: "POST",
90			dataType: "html",
91			url: "/bitrix/mst/ajax.php",
92			data: {"comp": "mst:catalog.cart.small", "action" : "none", "template" : this.templateName},
93			complete :function() { Mst.Functions.Loader(false); },
94			beforeSend:function() { Mst.Functions.Loader(true); },
95			success: function(data)
96			{
97				obShop.ShowCartPopup(data);
98
99
100			}
101		});
102	},
103
104	ShowCartPopup : function(data) {
105		var options = {
106			templateID: "messageTemplate",
107			needCover: true,
108			timeOut : false,
109			posX: "center",
110			posY: "center",
111			popupId : "basketPopup",
112			data: {content: data, specialClass: "basketPopup"}
113		};
114
115		popupWindow = new Mst.Popup(options);
116		popupWindow.show();
117	},
118
119    ShowPreOrderPopup : function(data) {
120        var options = {
121            templateID: "messageTemplate",
122            needCover: true,
123            timeOut : false,
124            posX: "center",
125            posY: "center",
126            popupId : "basketPopup",
127            data: {content: data, specialClass: "preOrder"}
128        };
129
130        popupWindow = new Mst.Popup(options);
131        popupWindow.show();
132    },
133
134	AddToWishList : function(ob, elemId, priceCode, reload)
135	{
136		if (!priceCode) priceCode = "RETAIL";
137		$.ajax({
138			context: this,
139			type: "GET",
140			dataType: "html",
141			url: "/bitrix/mst/ajax.php",
142			data: {"comp": "mst:catalog.cart.small", "action" : "addtowishlist", "elementId" : elemId, "template" : "wishlist", price : priceCode},
143			complete :function() { Mst.Functions.Loader(false); },
144			beforeSend:function() { Mst.Functions.Loader(true); },
145			success: function(data)
146			{
147				this.ReplaceSmallWishlist(data);
148				this.ReplaceWishListButtonText(ob);
149			}
150		});
151	},
152
153	ReplaceSmallWishlist : function(data) {},
154	ReplaceWishListButtonText : function(ob) {},
155
156	ShowWishlistEmpty : function() {
157		var options = {
158			//afterHideHandler : function() {window.location = "/";}
159			templateID: "messageTemplate",
160			needCover: true,
161			timeOut : false,
162			posX: "center",
163			posY: "center",
164			data: {content: $( "#popupWishListEmpty" ).tmpl().html()}
165		};
166
167		popupWindow = new Mst.Popup(options);
168		popupWindow.show();
169	}
170});
171
172Mst.Shop = newClass(MstBase.Shop, {
173	WishData : null,
174	basket : null,
175
176	addToCartSelector 			: ".add2cart",	//селектор контрола добавления в корзин
176у
177	canBuyClass					: "allow-buy",	//класс, который присутствует в кнопки добавления, сигнализирующий о том, что соотв. товар можно купить
178	itemParentWithIdSelector	: ".ui_element_id", //селектор, который содержит id, соответствующее идентефикатору товара
179	idPrefLen					: 2,	//длинна префикса у id, после которого следует идентефикатор товара (весь префикс игнорируется)
180
181	removeFromCartSelector 		: ".removeItem", //селектор контрола удаления элемента из корзины
182	smallCartSelector 			: "#smallCart", //селектор маленькой корзины
183	smallWishListSelector 		: "#smallWish", //селектор маленького WishList-а
184	newWishListBtnSelector		: "#newWishListBtn",//селектор элемента, который содержит новый текст кнопки "Добавить в избранное"
185	popupCartContentSelector	: ".buy_product",
186
187	showCartSelector			: ".ui_showCart", //селектор кнопки отображения корзины
188
189	lastValidQuantity			: null,//используется для запоминания последнего корретного количества при обработке ошибок ввода
190	parent						: null,//ссылка на родительский класс
191
192	constructor : function(options)
193	{
194		parentConstructor(this, options);
195		this.parent = this.constructor.prototype;
196	},
197
198	ShowCartPopup : function(data) {
199		this.parent.ShowCartPopup.call(this, data);
200		this.lastValidQuantity = $(".cartItemCount").find("input").val();
201	},
202
203
204
205	Init : function()
206	{
207
208		var localObj = this;
209
210		$(this.addToCartSelector + "." + this.canBuyClass).live("click", function(event){
211			event.preventDefault();
212			var parent = localObj.getParentForElem(this);
213			var elID = localObj.getIdForElement(this);
214			var priceCode = parent.find(".hiddenPriceCode").val();
215			if (elID){
216				localObj.AddToBasket(this, elID, priceCode);
217			}
218		});
219
220		$(this.removeFromCartSelector).live("click", function(event){
221			event.preventDefault();
222			var elID = parseInt($(this).parent().attr("id"));
223			if (elID){
224				localObj.DeleteFromBasket(this, elID);
225			}
226		});
227
228		$(".add2wish").live("click", function(event){
229			event.preventDefault();
230			var parent = localObj.getParentForElem(this);
231			var elID = localObj.getIdForElement(this);
232
233			// var parent = $(this).closest(".ui_element_id");
234			// var elID = parseInt(parent.attr("id").substring(2));
235
236			var priceCode = parent.find(".hiddenPriceCode").val();
237			if (elID){
238				localObj.AddToWishList(this, elID, priceCode);
239			}
240		});
241
242	/* 	$(".add2wish.reload").live("click", function(event){
243			event.preventDefault();
244			var parent = $(this).closest(".ui_element_id");
245			var elID = parseInt(parent.attr("id").substring(2));
246			var priceCode = parent.find(".hiddenPriceCode").val();
247			if (elID){
248				localObj.AddToWishList(this, elID, priceCode, true);
249			}
250		}); */
251
252		$(".cartItemCount").find("input").live("blur", function(event){
253			event.preventDefault();
254			if (this.value.match(/^[^1-9]/))
255			{
256				if (localObj.lastValidQuantity)
257				{
258					this.value = localObj.lastValidQuantity;
259				}
260				return;
261			}
262			var elID = parseInt($(this).parent().attr("id"));
263			if (elID){
264				localObj.ChangeQuantity(this, elID);
265			}
266			localObj.lastValidQuantity = this.value
267		});
268
269		$(".closeBtn").live("click", function(){
270			popupWindow.hide();
271		})
272        $('.popupCover').live('click', function() {
273           popupWindow.hide(); 
274        });
275
276		$(".showCart").live("click", function(event){
277			event.preventDefault();
278			localObj.ShowBasket();
279		});
280
281		$(this.showCartSelector).live("click", function(e) {
282			e.preventDefault();
283			localObj.ShowBasket();
284		});
285	},
286
287	getIdForElement : function (elem)
288	{
289		return this.getParentForElem(elem).attr("id").substr(this.idPrefLen);
290	},
291
292	getParentForElem : function(elem)
293	{
294		return $(elem).closest(this.itemParentWithIdSelector);
295	},
296
297	OnBasketAddSuccess : function(data, params) {
298		$(params.object).text(obMessage.InCart);
299		obShop.ShowCartPopup(data);
300
301		this.ReplaceSmallBasket($("#cartReplacement").html());
302	},
303
304	OnBasketUpdateSuccess : function(data, params) {
305		$("#jsPopup").find(this.popupCartContentSelector).html(data);
306		this.ReplaceSmallBasket($("#cartReplacement").html());
307	},
308
309	OnBasketDeleteSuccess : function(data, params) {
310		var btn = $("#id" + parseInt($(params.object).attr("id")) ).find(".add2cart");
311		if (btn.length) {
312			btn.text(obMessage.Buy);
313		}
314		$("#jsPopup").find(this.popupCartContentSelector).html(data);
315		this.ReplaceSmallBasket($("#cartReplacement").html());
316	},
317
318	ReplaceSmallBasket : function(data)
319	{
320		$(this.smallCartSelector).html(data);
321	},
322
323	ReplaceSmallWishlist : function(data)
324	{
325		$(this.smallWishListSelector).replaceWith(data);
326	},
327
328	ReplaceWishListButtonText : function(ob)
329	{
330		$(ob).text($(this.newWishListBtnSelector).text());
331		$(this.newWishListBtnSelector).empty();
332	}
333
334});
335
336/** Так как некоторые классы не испоьзуют опции (не требуют повторной инициализации), создаем их глобаÐ
336»ÑŒÐ½Ð¾ */
337var obShop = new Mst.Shop();
338
339Mst.CompareList = {
340
341	elementClass 		: "ui_element_id", //DOM-элемент этого класса должен содержать аттрибут id, соответствующий идентефикатору элемента каталога
342	btnClass 			: "ui_compare-btn", //класс DOM-элемента, на который вешается обработчик по добавлению/удалению из списка для сравнения
343	btnRemoveClass		: "ui_compare-remove", //класс, который содержится у кнопки удаления из списка сравнения
344	compareBlockId		: "ui_compare-small", // id DOM-элемента, который содержит список элементов в сравнении
345	newBtnContainerId	: "new-btn", // в ответе на AJAX запрос удаления/добавления будет искатся элемент с заданным атрибутом, его содержимым будет заменена кнопка, по которой был отправлен запрос на добавление/удаление
346	compareMsgClass		: "compare-btn-msg", //класс DOM-элемента, содержащий текст сообщения об успешном удалении/добавлении
347
348
349	addToListHandler : function(eventSender)
350	{
351		//@todo обработку ошибок, когда id не найдено
352		id = parseInt($(eventSender).closest("." + this.elementClass).attr("id").substring(2))
353
354		/** если кнопка имеет класс, отвечающей кнопке удаления, отправляем запрос на удаление, иначе - на добавление */
355		action = $(eventSender).hasClass(this.btnRemoveClass) ? "RemoveFromList" : "AddToList";
356		thisOb = this
357		$.ajax({
358			context : this,
359			type: "GET",
360			url: "/bitrix/mst/ajax.php",
361			data: {"comp": "mst:catalog.compare", "template" : "small", "action" : action, "id": id},
362			complete :function() { Mst.Functions.Loader(false); },
363			beforeSend:function() { Mst.Functions.Loader(true); },
364			success: function(data){
365				/** очищаем старые сообщение об успешном удалении/добавлении */
366				$("." + this.compareMsgClass).empty()
367				/** вставляем новый код блока с кратким списком */
368				$("#" + this.compareBlockId).replaceWith(data)
369				/** получаем новый код кнопки добавления/удаления */
370				newBtnHtml = $("#new-btn").html()
371				/** кнопка, вызвавшая этот обработчик заменяется на новый полученный код кнопки */
372				$("#id"+id+" ."+this.btnClass).replaceWith(newBtnHtml)
373				/** элемент, содержащий код новой кнопки удаляется */
374				$("#" + this.newBtnContainerId).empty()
375			}
376		});
377	},
378
379	Init : function()
380	{
381		$("." + Mst.CompareList.btnClass).live("click", function(e)
382		{
383			e.preventDefault();
384			Mst.CompareList.addToListHandler(this)
385		})
386	}
387}
388
389Mst.CurrencySelector = {
390
391	selectorId : "currency-select",
392
393	changeCurrencyHandler : function()
394	{
395		var newCurr = $("#" + this.selectorId).val()
396		$.ajax({
397			type: "GET",
398			url: "/bitrix/mst/ajax.php",
399			data: {"comp": "mst:currency.selector", "template" : ".default", "newCurr": newCurr},
400			complete :function() { Mst.Functions.Loader(false); },
401			beforeSend:function() { Mst.Functions.Loader(true); },
402			success: function(data){
403				location.reload()
404			}
405		});
406
407	},
408
409	Init : function()
410	{
411		var thisOb = this
412		$("#" + this.selectorId).live("change", function(){thisOb.changeCurrencyHandler()})
413	}
414
415}
416
417
418$(document).ready(function(){
419	obShop.Init();
420	Mst.CompareList.Init()
421	Mst.CurrencySelector.Init()
422});

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.