// DEBUG MODE -- Set to true if you want console logs to show. var approve_debug_mode = false; approve_debug_log("APPROVE SCRIPT LOADED"); if (window.location.hostname == 'tigermedical.com') { // ****************************************************************** // ****************************************************************** // CART PAGE // ****************************************************************** // ****************************************************************** // ****************************************************************** // CART PAGE Variable Configuration // ****************************************************************** // Element to know we are on the cart page -- ideally a wrapper var approve_cart_wrapper_ele = " .cartitems"; // Element for each line item var approve_cart_item_ele = approve_cart_wrapper_ele + ' .cart-item'; // Total cart price (optional -- watcher for updating the cart) var approve_cart_total_price_ele = '.money .sidecart-total-value' // Item variables var approve_cart_item_model_ele = approve_cart_wrapper_ele + ' h2.cart-item--content-title a'; var approve_cart_item_options_ele = approve_cart_wrapper_ele + ' .sidecart-item__options'; var approve_cart_item_price_ele = approve_cart_wrapper_ele + ' .cart-item--content-price span.money'; var approve_cart_item_qty_ele = approve_cart_wrapper_ele + ' .cart-item__quantity input.quantity-selector__input'; // Insert approve button after this element var approve_cart_insert_btn_after_ele = ' .cart-shipping'; // Element for TAX on cart (optional) var approve_cart_tax_price_ele = ''; // Element for SHIPPING on cart (optional) var approve_cart_shipping_price_ele = approve_cart_wrapper_ele + ' .cart-shippingcalc-rates li'; var approve_cart_shipping_price_dad = approve_cart_wrapper_ele + ' .cart-shippingcalc-rates'; // ****************************************************************** // END CART PAGE Variable Configuration // ****************************************************************** // ****************************************************************** // CART PAGE ELEMENT SELECTION -- No Action Required // ****************************************************************** // Find data wrappers -- ideally with syntax so that there will not be a console error thrown on non-cart pages [ie. no multiple query selectors / finds]. if (approve_cart_wrapper_ele){ var approve_cart_wrapper = document.querySelector(approve_cart_wrapper_ele); var approve_cart_item = document.querySelectorAll(approve_cart_item_ele); //console.log("items: ",approve_cart_item); } function approve_initialize_cart(){ if (!approve_cart_item){ if (approve_debug_mode){ console.log("no cart items found.") } return; } var approve_cart_items_array = []; approve_cart_item.forEach(function (item, index) { //console.log("item: ", item); var approve_cart_item = {}; // Find model, price, and qty for each cart item. var approve_cart_item_model_wrapper = item.querySelector(approve_cart_item_model_ele); var approve_cart_item_qty_wrapper = item.querySelector(approve_cart_item_qty_ele); var approve_cart_item_price_wrapper = item.querySelector(approve_cart_item_price_ele); // check model if (!approve_cart_item_model_wrapper){ if (approve_debug_mode){ console.log("No approve_cart_item_model_wrapper found."); } return; } // var approve_cart_item_model_wrapper = approve_cart_item_model_wrapper; // set and encode cart item model. var approve_cart_item_model = approve_cart_item_model_wrapper.textContent.trim(); var item_options = item.querySelectorAll(approve_cart_item_options_ele); item_options.forEach(function (item, index) { var item_clone = item.cloneNode(true); // console.log(item_clone); var option_t = item_clone.querySelector('span'); option_t.remove(); var option_choice = item_clone.textContent.trim(); var option_title = option_t.textContent.trim(); if (option_choice != null && option_title != null) { approve_cart_item_model += " | " + option_title + ": " + option_choice; } }); approve_cart_item.model = encodeURIComponent(approve_cart_item_model); // check price if (!approve_cart_item_price_wrapper){ if (approve_debug_mode){ console.log("No approve_cart_item_price_wrapper found."); } return; } var approve_price = approve_cart_item_price_wrapper.innerHTML.replace(/[^0-9.]/g, ''); var approve_cart_price = parseFloat(approve_price); // set price approve_cart_item.price = approve_cart_price; // check qty if (!approve_cart_item_qty_wrapper){ if (approve_debug_mode){ console.log("No approve_cart_item_qty_wrapper found. Qty is set to 1."); } var approve_qty = 1; } else { var approve_qty = approve_cart_item_qty_wrapper.value; } var approve_cart_qty = parseInt(approve_qty); // set qty approve_cart_item.qty = parseInt(approve_cart_qty); approve_cart_item.type = "new_product"; approve_cart_items_array.push(approve_cart_item); }); // Check to see if the approve button is already on the page. If it isn't, we will create it now. var approve_button = document.getElementById('approve_button_id'); if (!approve_button){ // Find the element where we want to insert our button. var approve_cart_insert_after_ele = document.querySelector(approve_cart_insert_btn_after_ele); if(!approve_cart_insert_after_ele){ if (approve_debug_mode){ console.log("Element to insert approve button after not found."); } return; } var approve_button = document.createElement('approve-button'); approve_button.id = "approve_button_id"; approve_button.style.display="inline-block"; approve_button.style.textAlign="right"; approve_button.style.marginLeft="0px"; approve_button.style.marginTop="0px"; approve_button.style.marginBottom="20px"; approve_button.setAttribute('application-type',"embedded_app"); approve_button.setAttribute('clear-cart-items',"true"); approve_cart_insert_after_ele.after(approve_button); } if (approve_cart_tax_price_ele){ var approve_tax_price_raw = document.querySelector(approve_cart_tax_price_ele); var approve_tax_price = approve_tax_price_raw.textContent.replace(/[^0-9.]/g, ''); approve_tax_price = parseFloat(approve_tax_price).toFixed(2); if (approve_tax_price && approve_tax_price > 0){ var approve_cart_shipping_item = {}; approve_cart_shipping_item.model = "Tax"; approve_cart_shipping_item.price = approve_tax_price; approve_cart_shipping_item.qty = 1; approve_cart_shipping_item.type = "new_product"; approve_cart_items_array.push(approve_cart_shipping_item); } } if (approve_cart_shipping_price_ele){ var approve_shipping_price_raw = document.querySelector(approve_cart_shipping_price_ele); //console.log("shipping ele: ", approve_shipping_price_raw); var approve_shipping_price = null; if (approve_shipping_price_raw != null) { approve_shipping_price = approve_shipping_price_raw.textContent.replace(/[^0-9.]/g, ''); approve_shipping_price = parseFloat(approve_shipping_price).toFixed(2); } if (approve_shipping_price != null){ var approve_cart_shipping_item = {}; approve_cart_shipping_item.model = "Shipping"; approve_cart_shipping_item.price = approve_shipping_price; approve_cart_shipping_item.qty = 1; approve_cart_shipping_item.type = "new_product"; approve_cart_items_array.push(approve_cart_shipping_item); } } approve_button.setAttribute('items',JSON.stringify(approve_cart_items_array)); } if (approve_cart_wrapper_ele){ approve_initialize_cart(); var approve_price_watcher = document.querySelector(approve_cart_total_price_ele); // Add observer to price element const approve_price_observer = new MutationObserver(function() { approve_initialize_cart(); }); approve_price_observer.observe(approve_price_watcher,{subtree: true, childList: true}); // var approve_shipping_price_watcher = document.querySelector(approve_cart_shipping_price_dad); // // Add observer to price element // const approve_shipping_price_observer = new MutationObserver(function() { // //console.log("observed reloading"); // approve_initialize_cart(); // }); // approve_shipping_price_observer.observe(approve_shipping_price_watcher,{subtree: true, childList: true}); } else { if (approve_debug_mode){ console.log("No approve_cart_wrapper found."); } } } // if (window.location.hostname == 'www.tigermedical.com') { // //console.log("==================================================="); // // ****************************************************************** // // Variable Configuration // // ****************************************************************** // // In the easiest implementation, you will be able to set every variable you need right here. // // PRODUCT PAGE: // // GENERAL PRODUCT WRAPPER -- element to look for to know we are on a product page // var approve_product_wrapper_ele = '.productPageClass'; // // GENERAL PRODUCT INFO WRAPPERS -- elements that wrap the product information that we need. Leave blank if you can use querySelector to find the element directly, without fear of selecting the wrong element. // var approve_model_wrapper_ele_name = ''; // var approve_price_wrapper_ele_name = ''; // var approve_qty_wrapper_ele_name = ''; // // PRODUCT INFO ELEMENTS -- if there is a wrapper present, these elements will be found within their wrappers. Otherwise, it will be a document query selector search. // var approve_model_ele_name = '.lblProductName'; // var approve_price_ele_name = '.lblSitePrice'; // var approve_qty_ele_name = '#ctl00_MainContentHolder_QuantityField'; // // GET PRODUCT INFO ELEMENTS FOR GLOABL USE -- No action requred here. // // model // if (approve_model_wrapper_ele_name){ // var approve_model_ele = document.querySelector(approve_model_wrapper_ele_name).querySelector(approve_model_ele_name); // } else { // var approve_model_ele = document.querySelector(approve_model_ele_name); // } // // price // if (approve_price_wrapper_ele_name){ // var approve_price_ele = document.querySelector(approve_price_wrapper_ele_name).querySelector(approve_price_ele_name); // } else { // var approve_price_ele = document.querySelector(approve_price_ele_name); // } // // qty // if (approve_qty_wrapper_ele_name){ // var approve_qty_ele = document.querySelector(approve_qty_wrapper_ele_name).querySelector(approve_qty_ele_name); // } else { // var approve_qty_ele = document.querySelector(approve_qty_ele_name); // } // // OPTIONS // // Options wrapper // var approve_options_wrapper_ele_name = '#ctl00_MainContentHolder_VariantsDisplay_VariantsPanel'; // // Select element. Should be multiple or able to be used in a foreach loop. // var approve_select_ele1_name = 'select'; // var approve_select_ele2_name = '.dd-selected'; // // The selected option for each select element // var approve_option_selected_ele1_name = 'option'; // var approve_option_selected_ele2_name = '.dd-selected-text'; // // label for each select // var approve_option_selected_ele1_label_name = '.choicelabel'; // var approve_option_selected_ele2_label_name = '.Modifierlabel'; // // ELEMENT TO INSERT THE BUTTON BELOW // // var approve_insert_after_ele = document.querySelector('.cart-form'); // var approve_insert_after_ele = document.querySelector('.price-holder'); // // qty inc / dec elements -- optional // var approve_inc_quantity_ele = ''; // var approve_dec_quantity_ele = ''; // // DEBUG MODE -- Set to true if you want console logs to show. // var approve_debug_mode = false; // // CART PAGE // var approve_cart_wrapper_ele = "#cartcontainer"; // var approve_cart_item_ele = '.cart_item'; // // ****************************************************************** // // PRODUCT PAGE // // ****************************************************************** // var approve_product_wrapper = document.querySelector(approve_product_wrapper_ele); // // ****************************************************************** // // Handles both the creation and update of the approve button. // // ****************************************************************** // function init_approve_button(){ // // model // if (!approve_model_ele){ // if (approve_debug_mode){ // console.log("No approve_model_raw found."); // } // return; // } // var approve_model = approve_model_ele.textContent // var sku = document.querySelector('[itemprop="sku"]'); // if(sku) approve_model = approve_model+" - "+sku.textContent // // price // if (!approve_price_ele){ // if (approve_debug_mode){ // console.log("No approve_price_raw found."); // } // return; // } // var approve_price = approve_price_ele.innerHTML.replace(/[^0-9.]/g, ''); // approve_price = parseFloat(approve_price); // // qty // if (!approve_qty_ele){ // if (approve_debug_mode){ // console.log("No approve_qty_raw found."); // } // var approve_qty = 1; // } else { // var approve_qty = approve_qty_ele.value; // } // approve_qty = parseInt(approve_qty); // // ****************************************************************** // // FIND SELECT OPTIONS // // ****************************************************************** // // if (approve_options_wrapper_ele_name){ // // var approve_selected_options = approve_options_wrapper_ele_name.querySelectorAll(approve_select_ele); // // approve_selected_options.forEach(function (item, index) { // // var approve_option_name = item.querySelector(approve_option_selected_ele).textContent; // // approve_model = approve_model + " / " + approve_option_name; // // }); // // } // // Check to see if the approve button is already on the page. If it isn't, we will create it now. // var approve_button = document.getElementById('approve_button_id'); // if (!approve_button){ // // If event listener is needed for options, here is where it can be initiated. // // if (approve_options_wrapper_ele_name){ // // // If a change listener is needed for options, it is initliazed here. // // var approve_options = approve_options_wrapper_ele_name.querySelectorAll(approve_select_ele); // // approve_options.forEach(function (item, index) { // // item.addEventListener('change',event => { // // init_approve_button(); // // }) // // }); // // } // // Insert Button // if(!approve_insert_after_ele){ // if (approve_debug_mode){ // console.log("Element to insert approve button after not found."); // } // return; // } // // var insert_ele = item.querySelector(approve_product_gallery_insert_btn_after_ele); // var approve_button_wrapper = document.createElement("div"); // approve_button_wrapper.id = "approve_button_id"; // approve_button_wrapper.className = "approve-gallery-btn-container"; // approve_button_wrapper.style.marginTop = "10px"; // approve_button_wrapper.innerHTML = /*html*/` //
// `; // //button wrapper // approve_button_wrapper.style.width = "auto"; // approve_button_wrapper.style.display = "block"; // approve_button_wrapper.style.margin = "10px 0px 20px 0px"; // approve_button_wrapper.style.textAlign = "left"; // //button // var approve_gallery_button = approve_button_wrapper.querySelector('.approve-gallery-button'); // approve_gallery_button.style.width = "150px"; // approve_gallery_button.style.textAlign = "center"; // approve_gallery_button.style.borderRadius = "12px"; // approve_gallery_button.style.fontFamily = "verdana,sans-serif"; // approve_gallery_button.style.fontSize = "14px"; // // button teaser // var approve_gallery_teaser = approve_button_wrapper.querySelector('.teaser'); // approve_gallery_teaser.style.fontSize = "1.5em"; // approve_gallery_teaser.style.fontWeight = "700"; // // sm text // var approve_gallery_teaser = approve_button_wrapper.querySelector('.sm-txt'); // approve_gallery_teaser.style.fontSize = ".8em"; // // button teaser rate // var approve_gallery_teaser_rate = approve_button_wrapper.querySelector('.teaser-rate'); // if (approve_price >= 1500){ // approve_insert_after_ele.after(approve_button_wrapper); // } // // var approve_button = document.createElement('approve-button'); // // approve_button.id = "approve_button_id"; // // approve_button.style.display="inline-block"; // // approve_button.style.marginTop="10px"; // // approve_button.setAttribute('application-type',"embedded_app"); // approve_insert_after_ele.after(approve_button_wrapper); // } // // If price is below $200, teaser rate breaks. Let's ensure that it's above $500. // if ((parseFloat(approve_price) * parseInt(approve_qty)) < 500){ // if (approve_debug_mode){ // console.log("Price is below $200."); // } // approve_button.style.display = "none"; // return; // } // approve_gallery_teaser_rate.setAttribute('approve-total',approve_price); // // Set approve button variables. // // approve_button.setAttribute('price',approve_price); // // approve_button.setAttribute('model',approve_model); // // approve_button.setAttribute('qty',approve_qty); // // approve_button.setAttribute('type',"new_product"); // window.kwipped_approve.core.activate_approve_teaser_rates(); // } // // ****************************************************************** // // Simple set button qty. Must pass the new QTY to the button. // // ****************************************************************** // function approve_update_qty(approve_qty){ // var approve_button = document.getElementById('approve_button_id'); // if (approve_button){ // var approve_btn_qty = parseInt(approve_button.getAttribute('qty')); // if (approve_qty != approve_btn_qty){ // approve_button.setAttribute('qty',approve_qty); // } // } // } // // ****************************************************************** // // If timing is an issue, this function creates an interval for setting button qty. // // ****************************************************************** // var approve_timer = null; // function approve_update_qty_timer(){ // var approve_button = document.getElementById('approve_button_id'); // if (approve_button){ // if(approve_timer) { // clearInterval(approve_timer); // approve_timer = null; // } // var approve_btn_qty = parseInt(approve_button.getAttribute('qty')); // var number_of_checks = 0; // approve_timer = setInterval(function(){ // if(number_of_checks>=5){ // clearInterval(approve_timer); // approve_timer = null; // } // if(approve_btn_qty != parseInt(approve_qty_ele.value)){ // approve_button.setAttribute('qty',parseInt(approve_qty_ele.value)); // clearInterval(approve_timer); // approve_timer = null; // } // number_of_checks++; // },500) // } // } // if (approve_product_wrapper){ // init_approve_button(); // /// If there is a qty element, we need to set watchers/listeners. // if (approve_qty_ele){ // // Add change watcher to qty input // approve_qty_ele.addEventListener('change',event => { // approve_update_qty_timer(); // }) // if (approve_inc_quantity_ele && approve_dec_quantity_ele){ // // buttons that raise or lower the quantity. // var approve_qty_btn_inc = document.querySelector(approve_inc_quantity_ele); // var approve_qty_btn_dec = document.querySelector(approve_dec_quantity_ele); // // Assign click events to these buttons so that qty is updated on click. // if (approve_qty_btn_inc && approve_qty_btn_dec){ // approve_qty_btn_inc.addEventListener('click',event => { // var approve_qty = parseInt(approve_qty_ele.value); // approve_update_qty_timer(); // }); // approve_qty_btn_dec.addEventListener('click',event => { // var approve_qty = parseInt(approve_qty_ele.value); // approve_update_qty_timer(); // }); // } else { // if (approve_debug_mode){ // console.log("No qty buttons found."); // } // } // } // } else { // if (approve_debug_mode){ // console.log("No qty element found."); // } // } // if (approve_price_ele){ // var approve_price_watcher = approve_price_ele; // // Add observer to price element // const approve_price_observer = new MutationObserver(function() { // init_approve_button(); // }); // approve_price_observer.observe(approve_price_watcher,{subtree: true, childList: true}); // var approve_model_watcher = approve_model_ele; // if (approve_model_watcher){ // // Add observer to price element // const approve_model_observer = new MutationObserver(function() { // init_approve_button(); // }); // approve_model_observer.observe(approve_model_watcher,{subtree: false, childList: true}); // } // } // } else { // if (!approve_product_wrapper && approve_debug_mode){ // console.log("No approve_product_wrapper found"); // } // } // // ****************************************************************** // // CART // // ****************************************************************** // // ****************************************************************** // // DATA WRAPPERS -- FOR INITIAL CHECKS // // ****************************************************************** // // Find data wrappers -- ideally with syntax so that there will not be a console error thrown on non-product pages [ie. no multiple query selectors / finds]. // var approve_cart_wrapper = document.querySelector(approve_cart_wrapper_ele); // var approve_cart_item = document.querySelectorAll(approve_cart_item_ele); // function approve_initialize_cart2(){ // if (!approve_cart_item){ // if (approve_debug_mode){ // console.log("no cart items found.") // } // return; // } // var approve_cart_items_array = []; // var approve_total_price = 0; // var approve_highest_price = 0; // approve_cart_item.forEach(function (item, index) { // var approve_cart_item = {}; // var approve_sku_ele_name = 'span.item_no'; // // Data wrappers for each approve cart item // var approve_cart_item_model_wrapper = item.querySelector('.title_item'); // var approve_cart_item_model_option_wrapper = item.querySelector('.modifiers'); // var approve_cart_item_qty_wrapper = item.querySelector('.box_qty'); // var approve_cart_item_price_wrapper = item.querySelector('.prices'); // var approve_cart_item_sku = item.querySelector(approve_sku_ele_name); // //console.log("SKU: ", approve_cart_item_sku); // // check to ensure data wrappers exist // if (!approve_cart_item_model_wrapper || !approve_cart_item_price_wrapper){ // if (approve_debug_mode){ // if (!approve_cart_item_model_wrapper){ // console.log("no approve_cart_item_model_wrapper found for cart item"); // } // if (!approve_cart_item_price_wrapper){ // console.log("no approve_cart_item_price_wrapper found for cart item"); // } // } // return; // } // // find model // if (!approve_cart_item_model_wrapper){ // if (approve_debug_mode){ // console.log("No approve_cart_item_model_wrapper found for cart item."); // } // return; // } // var approve_cart_item_model_wrapper2 = approve_cart_item_model_wrapper.querySelector('a'); // if (!approve_cart_item_model_wrapper2){ // if (approve_debug_mode){ // console.log("No approve_cart_item_model_wrapper2 found for cart item."); // } // return; // } // approve_cart_item_model = approve_cart_item_model_wrapper2.textContent; // var approve_sku = " | " + approve_cart_item_sku.textContent; // approve_cart_item_model_option = approve_cart_item_model_option_wrapper.innerHTML.replace(/<\/?[^>]+(>|$)/g, " / "); // approve_cart_item.model = encodeURIComponent(approve_cart_item_model + approve_cart_item_model_option + (approve_sku != '' ? approve_sku : '')); // // find price // if (!approve_cart_item_price_wrapper){ // if (approve_debug_mode){ // console.log("No approve_cart_item_price_wrapper found for cart item."); // } // return; // } // var approve_cart_item_price_wrapper2 = approve_cart_item_price_wrapper.querySelector('.number'); // if (!approve_cart_item_price_wrapper2){ // if (approve_debug_mode){ // console.log("No approve_cart_item_price_wrapper2 found for cart item."); // } // return; // } // var approve_cart_item_price = approve_cart_item_price_wrapper2.textContent; // if (!approve_cart_item_price){ // if (approve_debug_mode){ // console.log("No approve_cart_item_price found for cart item."); // } // return; // } // approve_cart_item_price = approve_cart_item_price.replace(/[^0-9.]/g, ''); // approve_cart_item_price = parseFloat(approve_cart_item_price); // approve_cart_item.price = approve_cart_item_price; // // find qty // if (approve_cart_item_qty_wrapper){ // var approve_cart_item_qty = approve_cart_item_qty_wrapper.value; // if (!approve_cart_item_qty){ // if (approve_debug_mode){ // console.log("no approve cart item qty value found."); // } // approve_cart_item_qty = 1; // } // } else { // var approve_cart_item_qty = 1 // } // approve_cart_item.qty = parseInt(approve_cart_item_qty); // approve_cart_item.type = "new_product"; // approve_cart_items_array.push(approve_cart_item); // // Cart total checks // approve_total_price += (approve_cart_item_price*approve_cart_item.qty); // if (approve_highest_price < approve_cart_item_price){ // approve_highest_price = approve_cart_item_price; // } // }); // // Check to see if the approve button is already on the page. If it isn't, we will create it now. // var approve_button = document.getElementById('approve_button_id'); // if (!approve_button){ // // Find the element where we want to insert our button. // var approve_cart_insert_after_ele = document.querySelector('#carttotals'); // if(!approve_cart_insert_after_ele){ // if (approve_debug_mode){ // console.log("Element to insert approve button after not found."); // } // return; // } // var approve_button = document.createElement('approve-button'); // approve_button.id = "approve_button_id"; // approve_button.style.display="inline-block"; // approve_button.style.textAlign="right"; // approve_button.style.marginLeft="20px"; // approve_button.style.marginTop="10px"; // approve_button.setAttribute('application-type',"embedded_app"); // approve_button.setAttribute('clear-cart-items',"true"); // if (approve_total_price >= 1500 && approve_highest_price >= 500){ // approve_cart_insert_after_ele.after(approve_button); // } else { // approve_button.style.display="none"; // } // } // var approve_tax_price_raw = document.querySelector('.lblTaxTotal'); // var approve_tax_price = approve_tax_price_raw.textContent.replace(/[^0-9.]/g, ''); // approve_tax_price = parseFloat(approve_tax_price).toFixed(2); // if (approve_tax_price && approve_tax_price > 0){ // var approve_cart_tax_item = {}; // approve_cart_tax_item.model = "Tax"; // approve_cart_tax_item.price = approve_tax_price; // approve_cart_tax_item.qty = 1; // approve_cart_tax_item.type = "new_product"; // approve_cart_items_array.push(approve_cart_tax_item); // } // // var approve_shipping_price_raw = null; // // var approve_shipping_price_selected = document.querySelector("input[type='radio']:checked"); // // if (approve_shipping_price_selected){ // // var approve_shipping_price_selected_parent = approve_shipping_price_selected.closest(".row"); // // var approve_shipping_price_raw = approve_shipping_price_selected_parent.querySelector(".price"); // // } // // if (!approve_shipping_price_raw){ // // approve_shipping_price_raw = document.querySelector('.lblShippingTotal'); // // } // // var approve_shipping_price = approve_shipping_price_raw.textContent.replace(/[^0-9.]/g, ''); // // approve_shipping_price = parseFloat(approve_shipping_price).toFixed(2);; // var approve_shipping_price_raw = null; // var approve_shipping_price_selected = document.querySelector("input[type='radio'][checked]"); // var approve_shipping_price_selected = document.querySelector(".trShipping .number .lblShippingTotal"); // // if (approve_shipping_price_selected){ // // var approve_shipping_price_selected_parent = approve_shipping_price_selected.closest(".row"); // // var approve_shipping_price_raw = approve_shipping_price_selected_parent.querySelector(".price"); // // } // // if (!approve_shipping_price_raw){ // approve_shipping_price_raw = document.querySelector('.lblShippingTotal'); // // } // var approve_shipping_price = approve_shipping_price_raw.textContent.replace(/[^0-9.]/g, ''); // approve_shipping_price = parseFloat(approve_shipping_price).toFixed(2); // if (approve_shipping_price && approve_shipping_price >= 0.00){ // var approve_shipping_truck = document.querySelector("#pnlTruckItems"); // var approve_shipping_regular = document.querySelector("#divShippingCalcResults"); // var approve_shipping_options = ""; // var approve_cart_shipping_item = {}; // if (approve_shipping_regular) { // approve_shipping_options += " | Regular Shipping: "; // var approve_selected_shipping_option = document.querySelector("#rbtnShippingMethod[checked]"); // if (approve_selected_shipping_option) { // var approve_shipping_selected_text = approve_selected_shipping_option.parentElement.parentElement.parentElement.querySelector(".txt"); // if (approve_shipping_selected_text) { // approve_shipping_options += approve_shipping_selected_text.textContent; // } // var approve_shipping_selected_price = approve_selected_shipping_option.parentElement.parentElement.parentElement.querySelector(".price"); // if (approve_shipping_selected_price) { // approve_shipping_options += " " + approve_shipping_selected_price.textContent; // } // } // approve_shipping_country = document.querySelector(".shipping .country select.promo_box.lstCountry option[selected]"); // approve_shipping_zip = document.querySelector(".shipping .zip input.promo_box.zipcodeField.toUpper"); // if (approve_shipping_country) { // approve_shipping_options+= " Country: "+approve_shipping_country.textContent; // } // if (approve_shipping_zip) { // approve_shipping_options+= " Zip Code: "+approve_shipping_zip.value; // } // } // if (approve_shipping_truck) { // approve_shipping_options += " | Truck Shipping: "; // approve_shipping_options += approve_shipping_truck.textContent.replace("Modify options", ""); // approve_shipping_country = document.querySelector(".shipping .country select.promo_box.lstCountry option[selected]"); // approve_shipping_zip = document.querySelector(".shipping .zip input.promo_box.zipcodeField.toUpper"); // if (approve_shipping_country) { // approve_shipping_options+= " Country: "+approve_shipping_country.textContent; // } // if (approve_shipping_zip) { // approve_shipping_options+= " Zip Code: "+approve_shipping_zip.value; // } // // approve_cart_shipping_item.model = "Truck Shipping: "+ approve_shipping_options; // // approve_cart_shipping_item.price = approve_shipping_price; // // approve_cart_shipping_item.qty = 1; // // approve_cart_shipping_item.type = "new_product"; // // approve_cart_items_array.push(approve_cart_shipping_item); // } // // get options text // // var approve_shipping_box = document.querySelector("#pnlTruckItems"); // // var approve_truck_items = true; // // if (!approve_shipping_box) {// may not be truck items // // approve_shipping_box = document.querySelector("#divShippingCalcResults"); // // approve_truck_items = false; // // } // // var approve_cart_shipping_item = {}; // // var approve_shipping_options = ""; // // if (approve_shipping_box) { // // if (approve_truck_items) approve_shipping_options += approve_shipping_box.textContent.replace("Modify options", ""); // // else { // // var approve_selected_shipping_option = document.querySelector("#rbtnShippingMethod[checked]"); // // if (approve_selected_shipping_option) { // // var approve_shipping_selected_text = approve_selected_shipping_option.parentElement.parentElement.parentElement.querySelector(".txt"); // // if (approve_shipping_selected_text) { // // approve_shipping_options += approve_shipping_selected_text.textContent; // // } // // } // // } // // approve_shipping_country = document.querySelector(".shipping .country select.promo_box.lstCountry option[selected]"); // // approve_shipping_zip = document.querySelector(".shipping .zip input.promo_box.zipcodeField.toUpper"); // // if (approve_shipping_country) { // // approve_shipping_options+= " | Country: "+approve_shipping_country.textContent; // // } // // if (approve_shipping_zip) { // // approve_shipping_options+= " | Zip Code: "+approve_shipping_zip.value; // // } // // } // approve_cart_shipping_item.model = "Shipping: " + approve_shipping_options; // approve_cart_shipping_item.price = approve_shipping_price; // approve_cart_shipping_item.qty = 1; // approve_cart_shipping_item.type = "new_product"; // approve_cart_items_array.push(approve_cart_shipping_item); // } // approve_button.setAttribute('items',JSON.stringify(approve_cart_items_array)); // } // var approve_cart_timer = null; // function approve_initialize_cart_timer(){ // // Unique to Tiger Supplies -- we need to make sure the grand total is present before loading anything // if(approve_cart_timer) { // clearInterval(approve_cart_timer); // approve_cart_timer = null; // } // var number_of_checks = 0; // approve_cart_timer = setInterval(function(){ // if(number_of_checks>=5){ // clearInterval(approve_cart_timer); // approve_cart_timer = null; // } // var approve_card_grand_total = document.getElementById('ctl00_MainContentHolder_lblGrandTotal'); // if(approve_card_grand_total){ // approve_initialize_cart2(); // clearInterval(approve_cart_timer); // approve_cart_timer = null; // } // number_of_checks++; // },500) // } // if (approve_cart_wrapper){ // approve_initialize_cart_timer(); // document.querySelectorAll("input[type='radio']").forEach(function (item, index) { // item.addEventListener('click',event => { // approve_initialize_cart2(); // }) // }); // var approve_price_watcher = document.querySelector(".total_prices"); // // Add observer to price element // const approve_price_observer = new MutationObserver(function() { // approve_initialize_cart2(); // }); // approve_price_observer.observe(approve_price_watcher,{subtree: true, childList: true}); // } else { // if (approve_debug_mode){ // console.log("No approve_cart_wrapper found."); // } // } // } // IF YOU WANT TO USE A LOG WITH COLORS YOU CAN USE function approve_debug_log(log, warn, err) { warn = warn || false; err = err || false; let css = "padding: 5px 20px; "; if (err) { css += "background:#8B0000; color:#fff; "; } else if(warn) { css += "background:#FFBF00; color:#000; "; } else { css += "background:#418AC9; color:#fff; "; } if (approve_debug_mode) console.log("%c"+log,css); }