/* Lazy Load Script */ document.addEventListener("DOMContentLoaded", function() { var lazyloadImages = document.querySelectorAll(".lazy"); var lazyloadThrottleTimeout; function lazyload () { if(lazyloadThrottleTimeout) { clearTimeout(lazyloadThrottleTimeout); } lazyloadThrottleTimeout = setTimeout(function() { var scrollTop = window.pageYOffset; lazyloadImages.forEach(function(img) { if(img.offsetTop < (window.innerHeight + scrollTop + 500)) { img.src = img.dataset.src; img.classList.remove('lazy'); } }); if(lazyloadImages.length == 0) { document.removeEventListener("scroll", lazyload); window.removeEventListener("resize", lazyload); window.removeEventListener("orientationChange", lazyload); } }, 20); } document.addEventListener("scroll", lazyload); window.addEventListener("resize", lazyload); window.addEventListener("orientationChange", lazyload); }); /* End of Lazyload script */ let chevrons = document.getElementsByClassName('chevron'); /*let input = document.getElementById('store-door-zipcode-input'); let currentLocation = document.getElementById('current-location');*/ let searchButton = document.getElementById('zip-code-search'); /*currentLocation.addEventListener('click', getGlobalZip);*/ if (searchButton) { searchButton.addEventListener('click', searchWithZipCode); } for (let i = 0; i < chevrons.length; i++) { chevrons[i].addEventListener('click', function(e) { let targetElement = e.target || e.srcElement; displayDropdownContent(targetElement, 'dropdown-content-container'); flipCheveron(targetElement); }); } function displayDropdownContent(ele, selector) { let sibling = ele.nextElementSibling; while (sibling) { if (sibling.classList.contains(selector)) { toggleDisplay(sibling); break; } sibling = sibling.nextElementSibling } } function toggleDisplay(ele) { if (ele.style.display === 'none' || ele.style.display === '') { ele.style.display = 'block'; } else { ele.style.display = 'none'; } } function flipCheveron(ele) { if (ele.classList.contains('chevron-up')) { ele.classList.remove('chevron-up'); } else { ele.classList.add('chevron-up'); } } /*function getGlobalZip(){ var data = this; window['getMyCurrentLocationZipCode'](function(zipcode){ input.value = zipcode; }); return false; }*/ function searchWithZipCode() { //let zipCode = input.value; tealiumStoreToDoor(); window.location.href = '/cars-for-sale?dst=25'; /*if (+zipCode === 'NaN' || zipCode.trim().length < 5 ) { window.location.href = '/cars-for-sale?cnd=new'; } else { window.location.href = '/cars-for-sale?cnd=new&zip=' + zipCode; }*/ } function tealiumStoreToDoor() { let clickdata = { "category_l1":"MLP", "category_l2":"Store to Door", "category_l3":"(not set)", "category_l4":"(not set)", "event":"search_inventory", "event_category":"EngagementType", "event_action":"EngagementType_MLP|||Click", "event_label":"Search Inventory", "event_value":"1", "pagegroup":"mlp" }; window.utag_data = clickdata; window.utag.link(window.utag_data); }