(function($){jQuery('document').ready(function($){var finalTemplate=$('#pfd-search-result-template'),outputTemplate=_.template(finalTemplate.html()),wrapper='#search-wrapper',resultList='#result-list',results='#search-results',searchLoader='#search-loading',searchInput='#search-input',notice='.pf-docs-helper',endPointError=pf_docs_search.end_point_error,errorDiv=".pf-docs-error-results-wrap",remote_url=$(searchInput).data('remote-url'),typingTimer,doneTypingInterval=4000;request_status='';var search_page=$('.search_page').val();init();function init(){$(searchInput).on('keyup',function(event){if(event.keyCode===13){processSearchResults(!1)}});$(searchInput).on('click',function(event){if(!$('.pf-docs-search-results-wrap').hasClass('pf-docs-show')){processSearchResults(!1)}});$('.pf-docs-search-container .pf-svg-search').on('click',function(event){processSearchResults(!1)});$(searchInput).on('keyup',function(event){if(event.keyCode!==13){clearTimeout(typingTimer);processSearchResults(!1,event);typingTimer=setTimeout(function(){doneTyping(event)},doneTypingInterval)}});$(searchInput).on('keydown',function(){clearTimeout(typingTimer)});function doneTyping(event){val=$.trim($(searchInput).val()) if(request_status!=''&&val.length>=3){searchResultUpdateInDb(val,request_status)}}} function processSearchResults(updateDatabase=!0,event=''){let subtype='subtype[]=docs';let source=[];if(typeof pfd_option.pfd_post_type!='undefined'){let post_types=[];source=pfd_option.pfd_post_type.split(',');source.forEach((type)=>{post_types.push('subtype[]='+type.trim())}) subtype=post_types.join('&')} var key=event.which,that=$(searchInput),val=$.trim($(searchInput).val()),valIs=val==$(that).val(),notEmpty=''!==val,type=$(searchInput).data('object-type'),max=$(wrapper).data('number'),url=remote_url+'/wp-json/wp/v2/search?'+subtype+'&search='+val+'&per_page='+max+'&orderby=relevance&order=asc';if(!valIs&&!notEmpty){return!1} $(results).parent().addClass('pf-docs-hide').removeClass('pf-docs-show');if(val==''){destroySearch(1)}else if(val.length==2){destroySearch();$('.search-results-text,.no-search-results-text').removeClass('pf-docs-show').addClass('pf-docs-hide');$(results).parent().addClass('pf-docs-show').removeClass('pf-docs-hide');$('.pf-docs-helper').removeClass('pf-docs-hide').addClass('pf-docs-show')} if(val.length>=3){$('.pf-docs-helper,.pf-svg-search').addClass('pf-docs-hide').removeClass('pf-docs-show');$(searchLoader).removeClass('pf-docs-hide').addClass('pf-docs-show');var jqxhr=$.getJSON(url,function(response){$(resultList).children().remove();$(resultList).removeClass('rs-full').addClass('rs-empty');$(searchLoader).removeClass('pf-docs-show').addClass('pf-docs-hide');$('.pf-svg-search').addClass('pf-docs-show').removeClass('pf-docs-hide');if(response.length==0){$(results).closest(wrapper).addClass('pf-docs-no-results');$(results).find('.no-search-results-text').removeClass('pf-docs-hide');$(results).find('.search-results-text').addClass('pf-docs-hide');request_status='fail'}else{$(results).closest(wrapper).removeClass('pf-docs-no-results');$(results).find('.search-results-text').removeClass('pf-docs-hide');$(results).find('.no-search-results-text').addClass('pf-docs-hide');grouped_results=group_posts(response,'subtype');source.forEach((type)=>{heading=type;if(type=='post'){heading='Blog Posts'} if(typeof grouped_results[type]!=='undefined'&&grouped_results[type].length>0){$(resultList).append("