PageSourceSearch

https://www.joomflix.com/components/com_virtuemart/assets/js/vmprices.js?vmver=18c01d63

js joomflix.com collected 2026-10-01 06:05:23 UTC 9,700 bytes, 333 lines download raw bytes

1if (typeof Virtuemart === "undefined")
2	var Virtuemart = {};
3
4Virtuemart.stopSendtocart = false;
5
6Virtuemart.setproducttype = function(form, id) {
7	form.view = null;
8	var datas = form.serialize();
9
10	var runs = 0,
11		maxruns = 20;
12	var container = form.closest('[data-vm="product-container"]');
13
14	if (container.length == 0) {
15		container = form;
16		while (!container.hasClass('product-container') && !container.hasClass('productdetails') && !container.hasClass('vm-product-details-container') && runs <= maxruns) {
17			container = container.parent();
18			runs++;
19		}
20		if (runs > maxruns) {
21			console.log('setproducttype: Could not find parent container product-container nor product-field-display');
22			return false;
23		}
24	}
25
26
27	var prices = container.find('[data-vm="product-prices"],.product-price');
28	if (0 == prices.length) {
29		prices = jQuery("#productPrice" + id);
30	}
31	datas = datas.replace("&view=cart", "");
32	datas = datas.replace("&task", "recalculate");
33
34	prices.fadeTo("fast", 0.75);
35	jQuery.ajax({
36		type: "POST",
37		cache: false,
38		dataType: "json",
39		url: Virtuemart.vmSiteurl + "index.php?option=com_virtuemart&view=productdetails&task=recalculate&format=json&nosef=1" + Virtuemart.vmLang,
40		data: datas
41	}).done(
42		function(data, textStatus) {
43			prices.fadeTo("fast", 1);
44			// Remove previous messages generated by this AJAX call:
45			jQuery("#system-message-container #system-message div.vmprices-message").remove();
46			// refresh price
47			for (var key in data) {
48				var value = data[key];
49				// console.log('my datas',key,value);
50				if (key == 'messages') {
51					// Extract the messages from the returned string, add the vmprices-message class (so the next ajax call
52					// can remove them again) and then move the messages to the original message container.
53					// Things are complicated by the fact that no #system-message element exists if no messages were printed so far
54					var newmessages = jQuery(data[key]).find("div.alert").addClass("vmprices-message");
55					if (!jQuery("#system-message-container #system-message").length && newmessages.length) {
56						jQuery("#system-message-container").append("<div id='system-message'></div>");
57					}
58					newmessages.appendTo("#system-message-container #system-message");
59				} else { // prices
60					if (value != 0) prices.find("span.Price" + key).show().html(value);
61					else prices.find(".Price" + key).html(0).hide();
62				}
63			}
64		}
65	);
66
67	return false; // prevent reload
68}
69
70Virtuemart.productUpdate = function() {
71	// This Event Gets Fired As Soon As The New Product
72	// Was Added To The Cart
73	// This Way Third Party Developer Can Include Their Own
74	// Add To Cart Module And Listen To The Event: "updateVirtueMartCartModule"
75	jQuery('body').trigger('updateVirtueMartCartModule');
76}
77
78Virtuemart.eventsetproducttype = function(event) {
79	Virtuemart.setproducttype(event.data.cart, event.data.virtuemart_product_id);
80}
81
82Virtuemart.sendtocart = function(form) {
83	if (Virtuemart.addtocart_popup == 1) {
84		Virtuemart.cartEffect(form);
85	} else {
86		form.append('<input type="hidden" name="task" value="add" />');
87		form.submit();
88	}
89}
90
91Virtuemart.cartEffect = function(form) {
92
93	var dat = form.serialize();
94
95	if (usefancy) {
96		jQuery.fancybox.showActivity();
97	}
98
99	jQuery.ajax({
100		type: "POST",
101		cache: false,
102		dataType: "json",
103		timeout: "20000",
104		url: Virtuemart.vmSiteurl + "index.php?option=com_virtuemart&nosef=1&view=cart&task=addJS&format=json" + Virtuemart.vmLang + window.Itemid,
105		data: dat
106	}).done(
107
108		function(datas, textStatus) {
109
110			if (datas.stat == 1) {
111				var txt = datas.msg;
112			} else if (datas.stat == 2) {
113				var txt = datas.msg;
114			} else {
115				var txt = "<H4>" + Virtuemart.vmCartError + "</H4>" + datas.msg;
116			}
117			if (usefancy) {
118				jQuery.fancybox({
119					"titlePosition": "inside",
120					"transitionIn": "fade",
121					"transitionOut": "fade",
122					"changeFade": "fast",
123					"type": "html",
124					"autoCenter": true,
125					"showCloseButton": false,
126					"closeClick": false,
127					"content": txt/*,
128					"autodimension"	: true,
129					"onComplete"	: function () {
130						setTimeout(function(){
131							jQuery.fancybox.close();
132							}, 500);
133					}*/
134				});
135			} else {
136				jQuery.facebox(txt, 'my-groovy-style');
137			}
138
139			jQuery('body').trigger('updateVirtueMartCartModule');
140		});
141
142};
143
144Virtuemart.dataFB = (function(dom, name) {
145	var t;
146	if (dom.is("[data-" + name + "]")) {
147		t = parseInt(dom.attr("data-" + name));
148	} else {
149		t = parseInt(dom.attr(name));
150	}
151	return t;
152});
153
154
155Virtuemart.incrQuantity = (function(event) {
156
157	var rParent = jQuery(this).closest("td, .addtocart-bar, form");
158
159	var quantity = rParent.find('input[name^="quantity["]');
160	var virtuemart_product_id = rParent.find('input[name="virtuemart_product_id[]"]').val();
161	var Ste = Virtuemart.dataFB(quantity, "step");
162
163	if (isNaN(Ste)) Ste = 1;
164	var Qtt = parseInt(quantity.val());
165	if (!isNaN(Qtt)) {
166		quantity.val(Qtt + Ste);
167		maxQtt = Virtuemart.dataFB(quantity, "max");
168		if (!isNaN(maxQtt) && quantity.val() > maxQtt) {
169			quantity.val(maxQtt);
170		}
171		if (!isNaN(virtuemart_product_id)) {
172			Virtuemart.setproducttype(event.data.cart, virtuemart_product_id);
173		} else {
174			Virtuemart.updFormS();
175		}
176
177	}
178});
179
180Virtuemart.decrQuantity = (function(event) {
181
182	var rParent = jQuery(this).closest("td, .addtocart-bar, form");
183	var quantity = rParent.find('input[name^="quantity["]');
184	var virtuemart_product_id = rParent.find('input[name="virtuemart_product_id[]"]').val();
185	var Ste = Virtuemart.dataFB(quantity, "step");
186	if (isNaN(Ste)) Ste = 1;
187	var minQtt = Virtuemart.dataFB(quantity, "init");
188	if (isNaN(minQtt)) minQtt = 1;
189	var Qtt = parseInt(quantity.val());
190
191	if (!isNaN(Qtt) && Qtt > Ste) {
192		quantity.val(Qtt - Ste);
193		if (!isNaN(minQtt) && quantity.val() < minQtt) {
194			quantity.val(minQtt);
195		}
196	} else quantity.val(minQtt);
197	if (!isNaN(virtuemart_product_id)) {
198		Virtuemart.setproducttype(event.data.cart, virtuemart_product_id);
199	} else {
200		Virtuemart.updFormS();
201	}
202
203});
204
205Virtuemart.addtocart = function(e) {
206
207	var targ;
208	if (!e) e = window.event;
209	e.preventDefault();
210
211	if (!Virtuemart.quantityErrorAlert(e)) {
212		return false;
213	}
214
215	if (e.hasOwnProperty('stopSendtocart') && e.stopSendtocart == true) {
216		return false;
217	}
218	if (e.target) targ = e.target;
219	else if (e.srcElement) targ = e.srcElement;
220	if (targ.nodeType == 3) // defeat Safari bug
221		targ = targ.parentNode;
222
223	//if (jQuery(targ).prop("type") == "submit" ||  jQuery(targ).prop("type") == "image" ) {
224	Virtuemart.sendtocart(e.data.cart);
225	return false;
226	//}
227};
228
229Virtuemart.quantityErrorAlert = function(e) {
230	var me = jQuery(this);
231	e.preventDefault();
232	if (me.is('input')) {
233		var step = Virtuemart.dataFB(me, "step");
234		return Virtuemart.checkQuantity(this, step, me.attr("data-errStr"));
235	}
236	return true;
237};
238
239Virtuemart.product = (function(carts) {
240	carts.each(function() {
241		var cart = jQuery(this),
242
243			quantityInput = cart.find('input[name="quantity[]"]'),
244			plus = cart.find('.quantity-plus'),
245			minus = cart.find('.quantity-minus'),
246			select = cart.find('select:not(.no-vm-bind)'),
247			radio = cart.find('input:radio:not(.no-vm-bind)'),
248			virtuemart_product_id = cart.find('input[name="virtuemart_product_id[]"]').val(),
249			quantity = cart.find('.quantity-input');
250		var Ste = Virtuemart.dataFB(quantity, "step");
251		//Fallback for layouts lower than 2.0.18b
252		if (isNaN(Ste)) {
253			Ste = 1;
254		}
255		this.action = "#";
256
257		plus
258			.off('click', Virtuemart.incrQuantity)
259			.on('click', {
260				cart: cart
261			}, Virtuemart.incrQuantity);
262
263		minus
264			.off('click', Virtuemart.decrQuantity)
265			.on('click', {
266				cart: cart
267			}, Virtuemart.decrQuantity);
268
269		select
270			.off('change', Virtuemart.eventsetproducttype)
271			.on('change', {
272				cart: cart,
273				virtuemart_product_id: virtuemart_product_id
274			}, Virtuemart.eventsetproducttype);
275
276		radio
277			.off('change', Virtuemart.eventsetproducttype)
278			.on('change', {
279				cart: cart,
280				virtuemart_product_id: virtuemart_product_id
281			}, Virtuemart.eventsetproducttype);
282
283		quantity
284			.off('click blur submit', Virtuemart.quantityErrorAlert)
285			.on('click blur submit', Virtuemart.quantityErrorAlert)
286			.off('keyup', Virtuemart.eventsetproducttype)
287			.on('keyup', {
288				cart: cart,
289				virtuemart_product_id: virtuemart_product_id
290			}, Virtuemart.eventsetproducttype);
291
292
293		var addtocart = cart.find('button[name="addtocart"], input[name="addtocart"], a[name="addtocart"]');
294
295		addtocart
296			.off('click submit', Virtuemart.addtocart)
297			.on('click submit', {
298				cart: cart
299			}, Virtuemart.addtocart);
300
301	});
302});
303
304Virtuemart.checkQuantity = function(obj, step, myStr) {
305	// use the modulus operator "%" to see if there is a remainder
306	var remainder = obj.value % step,
307		quantity = obj.value;
308
309	if (remainder != 0) {
310		//myStr = "'.vmText::_ ('COM_VIRTUEMART_WRONG_AMOUNT_ADDED').'";
311		if (!isNaN(myStr)) alert(myStr.replace("%s", step));
312		if (quantity != remainder && quantity > remainder) {
313			obj.value = quantity - remainder;
314		} else {
315			obj.value = step;
316		}
317		return false;
318	}
319	return true;
320}
321
322jQuery.noConflict();
323/*jQuery(document).ready(function($) {
324	Virtuemart.product(jQuery("form.product"));
325
326	/*$("form.js-recalculate").each(function(){
327		if ($(this).find(".product-fields").length && !$(this).find(".no-vm-bind").length) {
328			var id= $(this).find('input[name="virtuemart_product_id[]"]').val();
329			Virtuemart.setproducttype($(this),id);
330
331		}
332	});*/
333//});

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.