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