PageSourceSearch

https://alstertouristik.de/wp-content/plugins/travelmanager-buchungssoftware/js/chatbot.js?ver=7.1.2

js alstertouristik.de collected 2026-09-24 22:46:18 UTC 5,584 bytes, 158 lines download raw bytes

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

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.