PageSourceSearch

https://www.bveg.de/wp-content/cache/autoptimize/autoptimize_singl…89c1c676d017ea36124ca4c5d11c3.php?ver=0.2.2

js bveg.de collected 2026-09-25 04:01:45 UTC 12,387 bytes, 63 lines download raw bytes

1(function(){'use strict';var DEBOUNCE_MS=150;var MIN_CHARS=2;var MAX_RESULTS=8;var CSRF_COOKIE='f2ts_csrf';var CSRF_HEADER='X-F2TS-CSRF';var AUTOCOMPLETE_URL_DEFAULT='/wp-json/f2ts/v1/autocomplete';var SUGGESTIONS_URL_DEFAULT='/wp-json/f2ts/v1/suggestions';function init(){var inputs=document.querySelectorAll('input[data-f2ts-autocomplete]');for(var i=0;i<inputs.length;i++){attachWidget(inputs[i]);}}
2function attachWidget(input){var debounceTimer=null;var dropdown=null;var activeIndex=-1;var hits=[];var suggestions=[];var lastQueryWasFull=false;var wrapper;var parent=input.parentNode;if(parent&&parent.classList&&parent.classList.contains('f2ts-autocomplete')){wrapper=parent;}else{wrapper=document.createElement('div');wrapper.className='f2ts-autocomplete';input.parentNode.insertBefore(wrapper,input);wrapper.appendChild(input);}
3input.setAttribute('role','combobox');input.setAttribute('aria-autocomplete','list');input.setAttribute('aria-haspopup','listbox');input.setAttribute('aria-expanded','false');input.setAttribute('aria-controls','f2ts-ac-listbox-'+randomId());input.setAttribute('autocomplete','off');dropdown=document.createElement('div');dropdown.className='f2ts-autocomplete__dropdown';dropdown.setAttribute('role','listbox');dropdown.id=input.getAttribute('aria-controls');dropdown.hidden=true;wrapper.appendChild(dropdown);var liveRegion=document.createElement('div');liveRegion.className='f2ts-autocomplete__sr-status';liveRegion.setAttribute('role','status');liveRegion.setAttribute('aria-live','polite');liveRegion.setAttribute('aria-atomic','true');wrapper.appendChild(liveRegion);input.addEventListener('input',onInput);input.addEventListener('keydown',onKeyDown);input.addEventListener('focus',onFocus);wrapper.addEventListener('focusout',function(e){setTimeout(function(){if(!wrapper.contains(document.activeElement)){closeDropdown();}},150);});function onFocus(){var q=input.value.trim();if(q.length===0){fetchSuggestions('');}else if(hits.length>0||suggestions.length>0){openDropdown();}}
4function onInput(e){var q=e.target.value.trim();clearTimeout(debounceTimer);if(q.length===0){hits=[];lastQueryWasFull=false;debounceTimer=setTimeout(function(){fetchSuggestions('');},DEBOUNCE_MS);return;}
5if(q.length<MIN_CHARS){hits=[];lastQueryWasFull=false;debounceTimer=setTimeout(function(){fetchSuggestions(q);},DEBOUNCE_MS);return;}
6lastQueryWasFull=true;debounceTimer=setTimeout(function(){fetchHits(q);fetchSuggestions(q);},DEBOUNCE_MS);}
7function onKeyDown(e){if(dropdown.hidden||totalSelectable()===0)return;switch(e.key){case'ArrowDown':e.preventDefault();activeIndex=Math.min(activeIndex+1,totalSelectable()-1);updateActive();break;case'ArrowUp':e.preventDefault();activeIndex=Math.max(activeIndex-1,-1);updateActive();break;case'Enter':if(activeIndex>=0&&activeIndex<totalSelectable()){e.preventDefault();selectIndex(activeIndex);}
8break;case'Escape':e.preventDefault();closeDropdown();break;}}
9function hasSearchFooter(){return lastQueryWasFull&&input.value.trim().length>=MIN_CHARS;}
10function totalSelectable(){return suggestions.length+hits.length+(hasSearchFooter()?1:0);}
11function selectIndex(i){if(i<suggestions.length){submitWithQuery(suggestions[i].term);return;}
12if(i<suggestions.length+hits.length){selectHit(hits[i-suggestions.length]);return;}
13submitHostForm();}
14function buildHeaders(){var headers={'Accept':'application/json'};var csrf=ensureCsrfToken();if(csrf){headers[CSRF_HEADER]=csrf;}
15if(window.f2tsAutocompleteConfig&&window.f2tsAutocompleteConfig.nonce){headers['X-WP-Nonce']=window.f2tsAutocompleteConfig.nonce;}
16return headers;}
17function ensureCsrfToken(){var token=readCookie(CSRF_COOKIE);if(token){return token;}
18try{if(window.localStorage){var stored=window.localStorage.getItem(CSRF_COOKIE);if(stored&&/^[0-9a-f]{32,}$/i.test(stored)){writeCsrfCookie(stored);return stored;}}}catch(e){}
19if(typeof crypto!=='undefined'&&crypto.getRandomValues){var bytes=new Uint8Array(16);crypto.getRandomValues(bytes);token=Array.prototype.map.call(bytes,function(b){return('0'+b.toString(16)).slice(-2);}).join('');}else{token='';for(var i=0;i<32;i++){token+=Math.floor(Math.random()*16).toString(16);}}
20try{if(window.localStorage){window.localStorage.setItem(CSRF_COOKIE,token);}}catch(e){}
21writeCsrfCookie(token);return token;}
22function writeCsrfCookie(token){var attrs='; Path=/; SameSite=Lax';if(location.protocol==='https:'){attrs+='; Secure';}
23document.cookie=CSRF_COOKIE+'='+token+attrs;}
24function fetchHits(q){var url=(window.f2tsAutocompleteConfig&&window.f2tsAutocompleteConfig.endpoint)||AUTOCOMPLETE_URL_DEFAULT;var full=url+'?q='+encodeURIComponent(q);fetch(full,{credentials:'same-origin',headers:buildHeaders()}).then(function(res){return res.json();}).then(function(data){hits=(data&&data.hits)?data.hits.slice(0,MAX_RESULTS):[];activeIndex=-1;render();postFetchOpen();}).catch(function(){hits=[];render();postFetchOpen();});}
25function fetchSuggestions(q){var url=(window.f2tsAutocompleteConfig&&window.f2tsAutocompleteConfig.suggestionsEndpoint)||SUGGESTIONS_URL_DEFAULT;var full=url+'?q='+encodeURIComponent(q);fetch(full,{credentials:'same-origin',headers:buildHeaders()}).then(function(res){return res.json();}).then(function(data){suggestions=(data&&data.suggestions)?data.suggestions:[];activeIndex=-1;render();postFetchOpen();}).catch(function(){suggestions=[];render();postFetchOpen();});}
26function postFetchOpen(){if(totalSelectable()>0){openDropdown();return;}
27if(lastQueryWasFull){openDropdown();return;}
28closeDropdown();}
29function render(){dropdown.innerHTML='';announce();if(lastQueryWasFull&&suggestions.length===0&&hits.length===0){var empty=document.createElement('div');empty.className='f2ts-autocomplete__empty';empty.setAttribute('role','note');empty.textContent=labelForEmpty();dropdown.appendChild(empty);return;}
30if(suggestions.length>0){var suggestionsBlock=document.createElement('div');suggestionsBlock.className='f2ts-autocomplete__suggestions';var label=document.createElement('div');label.className='f2ts-autocomplete__suggestions-label';label.textContent=labelForSuggestions();suggestionsBlock.appendChild(label);var suggestionsList=document.createElement('ul');suggestionsList.className='f2ts-autocomplete__suggestions-list';suggestionsList.setAttribute('role','group');for(var i=0;i<suggestions.length;i++){var suggestion=suggestions[i];var suggestionItem=document.createElement('li');suggestionItem.className='f2ts-autocomplete__suggestion';suggestionItem.setAttribute('role','option');suggestionItem.id=dropdown.id+'-sugg-'+i;suggestionItem.dataset.index=String(i);suggestionItem.textContent=suggestion.term;(function(term){suggestionItem.addEventListener('mousedown',function(e){e.preventDefault();submitWithQuery(term);});})(suggestion.term);suggestionsList.appendChild(suggestionItem);}
31suggestionsBlock.appendChild(suggestionsList);dropdown.appendChild(suggestionsBlock);}
32if(hits.length>0){var hitsList=document.createElement('ul');hitsList.className='f2ts-autocomplete__hits';hitsList.setAttribute('role','group');for(var j=0;j<hits.length;j++){var hit=hits[j];hitsList.appendChild(renderHitItem(hit,suggestions.length+j));}
33dropdown.appendChild(hitsList);}
34if(lastQueryWasFull){var q=input.value.trim();if(q.length>=MIN_CHARS){var footer=renderSearchFooter(q,totalSelectable());dropdown.appendChild(footer);}}}
35function renderSearchFooter(q,linearIndex){var li=document.createElement('div');li.className='f2ts-autocomplete__footer';li.setAttribute('role','option');li.id=dropdown.id+'-footer';li.dataset.index=String(linearIndex);var label=document.createElement('span');label.className='f2ts-autocomplete__footer-label';var labelText=(window.f2tsAutocompleteConfig&&window.f2tsAutocompleteConfig.fullSearchLabel)||'Suche nach';label.textContent=labelText+' „'+q+'“';li.appendChild(label);li.addEventListener('mousedown',function(e){e.preventDefault();submitHostForm();});return li;}
36function submitHostForm(){var form=input.form;if(form){if(typeof form.requestSubmit==='function'){form.requestSubmit();}else{form.submit();}}}
37function renderHitItem(hit,linearIndex){var li=document.createElement('li');li.className='f2ts-autocomplete__item';li.setAttribute('role','option');li.id=dropdown.id+'-item-'+linearIndex;li.dataset.index=String(linearIndex);if(hit.thumbnail_url){var img=document.createElement('img');img.src=hit.thumbnail_url;img.alt='';img.className='f2ts-autocomplete__thumb';li.appendChild(img);}else{var placeholder=document.createElement('div');placeholder.className='f2ts-autocomplete__thumb f2ts-autocomplete__thumb--placeholder';placeholder.setAttribute('aria-hidden','true');li.appendChild(placeholder);}
38var text=document.createElement('div');text.className='f2ts-autocomplete__text';if(hit.overline){var overline=document.createElement('div');overline.className='f2ts-autocomplete__overline';overline.textContent=hit.overline;text.appendChild(overline);}
39var title=document.createElement('div');title.className='f2ts-autocomplete__title';title.textContent=hit.title||'';text.appendChild(title);var excerptText=hit.snippet?sanitizeMarkOnly(hit.snippet):'';if(!excerptText&&hit.excerpt){excerptText=escapeHtml(hit.excerpt);}
40if(excerptText){var excerpt=document.createElement('div');excerpt.className='f2ts-autocomplete__excerpt';excerpt.innerHTML=excerptText;text.appendChild(excerpt);}
41li.appendChild(text);(function(h){li.addEventListener('mousedown',function(e){e.preventDefault();selectHit(h);});})(hit);return li;}
42function updateActive(){var all=dropdown.querySelectorAll('[role="option"]');for(var i=0;i<all.length;i++){if(i===activeIndex){all[i].classList.add('f2ts-autocomplete__item--active');all[i].setAttribute('aria-selected','true');input.setAttribute('aria-activedescendant',all[i].id);if(all[i].scrollIntoView){all[i].scrollIntoView({block:'nearest'});}}else{all[i].classList.remove('f2ts-autocomplete__item--active');all[i].setAttribute('aria-selected','false');}}}
43function submitWithQuery(term){input.value=term;submitHostForm();}
44function selectHit(hit){if(hit&&hit.url){window.location.href=hit.url;}}
45function openDropdown(){dropdown.hidden=false;input.setAttribute('aria-expanded','true');}
46function closeDropdown(){dropdown.hidden=true;input.setAttribute('aria-expanded','false');input.removeAttribute('aria-activedescendant');activeIndex=-1;}
47function labelForSuggestions(){if(window.f2tsAutocompleteConfig&&window.f2tsAutocompleteConfig.suggestionsLabel){return String(window.f2tsAutocompleteConfig.suggestionsLabel);}
48return'Was andere suchen';}
49function labelForEmpty(){if(window.f2tsAutocompleteConfig&&window.f2tsAutocompleteConfig.emptyLabel){return String(window.f2tsAutocompleteConfig.emptyLabel);}
50return'Keine Treffer gefunden';}
51function announce(){var total=totalSelectable();var text;if(total===0){text=lastQueryWasFull?labelForEmpty():'';}else{var parts=[];if(suggestions.length===1){parts.push('1 Vorschlag');}else if(suggestions.length>1){parts.push(suggestions.length+' Vorschläge');}
52if(hits.length===1){parts.push('1 Ergebnis');}else if(hits.length>1){parts.push(hits.length+' Ergebnisse');}
53text=parts.join(', ');}
54if(liveRegion.textContent!==text){liveRegion.textContent=text;}}}
55function readCookie(name){if(!document.cookie)return'';var parts=document.cookie.split(';');for(var i=0;i<parts.length;i++){var cookie=parts[i].trim();if(cookie.indexOf(name+'=')===0){return decodeURIComponent(cookie.substring(name.length+1));}}
56return'';}
57function escapeHtml(str){if(str===null||str===undefined)return'';return String(str).replace(/&/g,'&amp;').replace(/</g,'&lt;').replace(/>/g,'&gt;').replace(/"/g,'&quot;').replace(/'/g,'&#39;');}
58function sanitizeMarkOnly(html){if(html===null||html===undefined||html==='')return'';var parser=document.createElement('div');parser.innerHTML=String(html);return walkNodes(parser);}
59function walkNodes(node){var out='';var children=node.childNodes;for(var i=0;i<children.length;i++){var child=children[i];if(child.nodeType===3){out+=escapeHtml(child.nodeValue||'');continue;}
60if(child.nodeType===1){var tag=child.nodeName.toLowerCase();if(tag==='mark'){out+='<mark>'+walkNodes(child)+'</mark>';}else{out+=walkNodes(child);}}}
61return out;}
62function randomId(){return Math.random().toString(36).substring(2,10);}
63window.f2tsAutocomplete={init:init,attachWidget:attachWidget};if(document.readyState==='loading'){document.addEventListener('DOMContentLoaded',init);}else{init();}})();

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.