1function tmOpenChatbot(obj) { 2 var dialoge = TMdialog(obj); 3 4 var title = dialoge['fahrplan_chatbot']; 5 var desc = dialoge['fahrplan_chatbot_desc']; 6 7 //Maximale Breite oder Bildschirmbreite minus 40px 8 var dialogWidth = Math.min(500, $(window).width() - 40); // 20px Abstand links und rechts 9 var dialogHeight = Math.min(600, $(window).height() - 40); // 20px Abstand oben und unten 10 11 // Chat-HTML erstellen 12 $("body").attr("chatbot_thread_id",""); 13 var $dialogContent = $('<div/>', { class: 'tm-chatbot-container' }).append( 14 $('<sub/>', { 15 text: desc, 16 }), 17 $('<div/>', { 18 class: 'chatbot-messages' 19 }), 20 $('<input/>', { 21 type: 'text', 22 class: 'tm-chatbot-input', 23 maxlength: 160 24 }), 25 $('<button/>', { 26 text: dialoge['senden'], 27 class: 'tm-chatbot-send-btn' 28 }) 29 ); 30 31 // Dialog öffnen 32 $dialogContent.dialog({ 33 title: title, 34 modal: true, 35 width:dialogWidth, 36 height: dialogHeight, 37 dialogClass: 'tm-chatbot-dialog', 38 open: function() { 39 if (window.TMstyleDialog) window.TMstyleDialog(this, obj); 40 41 $("body").css({ overflow: 'hidden' }); 42 43 // SchlieÃen-Button anpassen 44 $(this).parent().find(".ui-dialog-titlebar-close").html("â"); // oder Text/HTML/Icon deiner Wahl 45 46 // Chat-Ausgabebereich und Eingabeelemente referenzieren 47 var $messages = $(this).find('.chatbot-messages'); 48 var $input = $(this).find('.tm-chatbot-input'); 49 var $sendBtn = $(this).find('.tm-chatbot-send-btn'); 50 51 // Bei Enter -> Senden 52 $input.on('keypress', function(event) { 53 if (event.key === "Enter") { 54 event.preventDefault(); 55 $sendBtn.trigger("click"); 56 } 57 }); 58 59 function appendUserMessage(text) { 60 var $msg = $('<div/>').text((TMmodern(obj) ? dialoge.ich : 'Ich') + ': ' + text); 61 $messages.append($msg); 62 $messages.scrollTop($messages.prop('scrollHeight')); 63 } 64 65 // Bot-Nachrichten als HTML (Formatierungen erlauben) 66 function appendBotMessage(htmlContent) { 67 68 var html = htmlContent; 69 70 var $msg = $('<div/>').html(html); 71 $messages.append($msg); 72 $messages.scrollTop($messages.prop('scrollHeight')); 73 $sendBtn.removeAttr("disabled"); 74 $input.removeAttr("readonly").focus(); 75 } 76 77 function startLoading($btn, loadingText = dialoge["inhalt_laden"]) { 78 if ($btn.data('loading')) return; // schon im Ladezustand 79 $btn.data('loading', true); 80 $btn.prop('disabled', true); 81 // Originalinhalt sichern 82 if ($btn.data('original-html') === undefined) { 83 $btn.data('original-html', $btn.html()); 84 } 85 // Inhalt ersetzen/erweitern mit Spinner 86 $btn.html('<span class="tm-spinner"></span>' + loadingText); 87 } 88 89 function stopLoading($btn) { 90 if (!$btn.data('loading')) return; 91 $btn.data('loading', false); 92 $btn.prop('disabled', false); 93 // Originalinhalt wiederherstellen 94 const original = $btn.data('original-html'); 95 if (original !== undefined) { 96 $btn.html(original); 97 } 98 } 99 100 101 // Klick-Handler auf Senden-Button 102 $sendBtn.on('click', function() { 103 var userText = $input.val().trim(); 104 if (userText.length === 0) return; 105 106 // Eingabe im Chatfenster zeigen 107 appendUserMessage(userText); 108 109 // Eingabe sperren, bis Antwort da ist 110 $(".ui-button").first().focus(); 111 $input.val(''); 112 $input.attr("readonly", true); 113 $sendBtn.attr("disabled", true); 114 115 startLoading($sendBtn, dialoge['bitte_warten']); 116 117 var threadId = $("body").attr("chatbot_thread_id"); 118 119 var data = {}; 120 data['action'] = 'travelmanager_chatbot'; 121 data['thread_id'] = threadId; 122 data['question'] = encodeURIComponent(userText); 123 data['lang'] = TMlanguage(obj); 124 data["hash"]=jQuery(obj).attr("hash"); 125 126 TMpost(obj, data) 127 .done(function(response) { 128 if (response.answer) { 129 appendBotMessage(response.answer); 130 $("body").attr("chatbot_thread_id",response.thread_id); 131 132 } else { 133 appendBotMessage(TMmodern(obj) ? dialoge.invali
133d_response : "Keine oder unbekannte Antwort erhalten."); 134 } 135 }) 136 .fail(function(xhr) { 137 appendBotMessage(TMmodern(obj) ? dialoge.connection_failed : "Fehler bei der Anfrage: " + xhr.statusText); 138 }) 139 .always(function() { 140 stopLoading($sendBtn); 141 }); 142 }); 143 144 // Wenn 160 Zeichen erreicht sind -> Textfeld sperren 145 $input.on('input', function() { 146 if ($input.val().length >= 160) { 147 $input.attr('readonly', true); 148 } 149 }); 150 }, 151 close: function() { 152 $(this).dialog('destroy').remove(); 153 $("body").css({ overflow: 'auto' }); 154 } 155 }); 156 157 158 159 160}
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.