// DEBUG MODE -- Set to true if you want console logs to show. var approve_debug_mode = false; approve_debug_log("APPROVE SCRIPT LOADED"); var approve_commercial_product = false; var approve_commercial_stubs = [ "/equipment/brands/demo-product-807-filter-ls-burrs", "/equipment/mahlkonig/ek43", "/equipment/ditting/807-ls-b-ditti-pp", "/equipment/ditting/807-ls-esp-b-ditti-pp", "/equipment/mahlkonig/e65s-gbw-mahlk-pp", "/equipment/mahlkonig/gh2", "/equipment/mazzer/super-jolly-e", "/equipment/mazzer/mini-e", "/equipment/mahlkonig/e65s-mahlk-pp", "/equipment/mazzer/major-v-flat-mazze-pp", "/equipment/grind/hc-600-heyca-pp", "/equipment/heycafe/hc-880-s-heyca-pp", "/equipment/grind/hc-880lab-heyca-pp", "/equipment/grind/e80-gbw-mahlk-pp", "/equipment/ditting/807-ditti-pp", "/equipment/ditting/807-f-ditting-pp", "/equipment/grind/hc-h1-heyca-pp", "/equipment/mazzer/2844rse-mazze-pp", "/equipment/mahlkonig/e80supreme-mahlk-pp", "/equipment/mahlkonig/gua710", "/equipment/mahlkonig/ek43s-black-mahlk", "/equipment/anfim/scody-ii-anfim-pp", "/equipment/mazzer/zm-mazze", "/equipment/mazzer/mini-t", "/equipment/fetco/gr-2-2", "/equipment/anfim/cody-ii", "/equipment/nuova-simonelli/ami-722108", "/equipment/brands/ami-722108-us-f-nu-si-sp", "/equipment/brands/gua710-us-g-mahlk-sp", "/equipment/brands/2844rse-mazze-pp-1", "/equipment/mazzer/super-jolly-t", "/equipment/mazzer/robur-a", "/equipment/mazzer/kony-a", "/equipment/fetco/CBS-1221-fetco-pp", "/equipment/fetco/cbs-2131xts", "/equipment/brew/e1231us-1a115-pm001-fetco-pp", "/equipment/curtis/g4tp1s63a3100", "/equipment/fetco/e1232us-1b223-pm000-fetco-pp", "/equipment/curtis/cgc", "/equipment/fetco/e1241us-1a115-pm001-fetco-pp", "/equipment/fetco/cbs-2132xts", "/equipment/curtis/g4tp2s63a3100", "/equipment/curtis/g4tp1t10a3100", "/equipment/fetco/cbs-2141xts", "/equipment/fetco/e1251us-1b230-pm110-fetco-sp", "/equipment/curtis/gemxsift63a1000", "/equipment/brew/e1242us-1b223-pm000-fetco-pp", "/equipment/fetco/cbs-2142xts-e214251", "/equipment/curtis/g4tp2t10a3100", "/equipment/fetco/cbs-2142xts-e214251m", "/equipment/curtis/g4gemxsift63a1000", "/equipment/fetco/cbs-2151xts-e215151m", "/equipment/fetco/e1252us-ub230-pm110-fetco-pp", "/equipment/fetco/e1252us-ub230-pm110-fetco-pp", "/equipment/fetco/cbs-2161xts", "/equipment/fetco/cbs-2152xts", "/equipment/curtis/gemxtift10a1000", "/equipment/curtis/g4gemxtift10a1000", "/equipment/fetco/cbs-2162xts", "/equipment/peak-water/pwt001-pe-wa-sp", "/equipment/mixing-bottle-450ml-lo-co-sp", "/equipment/potassium-lo-co-sp", "/equipment/prep/sodium-lo-co-sp", "/equipment/magnesium-lo-co-sp", "/equipment/calcium-lo-co-sp", "/equipment/third-wave-water/third-wave-water", "/equipment/global-customized-water/38-1005", "/equipment/third-wave-water/5-gal-th-wa-pp", "/equipment/lelit/mc747plus-lelit-sp", "/equipment/prima-coffee/tww-5gal-pr-co-bp", "/equipment/prep/252-00210-everp-sp-1", "/equipment/everpure/252-20110-everp-sp", "/equipment/prep/peak-water/pwf001-pe-wa-sp", "/equipment/optipure/252-70260", "/equipment/lotus-water-kit-lo-co-bp", "/equipment/everpure/252-00310-everp-sp", "/equipment/everpure/252-70255-everp-sp", "/equipment/optipure/180-80180", "/equipment/puqp/4-003-02-puqpr-pp", "/equipment/chris-coffee-service/softsys38", "/equipment/optipure/300-05850-optip", "/equipment/optipure/300-05828", "/equipment/bwt/812420-bwt", "/equipment/bwt/812117-bwt-pp", "/equipment/prep/ev962780-everp-sp", "/equipment/everpure/300-05855-everp-sp", "/equipment/optipure/300-05829-optip-sp", "/equipment/prep/ev969331-everp-sp", "/equipment/everpure/300-05821-everp-sp", "/equipment/optipure/300-05830-optip-sp", "/equipment/everpure/252-60110-everp-sp", "/equipment/optipure/300-05835-optip-sp", "/equipment/everpure/300-05833-everp-sp", "/equipment/national-testing-labs/citycheck-standard-na-te-sp", "/equipment/everpure/300-05860-everp-sp", "/equipment/everpure/252-60115-everp-sp", "/equipment/optipure/160-52085-optip-sp", "/equipment/optipure/160-52012", "/equipment/everpure/252-20210-everp-sp", "/equipment/optipure/204-52810", "/equipment/prep/ev962892-everp-pp", "/equipment/everpure/160-52131-everp-sp", "/equipment/optipure/204-52820-optip", "/equipment/optipure/160-52822-optip-sp", "/equipment/Optipure/160-50142-optip-v", "/equipment/everpure/204-53040-everp-sp", "/equipment/everpure/170-52132-everp-sp", "/equipment/brands/ev997559-everp-pp", "/equipment/prep/ev997563-everp-pp", "/equipment/optipure/164-01602-optip-pp", "/equipment/everpure/ev9980-58-everp-sp", "/equipment/optipure/164-14366-optip-pp", "/equipment/optipure/164-15581-optip-sp", "/equipment/mahlkonig/dk-27-lvh", // BELOW ADDED 10/11/2024 "/equipment/mahlkonig/dk-27-lvs", "/equipment/mahlkonig/dk-15-lh", "/equipment/mahlkonig/dk-15-ls", "/equipment/ditting/kfa-1403-indus-ditti-sp", "/equipment/la-marzocco/swift", "/equipment/ditting/kfa1403-ditti-sp", "/equipment/ditting/kr1203-ditti-sp", "/equipment/victoria-arduino/amv28321-vi-ar-pp", "/equipment/mazzer/zm-mazze", "/equipment/nuova-simonelli/ami-722108", "/equipment/mahlkonig/e80w-gbs-mahlk-pp", "/equipment/mahlkonig/e80-gbw-mahlk-pp", "/equipment/mazzer/2844rse-mazze-pp", "/equipment/mahlkonig/e80-gbw-us-e-mahlk-pp", "/equipment/ditting/807-ls-esp-b-ditti-pp", "/equipment/mahlkonig/ek43s-black-mahlk", "/equipment/mahlkonig/ek43", "/equipment/mahlkonig/e80supreme-mahlk-pp", "/equipment/mahlkonig/e65s-gbw-mahlk-pp", "/equipment/brands/demo-product-807-filter-ls-burrs", "/equipment/ditting/807-ls-b-ditti-pp", "/equipment/ditting/807-f-ditting-pp", "/equipment/ditting/807-ditti-pp", "/equipment/anfim/alba-anfim-pp", "/equipment/mahlkonig/e65s-mahlk-pp", "/equipment/mahlkonig/gua710", "/equipment/fetco/gr-2-2", "/equipment/mazzer/major-v-flat-mazze-pp", "/equipment/anfim/luna-anfim-pp", "/equipment/mazzer/mini-e", "/equipment/heycafe/hc-880lab-heyca-pp", "/equipment/heycafe/hc-880-s-heyca-pp", "/equipment/heycafe/hc-h1-heyca-pp", "/equipment/mazzer/mini-t", "/equipment/timemore/70tgd050aa001-timem-pp", "/equipment/ditting/kr1403-ditti-sp", "/equipment/mahlkonig/omnia-bl-mahlk-pp", "/equipment/mazzer/kony-s-e-mazze-sp", "/equipment/mazzer/fmjc01u0e-mazze-pp", "/equipment/brands/major-v-flat-ob-n-mazzer-pp", "/equipment/anfim/pratica-anfim-sp", "/equipment/la-marzocco/strada-s-av-2-group-la-ma-pp", "/equipment/la-marzocco/kb90-av-la-ma-pp", "/equipment/slayer/espresso-v3-slaye-pp", "/equipment/victoria-arduino/mva388gst302000003-vi-ar-pp", "/equipment/synesso/mvp2-synes-pp", "/equipment/slayer/steam-lp-slaye-pp", "/equipment/astoria/tempesta-astor-pp", "/equipment/la-marzocco/gb5-s-av-la-ma-pp", "/equipment/la-marzocco/linea-pb-2av-la-ma-pp", "/equipment/la-marzocco/gb5-s-ee-la-ma-pp", "/equipment/synesso/s200", "/equipment/synesso/mvp2-u-g-r-2071773877-synes-sp", "/equipment/synesso/mvp2-u-g-r-201173554-synes-sp", "/equipment/slayer/slayer-single-group", "/equipment/la-marzocco/linea-s-av-la-ma-pp", "/equipment/la-marzocco/linea-s-ee-la-ma-pp", "/equipment/astoria/0ysae-2gl21119-astor-pp", "/equipment/la-marzocco/gs3-mp-la-ma", "/equipment/la-marzocco/gs3-av-la-ma", "/equipment/nuova-simonelli/mappc19vol02nd0001-nu-si-pp", "/equipment/victoria-arduino/aeov-vi-ar-pp", "/equipment/astoria/praticavantxtra-sae-astor-pp", "/equipment/nuova-simonelli/mappi19vol02nd0001-nu-si-pp", "/equipment/unic/602646-unic-pp", "/equipment/lucca/si5879-lucca-pp", "/equipment/lucca/si5878-lucca-pp", "/equipment/voga/grnd-cntrl-cyclps-voga-sp", "/equipment/marco/1000832us-marco-pp", "/equipment/fetco/e2262us-fetco-pp", "/equipment/curtis/g4gemxtift10a1000", "/equipment/curtis/gemxtift10a1000", "/equipment/fetco/e2252us-fetco-pp", "/equipment/curtis/g4gemxsift63a1000", "/equipment/fetco/e1252us-ub230-pm110-fetco-pp", "/equipment/curtis/g4tp2t10a3100", "/equipment/fetco/e2242us-fetco-pp", "/equipment/curtis/gemxsift63a1000", "/equipment/fetco/e2251us-fetco-pp", "/equipment/fetco/e1251us-1b230-pm110-fetco-sp", "/equipment/curtis/g4tp1t10a3100", "/equipment/fetco/e1242us-1b223-pm010-fetco-pp", "/equipment/curtis/g4tp2s63a3100", "/equipment/fetco/e2241us-fetco-pp", "/equipment/fetco/e2232us-fetco-pp", "/equipment/curtis/g4tp1s63a3100", "/equipment/curtis/cgc", "/equipment/fetco/e1232us-1b223-pm010-fetco-pp", "/equipment/fetco/e1241us-1a115-pm011-fetco-pp", "/equipment/fetco/e2231us-fetco-pp", "/equipment/fetco/e1231us-1a115-pm011-fetco-pp", "/equipment/fetco/CBS-1221-fetco-pp", "/equipment/la-marzocco/gs3-mp-la-ma", "/equipment/la-marzocco/gs3-av-la-ma", "/equipment/nuova-simonelli/mappc19vol02nd0001-nu-si-pp", "/equipment/victoria-arduino/aeov-vi-ar-pp", "/equipment/la-marzocco/linea-mini", "/equipment/marco/5001940c3b-marco-sp", "/equipment/mahlkonig/e80supreme-mahlk-pp", "/equipment/lucca/si5879-lucca-pp", "/equipment/lucca/si5878-lucca-pp", "/equipment/anfim/alba-anfim-pp", "/equipment/mahlkonig/e65s-mahlk-pp", "/equipment/marco/1001950us-marco-sp", "/equipment/caffewerks/cw-hydro-hv-caffe-sp", "/equipment/mazzer/msjpv202blk-mazze-pp", "/equipment/mazzer/fsjc01u0e-bqn-qqa-mazze-pp", "/equipment/anfim/luna-anfim-pp", "/equipment/mazzer/mini-e", "/equipment/mazzer/fsjt01u0e-bgn-qqa-mazze-pp", "/equipment/caffewerks/cw-hydro-caffe-sp", "/equipment/heycafe/buddy-heyca-pp", "/equipment/baratza/1085", "/equipment/summit/spr314los-summi-sp", "/equipment/caffewerks/cw-home-kit-caffe-sp", "/equipment/optipure/164-15581-optip-sp", "/equipment/everpure/ev997563-everp-pp", "/equipment/everpure/ev997559-everp-pp", "/equipment/caffewerks/cw-hydro-hv-caffe-sp", "/equipment/everpure/ev9980-58-everp-sp", "/equipment/everpure/170-52132-everp-sp", "/equipment/everpure/204-53040-everp-sp", "/equipment/caffewerks/cw-hydro-caffe-sp", "/equipment/Optipure/160-50142-optip-v", "/equipment/optipure/160-52822-optip-sp", "/equipment/everpure/ev433986-everp-sp", "/equipment/caffewerks/cw-home-kit-caffe-sp", "/equipment/everpure/ev962892-everp-pp", "/equipment/OptiPure/160-00350-optip-v", "/equipment/everpure/160-52131-everp-sp" ]; for(var s = 0; s < approve_commercial_stubs.length; s++) { if (window.location.pathname.indexOf(approve_commercial_stubs[s]) != -1) { approve_commercial_product = true; break; } } // ****************************************************************** // ****************************************************************** // PRODUCT PAGE // ****************************************************************** // ****************************************************************** var approve_hide_bread = false; var approve_bread_attempts = 0; // In the easiest implementation, you will be able to set every variable you need right here. // GENERAL PRODUCT WRAPPER -- element to look for to know we are on a product page var approve_product_wrapper_ele = '.productView-detailsWrapper'; var approve_product_wrapper = document.querySelector(approve_product_wrapper_ele); // Must ensure we are on a product page before attempting to select the remaining elements. if (approve_product_wrapper){ // ****************************************************************** // PRODUCT PAGE Variable Configuration // ****************************************************************** // PRODUCT INFO ELEMENTS -- These strings will be used in document.querySelector(). Ensure that there is only one of each on the page. var approve_model_ele_name = '.productView-title'; var approve_price_ele_name = '.price.price--withoutTax.price--main'; // ELEMENT TO INSERT THE BUTTON BELOW -- This strings will be used in document.querySelector(). Ensure that there is only one on the page. var approve_insert_after_ele_name = '.productView-product'; var approve_qty_ele_name = 'input.form-input.form-input--incrementTotal.rca-product-quantity'; // QTY INCREASE / DECREASE BUTTONS -- These buttons do not always trigger a change event on the QTY element. We will add click watchers on these elements. [Optional] var approve_inc_quantity_ele = 'button.button--icon[data-action="inc"]'; var approve_dec_quantity_ele = 'button.button--icon[data-action="dec"]'; // OPTIONS -- All of the following is optional. Options are be fairly custom // Wrapper for the ENTIRE options section //var approve_options_wrapper_ele_name = ' .form-field.rca-product-variant-options'; var approve_options_wrapper_ele_name = "[data-product-option-change]"; // Elements that need to have *change* watchers. Mostly used on select elements. Will be used in a foreach, so picking a class with multiple selects is both allowed and encouraged. Ensure these elements are contained within the wrapper above. var approve_subselect_ele_name = ' .form-radio[type="radio"]'; var approve_select_ele_name = ' .form-field'; // APPROVE BUTTON STYLING var approve_button_display_style = 'inline-block'; // '50px' -- All sides will have margin of 50PX // '50px 10px' -- top/bottom will be 50px, right/left 10px // '50px 10px 20px 30px' -- top / right / bottom / left var approve_button_display_margin = '10px 0px'; var approve_button_to_remove_ele = "#bread-finance-div"; // ****************************************************************** // END PRODUCT PAGE Variable Configuration // ****************************************************************** // ****************************************************************** // INITIAL PRODUCT PAGE ELEMENT SELECTION -- No Action Required // ****************************************************************** // Grabbing variables based on the variable configuration. // IMPORTANT -- this selection has to be made both INSIDE and OUTSIDE of init_approve_button. // This is because we need to first identify the elements for the use of watchers -- but also need them to be dynamic. // model var approve_model_ele = document.querySelector(approve_model_ele_name); if (!approve_model_ele){ approve_debug_log("APPROVE: No initial approve_model_ele found.",1); } // price var approve_price_ele = document.querySelector(approve_price_ele_name); if (!approve_price_ele){ approve_debug_log("APPROVE: No initial approve_price_ele found.",1); } // qty if (approve_qty_ele_name){ var approve_qty_ele = document.querySelector(approve_qty_ele_name); if (!approve_qty_ele){ approve_debug_log("APPROVE: No initial approve_qty_ele found.",1); } } // element to insert after var approve_insert_after_ele = document.querySelector(approve_insert_after_ele_name); if (!approve_insert_after_ele){ approve_debug_log("APPROVE: No initial approve_insert_after_ele found.",1); } // ****************************************************************** // END INITIAL PRODUCT PAGE ELEMENT SELECTION // ****************************************************************** // ****************************************************************** // Initilizes the approve button. // This function handles both the CREATION and UPDATE of button variables // ****************************************************************** function init_approve_button(){ // ****************************************************************** // DYNAMIC PRODUCT PAGE ELEMENT SELECTION -- No Action Required // ****************************************************************** // Grabbing variables based on the variable configuration. // IMPORTANT -- this selection has to be made both INSIDE and OUTSIDE of init_approve_button. // This is because we need to first identify the elements for the use of watchers -- but also need them to be dynamic. // model var approve_model_ele = document.querySelector(approve_model_ele_name); if (!approve_model_ele){ approve_debug_log("APPROVE: No dynamic approve_model_ele found.",0,1); return; } var approve_model = approve_model_ele.textContent // price var approve_price_ele = document.querySelector(approve_price_ele_name); if (!approve_price_ele){ approve_debug_log("APPROVE: No dynamic approve_price_ele found.",0,1); return; } var approve_price = approve_price_ele.innerHTML.replace(/[^0-9.]/g, ''); approve_price = parseFloat(approve_price); if (!approve_price || approve_price == 0){ approve_debug_log("APPROVE: Price not found (or is 0) after removing non-numerical characters.",1); } // qty if (approve_qty_ele_name){ var approve_qty_ele = document.querySelector(approve_qty_ele_name); } var approve_qty = 1; if (!approve_qty_ele){ approve_debug_log("APPROVE: No dynamic approve_qty_ele found.",1); } else { approve_qty = approve_qty_ele.value; } approve_qty = parseInt(approve_qty); // element to insert after var approve_insert_after_ele = document.querySelector(approve_insert_after_ele_name); if (!approve_insert_after_ele){ approve_debug_log("APPROVE: No dynamic approve_insert_after_ele found.",0,1); return; } // ****************************************************************** // END DYNAMIC PRODUCT PAGE ELEMENT SELECTION // ****************************************************************** // ****************************************************************** // FIND SELECT OPTIONS // ****************************************************************** var approve_options_wrapper_ele = null; if (approve_options_wrapper_ele_name){ // Get options wrapper approve_options_wrapper_ele = document.querySelector(approve_options_wrapper_ele_name); if (!approve_options_wrapper_ele){ approve_debug_log("No approve_options_wrapper_ele found."); } else { // TRH - added else to prevent js error when options dont exist var approve_option_set = approve_options_wrapper_ele.querySelectorAll(approve_select_ele_name); if (!approve_option_set){ approve_debug_log("No approve_selected_options found."); } // SELECT EACH RADIO BUTTON SET AND LOOP THROUGH (ITEM = RADIO BUTTON SET) approve_option_set.forEach(function (item, index) { // GET ALL BUTTONS FROM EACH BUTTON SET var approve_options = item.querySelectorAll(approve_subselect_ele_name); var approve_title = item.querySelector(' label:nth-child(1)'); var approve_title_fin = approve_title.textContent.replace(/\s\s+/g, ''); // LOOP THROUGH EACH BUTTON IN EACH SET approve_options.forEach(function (item, index) { // IF BUTTON IS CHECKED if (item.checked) { var approve_option_title_raw = approve_options_wrapper_ele.querySelector(' [data-product-attribute-value="'+item.value+'"]'); var approve_option_title = approve_option_title_raw.textContent.replace(/\s\s+/g, ''); // IF BUTTON SET ARE COLOR BUTTONS, PROCESS DIFFERENTLY if (approve_option_title == '') { var color_option = approve_option_title_raw.querySelector(' .form-option-variant.form-option-variant--color'); approve_model += " | " + approve_title_fin.substring(0,approve_title_fin.indexOf(':')) + ": " + color_option.title; } // OTHERWISE APPEND TO APPROVE MODEL else { approve_model += " | " + approve_title_fin.substring(0,approve_title_fin.indexOf(':')) + ": " + approve_option_title; } } }); }); } } // ****************************************************************** // END SELECT OPTIONS // ****************************************************************** // ****************************************************************** // ADD APPROVE BUTTON TO PAGE // ****************************************************************** // Check if the button is on the page 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){ approve_options_wrapper_ele = document.querySelector(approve_options_wrapper_ele_name); if (approve_options_wrapper_ele){ // If a change listener is needed for options, it is initliazed here. var approve_options1 = approve_options_wrapper_ele.querySelectorAll(approve_select_ele_name); approve_options1.forEach(function (item, index) { item.addEventListener('change',event => { setTimeout(()=>{ init_approve_button(); },800); }) }); } } // Insert Button= var approve_button = document.createElement('approve-button'); approve_button.id = "approve_button_id"; if (approve_button_display_style){ approve_button.style.display = approve_button_display_style; } if (approve_button_display_margin){ approve_button.style.margin = approve_button_display_margin; } approve_button.setAttribute('application-type',"embedded_app"); var approve_btn_wrapper = document.createElement("div"); approve_btn_wrapper.appendChild(approve_button); approve_insert_after_ele.after(approve_btn_wrapper); } // Removing a button //console.log("approve_price: ", approve_price); if (approve_button_to_remove_ele && approve_price < 10000){ //console.log("under 10k removing : ", approve_button_to_remove_ele); var approve_button_to_remove = document.querySelector(approve_button_to_remove_ele); if (approve_button_to_remove){ approve_button_to_remove.style.display = "none"; } } if (!approve_commercial_product) { if ((parseFloat(approve_price) * parseInt(approve_qty)) < 5000){ approve_debug_log("Price is below $5000."); approve_button.style.display = "none"; return; } } // 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"); } // ****************************************************************** // 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) } } init_approve_button(); if (approve_bread_attempts <= 1){ //if we have not observed then we're allowed to at least once var approve_bread_wrapper_ele = ' .form-action.rca-subscription'; var approve_bread_wrapper = document.querySelector(approve_bread_wrapper_ele); // if observer observes then increment bread attempts and reinitialize button const approve_bread_observer = new MutationObserver(function() { approve_bread_attempts++; init_approve_button(); }); approve_bread_observer.observe(approve_bread_wrapper,{subtree: true, childList: true}); } // 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){ activate_increase_and_decrease_buttons(); } } 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 { approve_debug_log("APPROVE: approve_product_wrapper not found.",1) } /** * * Activates quantity buttons. * QTY buttons are, sometimes added to the page after a page has been rendered. This will wait for that to happen. */ function activate_increase_and_decrease_buttons(number_of_tries=0){ number_of_tries++; // 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); if ((!approve_qty_btn_inc || !approve_qty_btn_dec) && number_of_tries < 10){ setTimeout(()=>(activate_increase_and_decrease_buttons(number_of_tries)),500); return } // 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_button = document.getElementById('approve_button_id'); if (approve_button){ var approve_btn_qty = parseInt(approve_button.getAttribute('qty')); approve_btn_qty = approve_btn_qty + 1; approve_update_qty(approve_btn_qty); } }); approve_qty_btn_dec.addEventListener('click',event => { var approve_button = document.getElementById('approve_button_id'); if (approve_button){ var approve_btn_qty = parseInt(approve_button.getAttribute('qty')); if (approve_btn_qty > 1){ approve_btn_qty = approve_btn_qty - 1; approve_update_qty(approve_btn_qty); } } }); } else { approve_debug_log("APPROVE: No approve_qty_btn_inc or approve_qty_btn_dec found.",1); } } // ****************************************************************** // ****************************************************************** // END PRODUCT PAGE // ****************************************************************** // ****************************************************************** // 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); }