%PDF- %PDF-
Direktori : /var/www/projetos/prod.jornalshowdafe.com.br/wp-content/themes/__betheme/js/ |
Current File : /var/www/projetos/prod.jornalshowdafe.com.br/wp-content/themes/__betheme/js/live-search.min.js |
var Mfn_livesearch={that:this,postsLoaded:[],dom:{ajaxFetchedPage:"",get resultsFromPage(){return this.ajaxFetchedPage},isItem:e=>e.target.closest(".mfn-live-search-wrapper"),itemAttr(e){const t=document.querySelector(".mfn-live-search-wrapper");return parseInt(t.getAttribute("data-"+e))},get searchForm(){return Array.from(document.querySelectorAll(".search_wrapper #searchform, .top_bar_right #searchform, #Side_slide #side-form, .mfn-live-search-wrapper .mfn-live-searchform"))},get searchField(){return Array.from(document.querySelectorAll(".search_wrapper input[type=text], .top_bar_right #searchform input[type=text], #Side_slide #side-form input[type=text], .mfn-live-search-wrapper input[type=text]"))},get liveSearchNoResults(){return Array.from(document.querySelectorAll(".mfn-live-search-box .mfn-live-search-noresults"))},get liveSearchBox(){return Array.from(document.querySelectorAll(".mfn-live-search-box"))},get liveSearchResultsList(){return Array.from(document.querySelectorAll(".mfn-live-search-list"))},get liveSearchResultsListShop(){return Array.from(document.querySelectorAll(".mfn-live-search-list-shop ul"))},get liveSearchResultsListBlog(){return Array.from(document.querySelectorAll(".mfn-live-search-list-blog ul"))},get liveSearchResultsListPortfolio(){return Array.from(document.querySelectorAll(".mfn-live-search-list-portfolio ul"))},get liveSearchResultsListPages(){return Array.from(document.querySelectorAll(".mfn-live-search-list-pages ul"))},get liveSearchResultsListCategories(){return Array.from(document.querySelectorAll(".mfn-live-search-list-categories ul"))}},create:{that:this,linkToLivesearch:e=>`${mfn.site_url}?s=${e}&mfn_livesearch`,Li:()=>document.createElement("li"),Heading:e=>e.querySelector(".post-title"),Link:e=>e.querySelector(".post-title a"),Excerpt:e=>e.querySelector(".post-excerpt p"),WooPrice:e=>e.querySelector(".post-product-price"),Image(e){const t=e.querySelector(".post-featured-image img");if(t){let e=document.createElement("img");return e.src=t.src,e}},Category(e){switch(!0){case e.classList.contains("product"):return"product";case e.classList.contains("page"):return"page";case e.classList.contains("portfolio"):return"portfolio";case e.classList.contains("post"):return"post"}},Textbox(e,t,r,s){let a=document.createElement("a"),i=document.createElement("p"),o=document.createElement("span"),l=document.createElement("div");if(l.classList.add("mfn-live-search-texts"),e.textContent&&t.href&&(a.innerHTML=e.textContent,a.href=t.href,l.appendChild(a)),s&&(o.innerHTML=s.innerHTML,l.appendChild(o)),null!=r&&r.textContent.match(/\w/)){let e="";const t=90,s=r.innerHTML;e=t>=s.length?s:`${s.substr(0,s.lastIndexOf(" ",t))}...`,i.innerHTML=e,l.appendChild(i)}return l},readyList(e){var t=this.that;let r=mfn.livesearch.loadPosts,s=t.Mfn_livesearch.dom.resultsFromPage;if(s=jQuery(s).find(".posts_group"),s.length){const[{children:e}]=s;Array.from(e).forEach((e=>{if(r>0){let r=this.Li();this.postId=e.id.match(/\d+/g).toString(),_.isObject(this.Image(e))&&r.appendChild(this.Image(e));const s=this.Textbox(this.Heading(e),this.Link(e),this.Excerpt(e),this.WooPrice(e));r.setAttribute("data-category",this.Category(e)),r.appendChild(s),t.Mfn_livesearch.postsLoaded.push(r)}r--}))}else e.target.value.length&&!t.Mfn_livesearch.postsLoaded.length&&jQuery(t.Mfn_livesearch.dom.liveSearchNoResults).fadeIn()},categoryPills(e){var t=this.that;if(mfn_livesearch_categories){const r=new RegExp(`[a-zA-Z]*${e}[a-zA-Z]*`,"gi");Object.values(mfn_livesearch_categories).filter((function(e){return e.match(r)})).forEach((e=>{let r=this.Li();r.setAttribute("data-category","category");let s=document.createElement("a");s.innerHTML=e,s.href=Object.keys(mfn_livesearch_categories).find((t=>mfn_livesearch_categories[t]===e)),r.appendChild(s),t.Mfn_livesearch.postsLoaded.push(r)}))}}},ajaxSearch(e,t){let r=null!==e.Mfn_livesearch.dom.isItem(t)?e.Mfn_livesearch.dom.itemAttr("char"):mfn.livesearch.minChar;if(t.target.value.length>=r){jQuery(e.Mfn_livesearch.dom.searchForm).addClass("mfn-livesearch-loading");let r=t.target.value.trim();jQuery.ajax({url:this.Mfn_livesearch.create.linkToLivesearch(r),type:"GET",success:function(r){e.Mfn_livesearch.dom.ajaxFetchedPage=r,setTimeout((function(){jQuery(e.Mfn_livesearch.dom.searchForm).removeClass("mfn-livesearch-loading"),e.Mfn_livesearch.postsLoaded=[],jQuery(e.Mfn_livesearch.dom.liveSearchNoResults).fadeOut(),e.Mfn_livesearch.create.categoryPills(t.target.value),e.Mfn_livesearch.create.readyList(t),e.Mfn_livesearch.refreshCategoryContainers(),e.Mfn_livesearch.assignToProperContainer(e.Mfn_livesearch.postsLoaded),e.Mfn_livesearch.hideNotUsedCategories(),e.Mfn_livesearch.toggleDropdown(t),e.Mfn_livesearch.toggleMoreResultsButton(t)}),0)}})}else e.Mfn_livesearch.toggleDropdown(t)},refreshCategoryContainers(){const e=this.that.Mfn_livesearch.dom,{pages:t,categories:r,portfolio:s,post:a,products:i}=mfn.livesearch.translation;jQuery(e.liveSearchResultsListShop).html(`<li data-category="info"> ${i} </li>`),jQuery(e.liveSearchResultsListPages).html(`<li data-category="info"> ${t} </li>`),jQuery(e.liveSearchResultsListPortfolio).html(`<li data-category="info"> ${s} </li>`),jQuery(e.liveSearchResultsListBlog).html(`<li data-category="info"> ${a} </li>`),jQuery(e.liveSearchResultsListCategories).html(`<li data-category="info"> ${r} </li>`)},assignToProperContainer(e){var t=this.that;e.forEach((e=>{switch(e.getAttribute("data-category")){case"product":jQuery(t.Mfn_livesearch.dom.liveSearchResultsListShop).append(e);break;case"page":jQuery(t.Mfn_livesearch.dom.liveSearchResultsListPages).append(e);break;case"portfolio":jQuery(t.Mfn_livesearch.dom.liveSearchResultsListPortfolio).append(e);break;case"post":jQuery(t.Mfn_livesearch.dom.liveSearchResultsListBlog).append(e);break;case"category":jQuery(t.Mfn_livesearch.dom.liveSearchResultsListCategories).append(e)}}))},hideNotUsedCategories(){this.that.Mfn_livesearch.dom.liveSearchResultsList.forEach((e=>{Array.from(e.children).forEach((e=>{1===e.querySelectorAll("ul li[data-category]").length?e.style.display="none":e.style.display="block"}))}))},toggleDropdown(e){let t,r=null!==this.that.Mfn_livesearch.dom.isItem(e)?this.that.Mfn_livesearch.dom.itemAttr("char"):mfn.livesearch.minChar;if(this.dom.isItem(e)){if(t=document.querySelector(".mfn-live-search-wrapper .mfn-live-search-box"),!this.dom.itemAttr("featured")){const e=document.querySelectorAll(".mfn-live-search-wrapper img");Array.from(e).forEach((e=>{e.style.display="none"}))}}else document.querySelector("#Side_slide")&&"0px"===document.querySelector("#Side_slide").style.right?t=document.querySelector("#Side_slide .mfn-live-search-box"):document.querySelector(".search_wrapper")&&"block"===document.querySelector(".search_wrapper").style.display?t=document.querySelector(".search_wrapper .mfn-live-search-box"):document.querySelector(".mfn-header-tmpl")?(t=jQuery(".search_wrapper input:focus").closest(".search_wrapper").find(".mfn-live-search-box"),jQuery(".search_wrapper input:focus").closest(".mcb-wrap").css("z-index",3)):t=document.querySelector(".top_bar_right .mfn-live-search-box");if(e.target.value.length<r)return jQuery(t).slideUp(300);jQuery(t).slideDown(300)},toggleMoreResultsButton(e){this.dom.liveSearchBox.forEach((t=>{const r=t.querySelector("a.button"),s=mfn.livesearch.loadPosts;this.postsLoaded.length>=s&&this.postsLoaded.length?(r.classList.remove("hidden"),r.href=this.create.linkToLivesearch(e.target.value)):r.classList.add("hidden")}))},closeBoxOnClick(){this.dom.searchForm.forEach((e=>{"none"!==jQuery(e).siblings(".mfn-live-search-box").css("display")||jQuery(e).closest(".mfn-loaded").length?e.setAttribute("mfn-livesearch-dropdown",!0):e.setAttribute("mfn-livesearch-dropdown",!1)}));let e=jQuery("[mfn-livesearch-dropdown=true]");e.closest(".mfn-loaded").length?(jQuery(e).find(".icon_close").click(),e.attr("mfn-livesearch-dropdown",!1)):(jQuery(e).find(".mfn-live-search-box").fadeOut(300),jQuery(e).siblings(".mfn-live-search-box").fadeOut(300)),this.refreshCategoryContainers(),this.hideNotUsedCategories(),e.siblings(".mfn-live-search-box").find(".button").addClass("hidden"),e.closest(".mcb-wrap").css("z-index",1)},events(){var e=_.debounce(this.ajaxSearch,300);this.dom.searchForm.forEach((e=>{e.addEventListener("submit",(e=>{e.preventDefault();const{value:t}=e.target.querySelector(".field");window.location.href=this.create.linkToLivesearch(t)}))})),document.addEventListener("keyup",(e=>{"Escape"===e.key&&(this.closeBoxOnClick(),e.stopPropagation())})),this.dom.searchField.forEach((t=>{t.addEventListener("click",(t=>{e(this.that,t)})),t.addEventListener("input",(t=>e(this.that,t))),t.addEventListener("click",(e=>{this.that.Mfn_livesearch.dom.isItem(e)?jQuery(".search_wrapper .mfn-live-search-box, .top_bar_right .mfn-live-search-box, #Side_slide .mfn-live-search-box").slideUp(300):(jQuery(".mfn-live-search-wrapper .mfn-live-search-box").slideUp(300),e.stopPropagation())}))})),this.dom.liveSearchBox.forEach((e=>{e.addEventListener("click",(e=>e.stopPropagation()))})),document.addEventListener("click",(e=>{this.closeBoxOnClick()}))},init(){this.events()}};Mfn_livesearch.init();