1(function () { 2 document.addEventListener("DOMContentLoaded", function () { 3 const wrappers = document.querySelectorAll(".cosmema-ki-search"); 4 wrappers.forEach(function (wrapper) { 5 initSearchForm(wrapper); 6 }); 7 }); 8 9 function initSearchForm(wrapper) { 10 if (wrapper.dataset.cosmemaInitialized === "true") return; 11 wrapper.dataset.cosmemaInitialized = "true"; 12 13 const instanceId = wrapper.getAttribute("data-instance-id"); 14 if (!instanceId) return; 15 16 const initialView = wrapper.getAttribute("data-initial-view") || "ki"; 17 const showSwitch = wrapper.getAttribute("data-show-switch") !== "0"; 18 19 const switchButton = wrapper.querySelector("#" + CSS.escape(instanceId + "-switch")); 20 const searchWrapper = wrapper.querySelector(".search-wrapper"); 21 const shortcodeWrapper = wrapper.querySelector("#" + CSS.escape(instanceId + "-shortcode")); 22 const input = wrapper.querySelector("#" + CSS.escape(instanceId + "-input")); 23 let isAIView = initialView === "ki"; 24 25 const i18n = window.cosmemaKiSearchI18n || {}; 26 27 if (isAIView) { 28 setupTypingEffect(input); 29 } 30 31 if (input) { 32 input.addEventListener("keydown", function (event) { 33 if (event.key === "Enter") { 34 event.preventDefault(); 35 cosmemaKiSearchSendMessage(input); 36 } 37 }); 38 } 39 40 if (switchButton && showSwitch) { 41 updateSwitchButtonText(switchButton, isAIView, i18n); 42 switchButton.addEventListener("click", function switchView() { 43 if (isAIView) { 44 searchWrapper.classList.add("hidden"); 45 shortcodeWrapper.classList.remove("hidden"); 46 } else { 47 searchWrapper.classList.remove("hidden"); 48 shortcodeWrapper.classList.add("hidden"); 49 } 50 isAIView = !isAIView; 51 updateSwitchButtonText(switchButton, isAIView, i18n); 52 }); 53 } 54 55 function updateSwitchButtonText(btn, aiView, i18n) { 56 const toNormal = i18n.switchToNormal || "Zur normalen Suche wechseln"; 57 const toAI = i18n.switchToAI || "Zur KI Suche wechseln"; 58 btn.innerText = aiView ? toNormal : toAI; 59 } 60 61 function setupTypingEffect(inputEl) { 62 if (!inputEl) return; 63 const messagesStr = inputEl.getAttribute("data-messages"); 64 if (!messagesStr) return; 65 const messages = messagesStr.split(";").filter(function (m) { 66 return m.trim().length > 0; 67 }); 68 if (messages.length === 0) return; 69 70 let messageIndex = 0; 71 let charIndex = 0; 72 const typingInterval = 40; 73 const erasingInterval = 10; 74 75 function type() { 76 if (charIndex < messages[messageIndex].length) { 77 inputEl.placeholder = messages[messageIndex].substring(0, charIndex + 1); 78 charIndex++; 79 setTimeout(type, typingInterval); 80 } else { 81 setTimeout(erase, 2000); 82 } 83 } 84 85 function erase() { 86 if (charIndex > 0) { 87 inputEl.placeholder = inputEl.placeholder.slice(0, -1); 88 charIndex--; 89 setTimeout(erase, erasingInterval); 90 } else { 91 inputEl.placeholder = ""; 92 messageIndex = (messageIndex + 1) % messages.length; 93 setTimeout(type, 500); 94 } 95 } 96 97 type(); 98 } 99 } 100 101 window.cosmemaKiSearchSendMessage = function (element) { 102 const wrapper = element.closest(".cosmema-ki-search"); 103 const instanceId = wrapper ? wrapper.getAttribute("data-instance-id") : null; 104 const input = wrapper && instanceId 105 ? wrapper.querySelector("#" + CSS.escape(instanceId + "-input")) 106 : null; 107 const message = input ? input.value.trim() : ""; 108 109 if (!message) { 110 return; 111 } 112 113 const borlabs = window.cosmemaKiSearchBorlabs; 114 if (borlabs && typeof borlabs.requestConsentAndSend === "function" && borlabs.isActive()) { 115 try { 116 borlabs.requestConsentAndSend(message); 117 } catch (error) { 118 console.error("cosmemaKiSearchSendMessage failed:", error); 119 } 120 return; 121 } 122 123 if (typeof window.neurabot === "undefined") { 124 console.error("window.neurabot is not defined."); 125 return; 126 } 127 128 if (typeof window.neurabot.openWindowAndTrySendMessage === "function") { 129 window.neurabot.openWindowAndTrySendMessage(message); 130 } else if (typeof window.neurabot.openWindowAndSendMessage === "function") { 131 window.neurabot.openWindowAndSendMessage(message); 132 } else { 133 console.error("window.neurabot.openWindowAndTrySendMessage and openWindowAndSendMessage are not available."); 134 } 135 }; 136})();
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.