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>" + 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 var rParent = jQuery(this).closest('td'); 156 rParent = !rParent.length ? jQuery(this).closest('form') : rParent; 157 var quantity = rParent.find('input[name^="quantity["]'); 158 var virtuemart_product_id = rParent.find('input[name="virtuemart_product_id[]"]').val(); 159 var Ste = Virtuemart.dataFB(quantity, "step"); 160 161 if (isNaN(Ste)) Ste = 1; 162 var Qtt = parseInt(quantity.val()); 163 if (!isNaN(Qtt)) { 164 quantity.val(Qtt + Ste); 165 maxQtt = Virtuemart.dataFB(quantity, "max"); 166 if (!isNaN(maxQtt) && quantity.val() > maxQtt) { 167 quantity.val(maxQtt); 168 } 169 if (!isNaN(virtuemart_product_id)) { 170 Virtuemart.setproducttype(event.data.cart, virtuemart_product_id); 171 } else { 172 Virtuemart.updFormS(); 173 } 174 175 } 176}); 177 178Virtuemart.decrQuantity = (function(event) { 179 var rParent = jQuery(this).closest('td'); 180 rParent = !rParent.length ? jQuery(this).closest('form') : rParent; 181 var quantity = rParent.find('input[name^="quantity["]'); 182 var virtuemart_product_id = rParent.find('input[name="virtuemart_product_id[]"]').val(); 183 var Ste = Virtuemart.dataFB(quantity, "step"); 184 if (isNaN(Ste)) Ste = 1; 185 var minQtt = Virtuemart.dataFB(quantity, "init"); 186 if (isNaN(minQtt)) minQtt = 1; 187 var Qtt = parseInt(quantity.val()); 188 189 if (!isNaN(Qtt) && Qtt > Ste) { 190 quantity.val(Qtt - Ste); 191 if (!isNaN(minQtt) && quantity.val() < minQtt) { 192 quantity.val(minQtt); 193 } 194 } else quantity.val(minQtt); 195 if (!isNaN(virtuemart_product_id)) { 196 Virtuemart.setproducttype(event.data.cart, virtuemart_product_id); 197 } else { 198 Virtuemart.updFormS(); 199 } 200 201}); 202 203Virtuemart.addtocart = function(e) { 204 205 var targ; 206 if (!e) e = window.event; 207 e.preventDefault(); 208 209 if (!Virtuemart.quantityErrorAlert(e)) { 210 return false; 211 } 212 213 if (e.hasOwnProperty('stopSendtocart') && e.stopSendtocart == true) { 214 return false; 215 } 216 if (e.target) targ = e.target; 217 else if (e.srcElement) targ = e.srcElement; 218 if (targ.nodeType == 3) // defeat Safari bug 219 targ = targ.parentNode; 220 221 //if (jQuery(targ).prop("type") == "submit" || jQuery(targ).prop("type") == "image" ) { 222 Virtuemart.sendtocart(e.data.cart); 223 return false; 224 //} 225}; 226 227Virtuemart.quantityErrorAlert = function(e) { 228 var me = jQuery(this); 229 e.preventDefault(); 230 if (me.is('input')) { 231 var step = Virtuemart.dataFB(me, "step"); 232 return Virtuemart.checkQuantity(this, step, me.attr("data-errStr")); 233 } 234 return true; 235}; 236 237Virtuemart.product = (function(carts) { 238 carts.each(function() { 239 var cart = jQuery(this), 240 241 quantityInput = cart.find('input[name="quantity[]"]'), 242 plus = cart.find('.quantity-plus'), 243 minus = cart.find('.quantity-minus'), 244 select = cart.find('select:not(.no-vm-bind)'),
245 radio = cart.find('input:radio:not(.no-vm-bind)'), 246 virtuemart_product_id = cart.find('input[name="virtuemart_product_id[]"]').val(), 247 quantity = cart.find('.quantity-input'); 248 var Ste = Virtuemart.dataFB(quantity, "step"); 249 //Fallback for layouts lower than 2.0.18b 250 if (isNaN(Ste)) { 251 Ste = 1; 252 } 253 this.action = "#"; 254 255 plus 256 .off('click', Virtuemart.incrQuantity) 257 .on('click', { 258 cart: cart 259 }, Virtuemart.incrQuantity); 260 261 minus 262 .off('click', Virtuemart.decrQuantity) 263 .on('click', { 264 cart: cart 265 }, Virtuemart.decrQuantity); 266 267 select 268 .off('change', Virtuemart.eventsetproducttype) 269 .on('change', { 270 cart: cart, 271 virtuemart_product_id: virtuemart_product_id 272 }, Virtuemart.eventsetproducttype); 273 274 radio 275 .off('change', Virtuemart.eventsetproducttype) 276 .on('change', { 277 cart: cart, 278 virtuemart_product_id: virtuemart_product_id 279 }, Virtuemart.eventsetproducttype); 280 281 quantity 282 .off('click blur submit', Virtuemart.quantityErrorAlert) 283 .on('click blur submit', Virtuemart.quantityErrorAlert) 284 .off('keyup', Virtuemart.eventsetproducttype) 285 .on('keyup', { 286 cart: cart, 287 virtuemart_product_id: virtuemart_product_id 288 }, Virtuemart.eventsetproducttype); 289 290 291 var addtocart = cart.find('button[name="addtocart"], input[name="addtocart"], a[name="addtocart"]'); 292 293 addtocart 294 .off('click submit', Virtuemart.addtocart) 295 .on('click submit', { 296 cart: cart 297 }, Virtuemart.addtocart); 298 299 }); 300}); 301 302Virtuemart.checkQuantity = function(obj, step, myStr) { 303 // use the modulus operator "%" to see if there is a remainder 304 var remainder = obj.value % step, 305 quantity = obj.value; 306 307 if (remainder != 0) { 308 //myStr = "'.vmText::_ ('COM_VIRTUEMART_WRONG_AMOUNT_ADDED').'"; 309 if (!isNaN(myStr)) alert(myStr.replace("%s", step)); 310 if (quantity != remainder && quantity > remainder) { 311 obj.value = quantity - remainder; 312 } else { 313 obj.value = step; 314 } 315 return false; 316 } 317 return true; 318} 319 320jQuery.noConflict(); 321/*jQuery(document).ready(function($) { 322 Virtuemart.product(jQuery("form.product")); 323 324 /*$("form.js-recalculate").each(function(){ 325 if ($(this).find(".product-fields").length && !$(this).find(".no-vm-bind").length) { 326 var id= $(this).find('input[name="virtuemart_product_id[]"]').val(); 327 Virtuemart.setproducttype($(this),id); 328 329 } 330 });*/ 331//});
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.