Advertisement
Guest User

Untitled

a guest
Mar 11th, 2017
86
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. (function(c){var b=(function(){var g={};var f={currencySymbol:"$",classCartIcon:"my-cart-icon",classCartBadge:"my-cart-badge",classProductQuantity:"my-product-quantity",classProductRemove:"my-product-remove",classCheckoutCart:"my-cart-checkout",affixCartIcon:true,showCheckoutModal:true,cartItems:[],clickOnAddToCart:function(i){},afterAddOnCart:function(j,i,k){},clickOnCartIcon:function(j,k,i,l){},checkoutCart:function(j,i,k){},getDiscountPrice:function(j,i,k){return null}};var h=function(i){var j=c.extend({},f);if(typeof i==="object"){c.extend(j,i)}return j};g.getOptions=h;return g}());var e=(function(){var i={};localStorage.products=localStorage.products?localStorage.products:"";var o=function(s){var q=-1;var r=f();c.each(r,function(t,u){if(u.id==s){q=t;return}});return q};var n=function(q){localStorage.products=JSON.stringify(q)};var k=function(w,r,q,s,v,u){var t=f();t.push({id:w,name:r,summary:q,price:s,quantity:v,image:u});n(t)};var f=function(){try{var r=JSON.parse(localStorage.products);return r}catch(q){return[]}};var p=function(t,s){var q=o(t);if(q<0){return false}var r=f();r[q].quantity=typeof s==="undefined"?r[q].quantity+1:s;n(r);return true};var l=function(v,r,q,s,u,t){if(typeof v==="undefined"){console.error("id required");return false}if(typeof r==="undefined"){console.error("name required");return false}if(typeof t==="undefined"){console.error("image required");return false}if(!c.isNumeric(s)){console.error("price is not a number");return false}if(!c.isNumeric(u)){console.error("quantity is not a number");return false}q=typeof q==="undefined"?"":q;if(!p(v)){k(v,r,q,s,u,t)}};var m=function(){n([])};var j=function(r){var q=f();q=c.grep(q,function(t,s){return t.id!=r});n(q)};var h=function(){var q=0;var r=f();c.each(r,function(s,t){q+=t.quantity*1});return q};var g=function(){var r=f();var q=0;c.each(r,function(s,t){q+=t.quantity*t.price});return q};i.getAllProducts=f;i.updatePoduct=p;i.setProduct=l;i.clearProduct=m;i.removeProduct=j;i.getTotalQuantity=h;i.getTotalPrice=g;return i}());var a=function(j){var i=b.getOptions(j);var r=c("."+i.classCartIcon);var p=c("."+i.classCartBadge);var v=i.classProductQuantity;var h=i.classProductRemove;var q=i.classCheckoutCart;var t="my-cart-modal";var u="my-cart-table";var f="my-cart-grand-total";var x="my-cart-empty-message";var w="my-cart-discount-price";var g="my-product-total";var o="my-cart-icon-affix";if(j.cartItems&&j.cartItems.constructor===Array){e.clearProduct();c.each(i.cartItems,function(){e.setProduct(this.id,this.name,this.summary,this.price,this.quantity,this.image)})}p.text(e.getTotalQuantity());if(!c("#"+t).length){c("body").append('<div class="modal fade" id="'+t+'" tabindex="-1" role="dialog" aria-labelledby="myModalLabel"><div class="modal-dialog" role="document"><div class="modal-content"><div class="modal-header"><button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button><h4 class="modal-title" id="myModalLabel"><span class="glyphicon glyphicon-shopping-cart"></span> Carrito</h4></div><div class="modal-body"><table class="table table-hover table-responsive" id="'+u+'"></table></div><div class="modal-footer"><button type="button" class="btn btn-default" data-dismiss="modal">Close</button><button type="button" class="btn btn-primary '+q+'">Checkout</button></div></div></div></div>')}var z=function(){var A=c("#"+u);A.empty();var C=e.getAllProducts();c.each(C,function(){var D=this.quantity*this.price;A.append('<tr title="'+this.summary+'" data-id="'+this.id+'" data-price="'+this.price+'"><td class="text-center" style="width: 30px;"><img width="30px" height="30px" src="'+this.image+'"/></td><td>'+this.name+'</td><td title="Unit Price">'+i.currencySymbol+this.price+'</td><td title="Cantidad"><input type="number" min="1" style="width: 70px;" class="'+v+'" value="'+this.quantity+'"/></td><td title="Total" class="'+g+'">'+i.currencySymbol+D+'</td><td title="Remove from Cart" class="text-center" style="width: 30px;"><a href="javascript:void(0);" class="btn btn-xs btn-danger '+h+'">X</a></td></tr>')});A.append(C.length?'<tr><td></td><td><strong>Total</strong></td><td></td><td></td><td><strong id="'+f+'"></strong></td><td></td></tr>':'<div class="alert alert-danger" role="alert" id="'+x+'">Your cart is empty</div>');var B=i.getDiscountPrice(C,e.getTotalPrice(),e.getTotalQuantity());if(C.length&&B!==null){A.append('<tr style="color: red"><td></td><td><strong>Total (including discount)</strong></td><td></td><td></td><td><strong id="'+w+'"></strong></td><td></td></tr>')}s();n()};var l=function(){z();c("#"+t).modal("show")};var y=function(){c.each(c("."+v),function(){var A=c(this).closest("tr").data("id");e.updatePoduct(A,c(this).val())})};var s=function(){c("#"+f).text(i.currencySymbol+e.getTotalPrice())};var n=function(){c("#"+w).text(i.currencySymbol+i.getDiscountPrice(e.getAllProducts(),e.getTotalPrice(),e.getTotalQuantity()))};if(i.affixCartIcon){var k=r.offset().top*1+r.css("height").match(/\d+/)*1;var m=r.css("position");c(window).scroll(function(){c(window).scrollTop()>=k?r.addClass(o):r.removeClass(o)})}r.click(function(){i.showCheckoutModal?l():i.clickOnCartIcon(r,e.getAllProducts(),e.getTotalPrice(),e.getTotalQuantity())});c(document).on("input","."+v,function(){var A=c(this).closest("tr").data("price");var C=c(this).closest("tr").data("id");var B=c(this).val();c(this).parent("td").next("."+g).text("$"+A*B);e.updatePoduct(C,B);p.text(e.getTotalQuantity());s();n()});c(document).on("keypress","."+v,function(A){if(A.keyCode==38||A.keyCode==40){return}A.preventDefault()});c(document).on("click","."+h,function(){var A=c(this).closest("tr");var B=A.data("id");A.hide(500,function(){e.removeProduct(B);z();p.text(e.getTotalQuantity())})});c("."+q).click(function(){var A=e.getAllProducts();if(!A.length){c("#"+x).fadeTo("fast",0.5).fadeTo("fast",1);return}y();i.checkoutCart(e.getAllProducts(),e.getTotalPrice(),e.getTotalQuantity());e.clearProduct();p.text(e.getTotalQuantity());c("#"+t).modal("hide")})};var d=function(j,k){var f=c(j);var g=b.getOptions(k);var h=c("."+g.classCartIcon);var i=c("."+g.classCartBadge);f.click(function(){g.clickOnAddToCart(f);var q=f.data("id");var m=f.data("name");var l=f.data("summary");var n=f.data("price");var p=f.data("quantity");var o=f.data("image");e.setProduct(q,m,l,n,p,o);i.text(e.getTotalQuantity());g.afterAddOnCart(e.getAllProducts(),e.getTotalPrice(),e.getTotalQuantity())})};c.fn.myCart=function(f){a(f);return c.each(this,function(){new d(this,f)})}})(jQuery);
Advertisement
Advertisement
Advertisement
RAW Paste Data Copied
Advertisement