if (typeof(KDK) !== 'object') { KDK = {}; } KDK.brandsearch = function() { let d = document; let term = d.getElementById('brandsearchterm').value; let brand = parseInt(window.location.href.split("/")[4]); window.location.href=("/search?searchtoken=hp&searchterm="+term+"&brandsearch="+brand); } KDK.catsearch = function() { let d = document; let term = d.getElementById('catsearchterm').value; let cat = parseInt(window.location.href.split("/")[4]); window.location.href=("/search?searchtoken=hp&searchterm="+term+"&categorysearch="+cat); } KDK.extractFirstText = function(str){ const matches = str.match(/"(.*?)"/); return matches ? matches[1] : str; }; KDK.hideSearch = function() { $("#kk_blk_overlay").css("display","none"); $("#searchbox").css("visibility","hidden"); }; KDK.imageError = function(obj) { obj.src = "/images/error_image.png"; }; KDK.no_blank_contact = function() { let contact_name = document.getElementById("contact_name").value.length; let email_length = document.getElementById("contact_email").value.length; let message_length = document.getElementById("contact_message").value.length; let the_at = document.getElementById("contact_email").value.indexOf("@"); if (contact_name < 5) { swal.fire("Please input your name. \n\n Thank you!"); return false; } if (email_length < 9 || the_at < 2) { swal.fire("Please input a correctly-formatted email address. \n\n Thanks!"); return false; } if (message_length < 20) { swal.fire("Please type your message (minimum 20 characters). \n\n Thank you!"); return false; } document.getElementById("wft_contact").submit(); }; KDK.no_empty_search = function() { 'use strict'; var input, form; input = document.getElementById("mainsearch"); form = document.getElementById("homepage_search"); if (input.value.toLowerCase() == "hp" || input.value.length > 2) { form.submit(); return true; } swal.fire("Please provide a search term of at least 3 characters. \n\n Thanks!"); return false; }; KDK.rotateHeros = function() { let fetchURL = SITEconfig.protocol+ SITEconfig.site_url+'/js/heros.json?'+SITEconfig.JS_timestamp; fetch(fetchURL) .then(function(response) { return response.json(); }).then (function(data) { //data has our data! var current_target, x, y, current_photo; x = 0; y = 0; current_target = document.getElementById('fullscreen').getAttribute("onclick").toString(); current_target = KDK.extractFirstText(current_target); while (x < data.urls.length) { //console.log("testing "+data.urls[x]+" against "+current_target); if (data.urls[x] == current_target) { let next_url = x+1; if (next_url >= data.urls.length) next_url = 0; document.getElementById("fullscreen").setAttribute("onclick",'window.location.href="'+data.urls[next_url]+'"'); break; } x++; } current_photo = document.getElementById('fullscreen').style.backgroundImage; current_photo = KDK.extractFirstText(current_photo); while (y < data.photos.length) { //console.log("testing "+data.photos[y]+" against "+current_photo); if (data.photos[y] == current_photo) { let next_pic = y+1; if (next_pic >= data.photos.length) next_pic = 0; document.getElementById("fullscreen").style.backgroundImage = "url('"+data.photos[next_pic]+"')"; break; } y++; } }); }; KDK.selectNavigate = function(element) { window.location.href = element.value; }; KDK.showSearch = function() { $("#kk_blk_overlay").css("display","block"); $("#searchbox").css("visibility","visible"); $("#mainsearch").focus(); }; KDK.toggleDropdown = function(which) { var ele; //console.log("Type: "+typeof(which)); //console.log("Value of which: "+which); ele = "#dropdown_"+which; let state = $(ele).css("visibility"); let change = "visible"; //console.log("Line 28, state is "+state+", ele is "+ele+" and change is "+change); if (state == change) { change = "hidden"; } $(ele).css("visibility", change); }; KDK.toggleBurger =function() { let ele = "#burgermenu"; let state = $(ele).css("visibility"); let change = "visible"; if (state == change) { change = "hidden"; } $(ele).css("visibility", change); }; KDK.updateCartHeaderImage = function(ct) { //console.log("updating Cart Header Image with qty "+ct); var img; img = "/images/icons/red_cart_"+ct+".png"; if (!ct) { img = "/images/icons/red_cart.png"; } if (ct >=10) { img = "/images/icons/red_cart_10.png"; } $('#cart_icon').attr('src', img); //update the mobile menu document.getElementById("mobile_cart_icon").style.display="block"; $("#mobile-cart-icon").attr('src', img); };