var cart_init=!1;Shopcada.cartDrawer=function(){if(!cart_init){var cartClassName="ajax-cart-drawer";if($('.ajax-cart-summary-sticky').length){cartClassName+=" ajax-cart-summary-sticky"} var setting={class:cartClassName,animate:!0};cartDrawer=new Shopcada.drawer(setting);cartDrawer.setTitle('');cart_init=!0}};Shopcada.GetCart=function(){source=$("#CartTemplate").html(),template=Handlebars.compile(source);$.ajax({url:'/api/shopcada/cart',data:'',dataType:'json',success:function(res){var cart=res.cart;var cartTotal=0;cart.products.forEach(function(item,i,self){if(item.image!=null){var img_path=item.image.substr(0,item.image.lastIndexOf('/'))+"/95x95/";var img_name=item.image.split("/").pop();var product_img=img_path+img_name;self[i].image=product_img;var item_total=item.qty*item.price;var item_total_list_price=item.qty*item.list_price;self[i].total_raw=item_total;self[i].total=Shopcada.formatMoney(item_total);self[i].total_list_price_raw=item_total_list_price;self[i].total_list_price=Shopcada.formatMoney(item_total_list_price);cartTotal+=item_total} var option_obj=item.options;product_options=[];for(var x in option_obj){option={option:x,value:option_obj[x]};product_options.push(option)} self[i].product_options=product_options});cart.cart_total=Shopcada.formatMoney(cartTotal);if(cart.products.length){cart.extra_class="has-products"} cartDrawer.showContent(template(cart))}})} if($('.ajax-cart-pattern-dropdown').length){Shopcada.drawer.prototype.init=function(setting){if(!this.is_init){this.uuid=new Date().getTime();var extra_class='';var extra_class='';if(setting!==undefined){if(setting.class!==undefined){extra_class=" "+setting.class}} $('.customer-links .cart').append("
"+"
"+"
"+"

"+"
"+"
"+"
"+"
"+"
"+"
"+"
");this.element=$('#drawer-wrapper-'+this.uuid);this.escKeyBind();this.closeOnClick();this.is_init=!0}}} Shopcada.AddToCart=function(id,model,title){$.ajax({type:"POST",url:"/api/shopcada/cart",data:JSON.stringify({product_id:id,sku:model,qty:1}),dataType:"json",contentType:"application/json; charset=utf-8",success:function(){localStorage.removeItem('cartCount');localStorage.removeItem('cartAmount');if(location.pathname=='/cart'){location.reload()}else{$('#bs-modal').find('.modal-content').empty();$('#bs-modal').addClass('modal-status');$('#bs-modal').find('.modal-content').append('
'+title+' added to your shopping bag
') UpdateCart();$('#bs-modal').modal('show');setTimeout(function(){$('#bs-modal').modal('hide');$('html,body').addClass('iphone-navbar-forced-out');Shopcada.cartDrawer();Shopcada.GetCart();return!1},1000)}},error:function(xhr,status,error){var err=JSON.parse(xhr.responseText);$('#bs-modal').find('.modal-content').empty();$('#bs-modal').addClass('modal-status');$('#bs-modal .modal-content').append('
'+err.message+'
') $('#bs-modal').modal('show');setTimeout(function(){$('#bs-modal').modal('hide')},2000)}});return!1} $(document).ready(function(){Handlebars.registerHelper('ifEquals',function(arg1,arg2,options){return(arg1==arg2)?options.fn(this):options.inverse(this)});Handlebars.registerHelper('ifGreater',function(arg1,arg2,options){return(arg1>arg2)?options.fn(this):options.inverse(this)});if($('.ajax-cart-pattern-dropdown').length){$('a.cart-link').on('mouseenter',function(){if(isTouchDevice){return} $('html,body').addClass('iphone-navbar-forced-out');Shopcada.cartDrawer();Shopcada.GetCart();return!1});$('.cart').on('mouseleave',function(){$('body').removeClass('drawer-expanded');$('.drawer-wrapper').removeClass('expanded')})}else{$('a.cart-link').click(function(){$('html,body').addClass('iphone-navbar-forced-out');$('body').removeClass('nav-expanded account-open');Shopcada.cartDrawer();Shopcada.GetCart();var top_height=headerHeight+headerTopHeight;if($('#admin-menu').is(":visible")&&!$('body').hasClass('sticky-enabled')){var top_height=headerHeight+headerTopHeight+$('#admin-menu').height()-1} $('.drawer.drawer-right').css('padding-top',top_height);return!1})} $(window).on('scroll resize',function(){var top_height=headerHeight+headerTopHeight;if($('#admin-menu').is(":visible")&&!$('body').hasClass('sticky-enabled')){var top_height=headerHeight+headerTopHeight+$('#admin-menu').height()-1} $('.drawer.drawer-right').css('padding-top',top_height)});$(document).on('click','.drawer .drawer-close, .overlay',function(){$('html,body').removeClass('iphone-navbar-forced-out')});$('.product-action-button.action-cart').on('click',function(){var id=$(this).data('id');var model=$(this).data('model');var title=$(this).data('title');if(id&&model){Shopcada.AddToCart(id,model,title)}else{return!0} return!1})})