Untitled
unknown
plain_text
a year ago
3.1 kB
2
Indexable
Never
function IncreaseMyCart(variantID,plusquantity) { var xhr = new XMLHttpRequest(); var url = "/cart/change.js"; xhr.open("POST", url, true); xhr.setRequestHeader("Content-Type", "application/json"); xhr.onreadystatechange = function () { if (xhr.readyState === 4 && xhr.status === 200) { var parsedState = JSON.parse(xhr.responseText); //window.scrollTo({top: 0, behavior: 'smooth'}); document.querySelector('cart-notification').renderContentsedit(parsedState); } }; var sectionsToRender = ["cart-notification-productedit", "cart-notification-button", "cart-icon-bubble"]; var sections_url = window.location.pathname; var data = JSON.stringify({"quantity": plusquantity, "id": variantID, "sections" : sectionsToRender, "sections_url" :sections_url }); xhr.send(data); } ^^starts here^^^^^^^^ _________________________________________ it then continues: renderContentsedit(parsedState) { document.getElementById("cart-notification-default").innerHTML=""; this.productId = parsedState.id; this.getSectionsToRenderedit().forEach((section => { document.getElementById(section.id).innerHTML = this.getSectionInnerHTML(parsedState.sections[section.id], section.selector); })); //document.getElementsByClassName("cart-logo")[0].addEventListener("click", this.open.bind(this)); var dropDownIcon = document.querySelector('#cart-icon-bubble'); if(dropDownIcon.getAttribute("aria-expanded") == "false") { dropDownIcon.click(); } //if (this.header) this.header.reveal(); //this.open(); } getSectionsToRenderedit() { return [ { id: 'cart-notification-productedit', // selector: `#cart-notification-product-${this.productId}`, }, { id: 'cart-notification-button' }, { id: 'cart-icon-bubble' } ]; } then I think those two codes work together: getSectionInnerHTML(html, selector = '.shopify-section') { return new DOMParser() .parseFromString(html, 'text/html') .querySelector(selector).innerHTML; } ________________________________ getSectionsToRender() { return [ { id: 'main-cart-items', section: document.getElementById('main-cart-items').dataset.id, selector: '.js-contents', }, { id: 'cart-icon-bubble', section: 'cart-icon-bubble', selector: '.shopify-section' }, { id: 'cart-notification', section: 'cart-notification-product', selector: '.shopify-section' }, { id: 'cart-notification-product-edit', section: 'cart-notification-product', selector: '.shopify-section' }, { id: 'cart-live-region-text', section: 'cart-live-region-text', selector: '.shopify-section' }, { id: 'main-cart-footer', section: document.getElementById('main-cart-footer').dataset.id, selector: '.js-contents', } ]; }