1(function(){"use strict";console.log("Typesense: Script caricato per Stile");function getSearchApiUrl(){var pathname=window.location.pathname;var hasStaging=pathname.startsWith("/staging/");var contextPath="";if(window.APP_CONFIG&&window.APP_CONFIG.contextPath!==undefined&&window.APP_CONFIG.contextPath!==null){contextPath=window.APP_CONFIG.contextPath;if(contextPath==="/"){contextPath=""}if(!hasStaging&&contextPath.indexOf("/staging")!==-1){contextPath=contextPath.replace("/staging","")}else if(hasStaging&&contextPath.indexOf("/staging")===-1){contextPath="/staging"+(contextPath.startsWith("/")?contextPath:"/"+contextPath)}}else{console.warn("Typesense: APP_CONFIG.contextPath non disponibile, uso fallback dal pathname");if(hasStaging){var parts=pathname.split("/").filter(function(p){return p&&p!=="staging"});if(parts.length>0){contextPath="/staging/"+parts[0]}else{contextPath="/staging"}}else{contextPath=""}}var finalUrl=contextPath+"/common/pages/searchTypesense.jsp";console.log("Typesense: contextPath:",contextPath,"â URL:",finalUrl);return finalUrl}const MIN_QUERY_LENGTH=2;const DEBOUNCE_DELAY=300;const MAX_SUGGESTIONS=10;let searchTimeout=null;let currentRequest=null;let activeInput=null;function initAutocomplete(inputId,suggestionsContainerId){const input=document.getElementById(inputId);const container=document.getElementById(suggestionsContainerId);if(!input||!container){console.warn("Typesense: Elementi non trovati - inputId:",inputId,"containerId:",suggestionsContainerId);return}container._userSelectedSuggestion=false;console.log("Typesense: Inizializzazione autocomplete per",inputId);input.addEventListener("input",function(){handleInput(input,container)});input.addEventListener("focus",function(){if(input.value.length>=MIN_QUERY_LENGTH){handleInput(input,container)}});input.addEventListener("blur",function(){setTimeout(function(){hideSuggestions(container)},200)});input.addEventListener("keydown",function(e){handleKeydown(e,input,container)});const form=input.closest("form");if(form){console.log("Typesense: Aggiunto listener submit per form di",inputId);form.addEventListener("submit",function(e){const selected=container.querySelector(".suggestion-item.active");if(selected&&container._userSelectedSuggestion){e.preventDefault();const url=selected.getAttribute("data-url");if(url&&url!=="#"){window.location.href=url}}})}else{console.warn("Typesense: Form non trovato per input",inputId)}}function handleInput(input,container){const query=input.value.trim();if(searchTimeout){clearTimeout(searchTimeout)}if(query.length<MIN_QUERY_LENGTH){hideSuggestions(container);return}searchTimeout=setTimeout(function(){console.log("Typesense: Eseguo ricerca per query:",query);performSearch(query,input,container)},DEBOUNCE_DELAY)}function performSearch(query,input,container){if(currentRequest){currentRequest.abort()}activeInput=input;showLoading(container);const url=getSearchApiUrl()+"?q="+encodeURIComponent(query)+"&per_page="+MAX_SUGGESTIONS;console.log("Typesense: URL ricerca:",url);const xhr=new XMLHttpRequest;currentRequest=xhr;xhr.open("GET",url,true);xhr.setRequestHeader("Accept","application/json");xhr.onload=function(){if(xhr.status===200){try{const data=JSON.parse(xhr.responseText);displaySuggestions(data,container,query)}catch(e){console.error("Errore parsing risposta Typesense:",e);hideSuggestions(container)}}else if(xhr.status===404){console.warn("Typesense: 404, provo URL alternativo");var altUrl=url;if(url.indexOf("/staging/")!==-1){altUrl=url.replace("/staging/","/")}else{var pathname=window.location.pathname;if(pathname.startsWith("/staging/")){var baseUrl=url.substring(0,url.indexOf("/common"));altUrl=baseUrl.replace(/^\/(turismo|stile|consigli)/,"/staging/$1")+url.substring(url.indexOf("/common"))}}if(altUrl!==url){console.log("Typesense: Provo URL alternativo:",altUrl);var xhr2=new XMLHttpRequest;xhr2.open("GET",altUrl,true);xhr2.setRequestHeader("Accept","application/json");xhr2.onload=function(){if(xhr2.status===200){try{const data=JSON.parse(xhr2.responseText);displaySuggestions(data,container,query)}catch(e){console.error("Errore parsing risposta Typesense (fallback):",e);hideSuggestions(container)}}else{console.error("Errore ricerca Typesense (fallback):",xhr2.status);hideSuggestions(container)}currentRequest=null};xhr2.onerror=function(){console.error("Errore network ricerca Typesense (fallback)");hideSuggestions(container);currentRequest=null};xhr2.send();currentRequest=xhr2;return}console.error("Errore ricerca Typesense: 404");hideSuggestions(container)}
1else if(xhr.status===503){hideSuggestions(container)}else{console.error("Errore ricerca Typesense:",xhr.status);hideSuggestions(container)}currentRequest=null};xhr.onerror=function(){console.error("Errore network ricerca Typesense");hideSuggestions(container);currentRequest=null};xhr.send()}function displaySuggestions(data,container,query){console.log("Typesense: displaySuggestions chiamato, data:",data);container.innerHTML="";container._userSelectedSuggestion=false;if(!data||!data.hits||data.hits.length===0){console.log("Typesense: Nessun risultato trovato");container.innerHTML='<div class="suggestion-item suggestion-no-results">Nessun risultato trovato</div>';container.classList.add("show");return}console.log("Typesense: Trovati",data.hits.length,"risultati");data.hits.forEach(function(hit,index){const doc=hit.document;const item=createSuggestionItem(doc,hit,query,index===0);container.appendChild(item)});container.classList.add("show");console.log("Typesense: Suggerimenti mostrati, container ha classe show:",container.classList.contains("show"))}function createSuggestionItem(doc,hit,query,isFirst){const item=document.createElement("div");item.className="suggestion-item"+(isFirst?" active":"");item.setAttribute("data-url",doc.url||"#");item.setAttribute("tabindex","0");item.setAttribute("role","option");let title=doc.title||"";if(hit&&hit.highlights&&hit.highlights.length>0){title=hit.highlights[0].snippet}else{title=highlightQuery(title,query)}let html='<div class="suggestion-content">';if(doc.image_url){html+='<img src="'+escapeHtml(doc.image_url)+'" alt="" class="suggestion-image" loading="lazy">'}html+='<div class="suggestion-text">';html+='<div class="suggestion-title">'+title+"</div>";if(doc.meta_description){const desc=truncate(doc.meta_description,80);html+='<div class="suggestion-description">'+escapeHtml(desc)+"</div>"}html+="</div>";html+="</div>";item.innerHTML=html;item.addEventListener("click",function(){const c=item.closest(".search-suggestions");if(c)c._userSelectedSuggestion=true;window.location.href=doc.url||"#"});item.addEventListener("mouseenter",function(){const parentContainer=item.closest(".search-suggestions");if(parentContainer){parentContainer.querySelectorAll(".suggestion-item").forEach(function(el){el.classList.remove("active")})}item.classList.add("active")});return item}function highlightQuery(text,query){if(!query||!text)return escapeHtml(text);const regex=new RegExp("("+escapeRegex(query)+")","gi");return escapeHtml(text).replace(regex,"<mark>$1</mark>")}function showLoading(container){container.innerHTML='<div class="suggestion-item suggestion-loading">Ricerca in corso...</div>';container.classList.add("show")}function hideSuggestions(container){container._userSelectedSuggestion=false;container.classList.remove("show");container.innerHTML=""}function handleKeydown(e,input,container){const items=container.querySelectorAll(".suggestion-item:not(.suggestion-no-results):not(.suggestion-loading)");const active=container.querySelector(".suggestion-item.active");let currentIndex=-1;if(active){currentIndex=Array.from(items).indexOf(active)}if(e.key==="ArrowDown"){e.preventDefault();if(currentIndex<items.length-1){container._userSelectedSuggestion=true;if(active)active.classList.remove("active");items[currentIndex+1].classList.add("active");items[currentIndex+1].scrollIntoView({block:"nearest"})}}else if(e.key==="ArrowUp"){e.preventDefault();if(currentIndex>0){container._userSelectedSuggestion=true;if(active)active.classList.remove("active");items[currentIndex-1].classList.add("active");items[currentIndex-1].scrollIntoView({block:"nearest"})}else if(currentIndex===0){if(active)active.classList.remove("active");input.focus()}}else if(e.key==="Enter"){if(active&&active!==input&&container._userSelectedSuggestion){e.preventDefault();const url=active.getAttribute("data-url");if(url&&url!=="#"){window.location.href=url}}}else if(e.key==="Escape"){hideSuggestions(container);input.blur()}}function escapeHtml(text){const div=document.createElement("div");div.textContent=text;return div.innerHTML}function escapeRegex(text){return text.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function truncate(text,maxLength){if(!text||text.length<=maxLength)return text;return text.substring(0,maxLength)+"..."}if(document.readyState==="loading"){document.addEventListener("DOMContentLoaded",init)}else{init()}const initializedInputs=new Set;
1function init(){console.log("Typesense: Inizializzazione Stile...");const desktopInput=document.getElementById("search");const desktopContainer=document.getElementById("searchSuggestions");if(desktopInput&&desktopContainer){if(!initializedInputs.has("search")){console.log("Typesense: Trovati elementi desktop");initAutocomplete("search","searchSuggestions");initializedInputs.add("search")}}else{console.warn("Typesense: Elementi desktop non trovati (potrebbero essere nascosti)")}const mobileInput=document.getElementById("searchMobile");const mobileContainer=document.getElementById("searchSuggestionsMobile");if(mobileInput&&mobileContainer){if(!initializedInputs.has("searchMobile")){console.log("Typesense: Trovati elementi mobile");initAutocomplete("searchMobile","searchSuggestionsMobile");initializedInputs.add("searchMobile")}}else{console.warn("Typesense: Elementi mobile non trovati (potrebbero essere nascosti)")}}function tryInitWhenVisible(){console.log("Typesense: tryInitWhenVisible chiamato");const desktopForm=document.querySelector(".search-form");const desktopInput=document.getElementById("search");const desktopContainer=document.getElementById("searchSuggestions");if(desktopForm&&desktopInput&&desktopContainer){const isVisible=!desktopForm.classList.contains("d-none")&&(desktopForm.classList.contains("d-md-inline-flex")||desktopForm.style.display!=="none");console.log("Typesense: Form desktop visibile?",isVisible,"già inizializzato?",initializedInputs.has("search"));if(isVisible&&!initializedInputs.has("search")){console.log("Typesense: Form desktop ora visibile, inizializzo...");initAutocomplete("search","searchSuggestions");initializedInputs.add("search")}}const mobileSearchBox=document.getElementById("mobileSearchBox");const mobileInput=document.getElementById("searchMobile");const mobileContainer=document.getElementById("searchSuggestionsMobile");if(mobileSearchBox&&mobileInput&&mobileContainer){const isVisible=mobileSearchBox.style.display!=="none"&&mobileSearchBox.style.display!=="";console.log("Typesense: Form mobile visibile?",isVisible,"già inizializzato?",initializedInputs.has("searchMobile"));if(isVisible&&!initializedInputs.has("searchMobile")){console.log("Typesense: Form mobile ora visibile, inizializzo...");initAutocomplete("searchMobile","searchSuggestionsMobile");initializedInputs.add("searchMobile")}}}const observer=new MutationObserver(function(mutations){tryInitWhenVisible()});if(document.querySelector(".search-form")){observer.observe(document.querySelector(".search-form"),{attributes:true,attributeFilter:["class","style"]})}if(document.getElementById("mobileSearchBox")){observer.observe(document.getElementById("mobileSearchBox"),{attributes:true,attributeFilter:["style","class"]})}document.addEventListener("click",function(e){if(e.target.closest(".search-box .icon-search")||e.target.closest(".icon-search")||e.target.classList.contains("icon-search")){console.log("Typesense: Click sulla lente di ricerca rilevato");setTimeout(function(){tryInitWhenVisible()},200)}})})();
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.