// Collapsible var coll = document.getElementsByClassName("collapsible"); for (let i = 0; i < coll.length; i++) { coll[i].addEventListener("click", function () { this.classList.toggle("active"); var content = this.nextElementSibling; if (content.style.maxHeight) { content.style.maxHeight = null; } else { content.style.maxHeight = content.scrollHeight + "px"; } }); } function getTime() { let today = new Date(); hours = today.getHours(); minutes = today.getMinutes(); if (hours < 10) { hours = "0" + hours; } if (minutes < 10) { minutes = "0" + minutes; } let time = hours + ":" + minutes; return time; } // Gets the first message function firstBotMessage() { let firstMessage = "How's it going?" document.getElementById("botStarterMessage").innerHTML = '

' + firstMessage + '

'; let time = getTime(); $("#chat-timestamp").append(time); document.getElementById("userInput").scrollIntoView(false); } firstBotMessage(); // Retrieves the response function getHardResponse(userText) { let botResponse = getBotResponse(userText); let botHtml = '

' + botResponse + '

'; $("#chatbox").append(botHtml); document.getElementById("chat-bar-bottom").scrollIntoView(true); } //Gets the text text from the input box and processes it function getResponse() { let userText = $("#textInput").val(); if (userText == "") { userText = "I love Code Palace!"; } let userHtml = '

' + userText + '

'; $("#textInput").val(""); $("#chatbox").append(userHtml); document.getElementById("chat-bar-bottom").scrollIntoView(true); setTimeout(() => { getHardResponse(userText); }, 1000) } // Handles sending text via button clicks function buttonSendText(sampleText) { let userHtml = '

' + sampleText + '

'; $("#textInput").val(""); $("#chatbox").append(userHtml); document.getElementById("chat-bar-bottom").scrollIntoView(true); //Uncomment this if you want the bot to respond to this buttonSendText event // setTimeout(() => { // getHardResponse(sampleText); // }, 1000) } function sendButton() { getResponse(); } function heartButton() { buttonSendText("Heart clicked!") } // Press enter to send a message $("#textInput").keypress(function (e) { if (e.which == 13) { getResponse(); } });