Created
April 21, 2023 09:46
-
-
Save Sally165/bc2ce12e65f60d750cc33a7233388bf5 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script> | |
<script> | |
try { | |
setTimeout(function () { | |
window.__pagefly_helper_store__ && | |
window.__pagefly_helper_store__.subscribe(function (res) { | |
$.getJSON('/cart.json').then(cart => { | |
fetch('/cart?view=item').then(response => response.text()) | |
.then(text => { | |
const sectionInnerHTML = new DOMParser().parseFromString(text, 'text/html'); | |
const cartFormInnerHTML = sectionInnerHTML.getElementById('CartDrawer').innerHTML; | |
const totalPrice=sectionInnerHTML.querySelector('#CartDrawer .totals__subtotal-value').innerHTML; | |
$('#CartDrawer').html(cartFormInnerHTML) | |
$('cart-drawer').removeClass('is-empty') | |
$('cart-drawer-items').removeClass('is-empty') | |
if($('#cart-icon-bubble .cart-count-bubble').length===0){ | |
const cartNumber=document.createElement('div') | |
cartNumber.className='cart-count-bubble' | |
cartNumber.innerHTML=` | |
<span aria-hidden="true">${cart.item_count}</span> | |
<span class="visually-hidden">${cart.item_count} items</span> | |
` | |
$('#cart-icon-bubble').append(cartNumber) | |
}else{ | |
$('.cart-count-bubble span[aria-hidden="true"]').each((_,count)=>$(count).text(cart.item_count)) | |
} | |
$('#cart-icon-bubble')[0].click() | |
$('#CartDrawer-Overlay').on('click',()=>{ | |
$('cart-drawer').removeClass('active') | |
$('body').removeClass('overflow-hidden') | |
}) | |
}) | |
}); | |
}); | |
}, 2500); | |
} catch (e) { | |
console.warn(e); | |
} | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment