/*! * product-search.js * * Copyright (c) "kento" Karim Rahimpur www.itthinx.com * * This code is provided subject to the license granted. * Unauthorized use and distribution is prohibited. * See COPYRIGHT.txt and LICENSE.txt * * This code is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * * This header and all notices must be kept intact. * * @author itthinx * @package woocommerce-product-search * @since 1.0.0 */ ;var ixwps={doPost:true,blinkerTimeouts:[],blinkerTimeout:5000,xhr:null};(function(a){ixwps.inhibitEnter=function(b){a("#"+b).keydown(function(c){if(c.keyCode==13){c.preventDefault();return false}})};ixwps.dynamicFocus=function(d,c){var e=a("#"+d),b=a("#"+c);e.focusout(function(g){var f=a(this);setTimeout(function(){var h=(f.find(":focus").length>0);if(!h){b.hide()}},100)});e.focusin(function(h){var g=a(this),f=g.find("input.product-search-field");if(f.length>0){if(a(f[0]).val().length==0){b.html("")}}b.show()})};ixwps.navigate=function(c,b){a("#"+c).keydown(function(l){var j=0,g=false,n=false;switch(l.keyCode){case 37:break;case 39:break;case 38:j=-1;break;case 40:j=1;break;case 13:g=true;break;case 27:n=true;break}if(j!=0){var k=a("#"+b).find(".entry"),f=a("#"+b+" .entry.active").index();if(k.length>0){if(f>=0){a(k[f]).removeClass("active")}f+=j;if(f<0){f=k.length-1}else{if(f>=k.length){f=0}}a(k[f]).addClass("active");var h=k[f].offsetTop;a("#"+b).find(".product-search-results-content").first().prop("scrollTop",h)}l.preventDefault();return false}if(g){var k=a("#"+b).find(".entry"),f=a("#"+b+" .entry.active").index();if((f>=0)&&(f0){if(f>=0){a(k[f]).removeClass("active");a("#"+b).find(".product-search-results-content").first().prop("scrollTop",0)}}l.preventDefault();return false}})};ixwps.autoAdjust=function(d,c){var e=a("#"+d),b=a("#"+c);b.on("adjustWidth",function(g){g.stopPropagation();var f=e.outerWidth()-(b.outerWidth()-b.innerWidth());b.width(f)})};ixwps.productSearch=function(h,g,c,b,j,i){if(!ixwps.doPost){return}if(typeof i==="undefined"){i={}}var k=a("#"+c),e=a("#"+h),d=ixwps.blinkerTimeout;if(typeof i.blinkerTimeout!=="undefined"){d=i.blinkerTimeout}j=a.trim(j);if(j!=""){e.addClass("blinker");if(d>0){ixwps.blinkerTimeouts["#"+h]=setTimeout(function(){e.removeClass("blinker")},d)}var f={action:"product_search","product-search":1,"product-query":j};if(typeof i.lang!=="undefined"){f.lang=i.lang}a("#"+h).parent().find(".product-search-field-clear").hide();if(ixwps.xhr!==null){ixwps.xhr.abort()}ixwps.xhr=a.post(b,f,function(p){ixwps.xhr=null;var q="";if((p!==null)&&(p.length>0)){var v=null,n=true,u=true,t=true,m=true,o=true;if(typeof i.product_thumbnails!=="undefined"){n=i.product_thumbnails}if(typeof i.show_description!=="undefined"){u=i.show_description}if(typeof i.show_price!=="undefined"){t=i.show_price}if(typeof i.show_add_to_cart!=="undefined"){m=i.show_add_to_cart}if(typeof i.show_more!=="undefined"){o=i.show_more}q+='';for(var w in p){var s="";if(v!=p[w].type){v=p[w].type;s="first"}q+='';if(n&&v!="s_product_cat"&&v!="s_more"){q+='"}switch(v){case"s_more":if(o){q+='"}break;case"s_product_cat":q+='";break;default:q+='"}q+=""}q+="
';q+='';if(typeof p[w].thumbnail!=="undefined"){var l="",x="",r="";if(typeof p[w].thumbnail_alt!=="undefined"){r=' alt="'+p[w].thumbnail_alt+'" '}if(typeof p[w].thumbnail_width!=="undefined"){l=' width="'+p[w].thumbnail_width+'" '}if(typeof p[w].thumbnail_height!=="undefined"){x=' height="'+p[w].thumbnail_height+'" '}q+='"}q+="";q+="';q+='';q+=''+p[w].title+"";q+="";q+="';q+='';q+=''+p[w].title+"";q+="";q+="';q+='';q+=''+p[w].title+"";if(u){if(typeof p[w].description!=="undefined"){q+=''+p[w].description+""}}if(t){if(typeof p[w].price!=="undefined"){q+=''+p[w].price+""}}q+="";if(m){if(typeof p[w].add_to_cart!=="undefined"){q+='
'+p[w].add_to_cart+"
"}}q+="
"}else{if(typeof i.no_results!=="undefined"){if(i.no_results.length>0){q+='
';q+=i.no_results;q+="
"}}}k.show().html(q);ixwps.clickable(c);k.trigger("adjustWidth");e.removeClass("blinker");if(d>0){clearTimeout(ixwps.blinkerTimeouts["#"+h])}a("#"+h).parent().find(".product-search-field-clear").show()},"json")}else{k.hide().html("");a("#"+h).parent().find(".product-search-field-clear").hide()}};ixwps.clickable=function(b){a("#"+b+" table.search-results tr").click(function(d){if(!a(d.target).hasClass("add_to_cart_button")){var c=a(this).find("a").attr("href");if(c){window.location=c}}});a("#"+b+" table.search-results tr").css("cursor","pointer")};a(document).ready(function(){a(".product-search-form input.product-search-field").prop("disabled",false);a(document).on("click",".product-search-form .product-search-field-clear",function(){var b=a(this).parent().find("input.product-search-field");if(b.length>0){b.trigger("clear");b.closest(".product-search").find(".product-search-results-content").html("");if(b.closest(".product-search").find(".product-search-results-content").length===0){b.closest(".product-search").find(".product-search-results").html("")}a(this).hide()}})})})(jQuery);