{"version":3,"file":"maf_Cart.js","names":["$","on","e","setTimeout","priceParent","parents","find","price","text","children","length","origPrice","replace","indexOf","split","sel","ready","id","currentTarget","prop","select","this","attr","click","inputs","currentProduct","applyPromo","includes","val","trigger","removeFreeShippingPromo","SMARTMEDICALIDONLY_UUID","ajax","url","success","result","location","reload","applyFreeShippingPromo","numItems","itemsInCart","idsInCart","productNameInCart","each","index","element","push","productName","smartIdInCart","jQuery","inArray","iceTagInCart","fillableWallerCard","seatbeltId","filter","value","productQualify","i","findIfItemInCart","type","dataType","data","items","classes","target","response","title","product","newProduct","remove","itemIsInCart","mafCartItems","prepend","dialog","$productContainer","closest","document","ajaxStop","localStorage","setItem","itemRemovedReport","event","ecommerce","products","getItem","name","category","variant","quantity","brand","dataLayer"],"sources":["maf_Cart.js"],"sourcesContent":["//Select the proper radio button when editing a donation in the cart\n$('[data-maf-cart=donation-edit]').on('click', function(e) {\n setTimeout(function() {\n var priceParent = $('[data-maf-cart=donation-edit]').parents('div.maf-card-product-90000A, div.maf-card-product-90001').find('.line-item-price');\n var price = priceParent.text();\n if (priceParent.children('.pricing').length) {\n price = priceParent.children('.pricing').text();\n }\n var origPrice = price.replace('$', '');\n price = origPrice.replace('.00', '').replace(',', '');\n if (price.indexOf('$') > -1) {\n price = price.split('$')[0];\n }\n var sel = 'input[value=' + price.replace(',', '').replace('.', '') + ']';\n if (!price || !origPrice) {\n return; //Something bad happened,,\n }\n //Wait for the form to appear and attach listeners.\n $('#monthly_donation_other_field, #onetime_donation_other_field').ready(function() {\n //Clear the \"other\" donation field if another is clicked.\n $('.maf-donation-component-default-form, #form1').find('input').on('click', function(e) {\n var id = $(e.currentTarget).prop('id');\n if (id.indexOf('maf_donation_other') === 0) {\n var sel = '#monthly_donation_other_field';\n if (id.indexOf('_u') > -1) {\n sel += '_u';\n }\n $(sel).select();\n } else if ($(e.currentTarget).prop('type') !== 'submit') {\n $('#monthly_donation_other_field, #onetime_donation_other_field').prop('value', '');\n }\n });\n $('#monthly_donation_other_field, #onetime_donation_other_field').on('click', function() {\n var sel = '#maf_donation_other';\n var id = $(this).attr('id');\n if (id && id.indexOf('onetime_') > -1) {\n sel += '_u';\n }\n $(sel).click();\n });\n var inputs = $('.maf-donation-component-default-form, #form1').find(sel);\n if (inputs.length) {\n //It's a default donation\n inputs.prop('checked', true);\n } else {\n //Custom donation\n $('#maf_donation_other_u, #maf_donation_other').click();\n $('#onetime_donation_other_field, #monthly_donation_other_field').prop('value', origPrice);\n }\n });\n }, 750);\n});\n\nvar currentProduct = null; //Global on purpose\n$('body').on('click', '.edit.maf-link', function(e) {\n var target = $(e.target).parents('.maf-component-cart-card');\n var classes = target.prop('className').split(' ');\n for (var i = 0; i < classes.length; i++) {\n if (classes[i].indexOf('maf-card-product-') > -1) {\n currentProduct = classes[i].replace('maf-card-product-', '');\n }\n }\n});\n\n$('body').on('product:updateAddToCart', function(e, response) {\n // //console.log('CART UPDATE');\n //console.log('updateAddToCart', arguments);\n var title = response.product.productName;\n //Update the modal title with the new product title\n $('.quick-view-dialog .product-name').text(title);\n\n var newProduct = response.product.id;\n //console.log(currentProduct, newProduct);\n $('#modal-error').remove();\n if (newProduct !== currentProduct) {\n var itemIsInCart = null;\n //console.log('This item has changed..');\n var items = response.product.mafCartItems;\n if (items) {\n for (var i = 0; i < items.length; i++) {\n if (newProduct === items[i].id) {\n //console.log('This item is already in the cart', newProduct, items[i]);\n itemIsInCart = true;\n }\n }\n }\n if (itemIsInCart) {\n //Throw an error?\n $('.modal-body .detail-panel').prepend('Item already exists in cart!');\n return; //Don't do the timeout and keep the button disabled.\n }\n }\n setTimeout(function() {\n //Enabling the cart button as they are disabling it for some reason\n //and I can't figure out why..\n var dialog = $(response.$productContainer).closest('.quick-view-dialog');\n $('.update-cart-product-global', dialog).attr('disabled', false);\n }, 500);\n});\n\n$('body').on('click', '.cart-delete-confirmation-btn', function(e) {\n //refresh the page after delete confirmation button is clicked..\n setTimeout(function() {\n location.reload();\n }, 250);\n});\n\n$('body').on('change', '#shippingMethods', function() {\n //change classes of shipping methods in order to show or not show shipping discounts in cart\n // var id = $(this).children(\":selected\").attr(\"data-shipping-id\");\n var onlySmartDonation = $('.maf-cart-case-104140000-90000A');\n if(onlySmartDonation){\n //console.log(id);\n //console.log(onlySmartDonation.length);\n }\n});\n\n$('body').on('click', '.product-edit a', function(e) { \n $(document).ajaxStop(function(){\n $('select option[data-value-id=\"00000\"]').attr('disabled', 'disabled');\n }); \n});\n\nfunction applyPromo(){\n //console.log('YES APPLY PROMO');\n setTimeout(function(){\n var freeshippingPromoCoupon = $('.coupons-and-promos .coupon-code').text().includes(\"SMARTMEDICALIDONLY\");\n if(!freeshippingPromoCoupon){\n $('.form-control.coupon-code-field').val('SMARTMEDICALIDONLY');\n $('button.promo-code-btn').trigger('click');\n }\n }, 333);\n}\n\nfunction removeFreeShippingPromo(){\n //console.log('NO PROMO');\n setTimeout(function(){\n var freeshippingPromoCoupon = $('.coupons-and-promos .coupon-code').text().includes(\"SMARTMEDICALIDONLY\");\n if(freeshippingPromoCoupon){\n //console.log('erase promo',this);\n var SMARTMEDICALIDONLY_UUID = $('.remove-coupon').attr( 'data-uuid' );\n //console.log(SMARTMEDICALIDONLY_UUID);\n $.ajax({ url: '/on/demandware.store/Sites-medicalert-Site/default/Cart-RemoveCouponLineItem?code=SMARTMEDICALIDONLY&uuid='+SMARTMEDICALIDONLY_UUID, success: function(result){\n location.reload();\n } });\n }\n }, 333);\n}\n\nfunction applyFreeShippingPromo(numItems, itemsInCart){\n setTimeout(function(){\n var idsInCart = [];\n var productNameInCart = [];\n $.each(itemsInCart, function(index, element) {\n idsInCart.push(element.id);\n productNameInCart.push(element.productName);\n });\n // Need to Revisit this and call qualifying products inside of Category instead of 1 by 1 so it can be administered\n // var donationInCart = jQuery.inArray('Donation', productNameInCart) !== -1;\n var smartIdInCart = jQuery.inArray('Smart Medical ID Card', productNameInCart) !== -1;\n var iceTagInCart = jQuery.inArray('MedicAlert ICE Tag', productNameInCart) !== -1;\n var fillableWallerCard = jQuery.inArray('MedicAlert Fillable Wallet Card', productNameInCart) !== -1;\n var seatbeltId = jQuery.inArray('MedicAlert Seatbelt ID Holder', productNameInCart) !== -1;\n //console.log('numItems: ',numItems);\n //console.log('itemsInCart: ',itemsInCart);\n //console.log('idsInCart: ', idsInCart);\n //console.log('productNameInCart: ', productNameInCart);\n //console.log('donationInCart: ',donationInCart);\n //console.log('smartIdInCart: ',smartIdInCart);\n //console.log('iceTagInCart: ',smartIdInCart);\n //console.log('seatbeltId: ',seatbeltId);\n //console.log('fillableWallerCard: ',fillableWallerCard);\n\n function noFreeShippingProductsList(value) {\n var productQualify = ['Renewal', 'Donation', 'Smart', 'ICE', 'Fillable','Seatbelt','Advantage 1 Year Protection Plan','Safe & Connected Plan 1yr', 'Safe & Found Plan 1yr'];\n\n for (var i = 0; i < productQualify.length; i++) {\n if (value.indexOf(productQualify[i]) > -1) {\n return false;\n }\n }\n return true;\n }\n\n var engravableProductsListInCart = productNameInCart.filter(noFreeShippingProductsList);\n var engravableProducts = engravableProductsListInCart.length;\n\n //console.log('productNameInCart: ',productNameInCart);\n //console.log('engravableProductsListInCart: ',engravableProductsListInCart);\n //console.log('engravableProducts: ',engravableProducts);\n //console.log('numItems',numItems);\n //console.log('numItems === 1 && smartIdInCart: ', (numItems === 1 && smartIdInCart));\n //console.log('( smartIdInCart && engravableProductsListInCart === 0 ): ', ( smartIdInCart && engravableProductsListInCart === 0 ));\n if( ( engravableProducts === 0 && (smartIdInCart || fillableWallerCard || seatbeltId || iceTagInCart) ) ){\n applyPromo();\n } else{\n removeFreeShippingPromo();\n }\n }, 333);\n}\n\nfunction findIfItemInCart(){\n var url = \"/on/demandware.store/Sites-medicalert-Site/en_US/Cart-Get\";\n $.ajax({\n url: url,\n type: 'GET',\n dataType: 'json',\n success: function(data) {\n applyFreeShippingPromo(data.numItems,data.items);\n }\n });\n}\nfindIfItemInCart();\n\n$('body').on('promotion:success', function(e, data) {\n //console.log('promo is :', data);\n setTimeout(function() {\n location.reload();\n }, 250);\n});\n\n$('.remove-product').on('click', function() {\n localStorage.setItem('ma-remove-product-pid', $(this).attr('data-pid'));\n localStorage.setItem('ma-remove-product-name', $(this).attr('data-name'));\n localStorage.setItem('ma-remove-product-price', $(this).attr('data-price').replace('$', ''));\n localStorage.setItem('ma-remove-product-quantity', $(this).attr('data-quantity'));\n localStorage.setItem('ma-remove-product-variations', $(this).attr('data-variations'));\n localStorage.setItem('ma-remove-product-category', $(this).attr('data-category'));\n});\n\n/*global dataLayer*/\n$('.cart-delete-confirmation-btn').on('click', function() {\n var itemRemovedReport = {\n 'event': 'removeFromCart',\n 'ecommerce': {\n 'remove': {\n 'products': [{\n 'id': localStorage.getItem('ma-remove-product-pid'),\n 'name': localStorage.getItem('ma-remove-product-name'),\n 'price': localStorage.getItem('ma-remove-product-price'),\n 'category': localStorage.getItem('ma-remove-product-category'),\n 'variant': localStorage.getItem('ma-remove-product-variations'),\n 'quantity': localStorage.getItem('ma-remove-product-quantity'),\n 'brand': 'MedicAlert'\n }]\n }\n }\n };\n\n dataLayer.push({ ecommerce: null });\n dataLayer.push(itemRemovedReport);\n\n});\n"],"mappings":"AACAA,EAAE,iCAAiCC,GAAG,SAAS,SAASC,GACpDC,YAAW,WACP,IAAIC,EAAcJ,EAAE,iCAAiCK,QAAQ,2DAA2DC,KAAK,oBACzHC,EAAQH,EAAYI,OACpBJ,EAAYK,SAAS,YAAYC,SACjCH,EAAQH,EAAYK,SAAS,YAAYD,QAE7C,IAAIG,EAAYJ,EAAMK,QAAQ,IAAK,KACnCL,EAAQI,EAAUC,QAAQ,MAAO,IAAIA,QAAQ,IAAK,KACxCC,QAAQ,MAAQ,IACtBN,EAAQA,EAAMO,MAAM,KAAK,IAE7B,IAAIC,EAAM,eAAiBR,EAAMK,QAAQ,IAAK,IAAIA,QAAQ,IAAK,IAAM,IAChEL,GAAUI,GAIfX,EAAE,gEAAgEgB,OAAM,WAEpEhB,EAAE,gDAAgDM,KAAK,SAASL,GA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