PageSourceSearch

https://adamtropics.com/components/com_virtuemart/assets/js/vmprices.js?vmver=fbb04157

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

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.