-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1792640
commit e2d72f2
Showing
5 changed files
with
239 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,137 @@ | ||
/* General Reset */ | ||
* { | ||
margin: 0; | ||
padding: 0; | ||
box-sizing: border-box; | ||
font-family: Arial, sans-serif; | ||
} | ||
|
||
/* Chat Button */ | ||
.chat-button { | ||
position: fixed; | ||
bottom: 70px; | ||
right: 20px; | ||
background-color: #A31F34; | ||
color: white; | ||
padding: 10px 15px; | ||
border-radius: 50px; | ||
cursor: pointer; | ||
font-size: 16px; | ||
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2); | ||
z-index: 1000; | ||
display: flex; | ||
align-items: center; | ||
justify-content: center; | ||
} | ||
|
||
/* Chat Window */ | ||
.chat-window { | ||
position: fixed; | ||
bottom: 20px; | ||
right: 20px; | ||
width: 300px; | ||
height: 400px; | ||
background-color: white; | ||
border-radius: 10px; | ||
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2); | ||
z-index: 1001; | ||
display: none; /* Initially hidden */ | ||
flex-direction: column; | ||
overflow: hidden; | ||
} | ||
|
||
/* Chat Header */ | ||
.chat-header { | ||
background-color: #A31F34; | ||
color: white; | ||
padding: 10px; | ||
font-size: 18px; | ||
font-weight: bold; | ||
display: flex; | ||
justify-content: space-between; | ||
align-items: center; | ||
} | ||
|
||
/* Close Chat Button */ | ||
.close-chat { | ||
cursor: pointer; | ||
font-size: 20px; | ||
font-weight: bold; | ||
} | ||
|
||
/* Chat Body */ | ||
.chat-body { | ||
flex: 1; /* Ensures it takes up available space */ | ||
padding: 10px; | ||
overflow-y: auto; /* Enables vertical scrolling */ | ||
background-color: #f9f9f9; | ||
max-height: 300px; /* Limit the height of the chat body */ | ||
scrollbar-width: thin; /* Custom scrollbar for modern browsers */ | ||
scrollbar-color: #A31F34 #f9f9f9; | ||
} | ||
|
||
/* Optional: Styling for scrollbars in webkit browsers (Chrome, Safari) */ | ||
.chat-body::-webkit-scrollbar { | ||
width: 8px; /* Width of the scrollbar */ | ||
} | ||
|
||
.chat-body::-webkit-scrollbar-thumb { | ||
background-color: #A31F34; /* Color of the scrollbar thumb */ | ||
border-radius: 4px; /* Roundness of the scrollbar thumb */ | ||
} | ||
|
||
.chat-body::-webkit-scrollbar-track { | ||
background-color: #f9f9f9; /* Color of the scrollbar track */ | ||
} | ||
|
||
.bot-message { | ||
background-color: #e0e0e0; | ||
color: #333; | ||
padding: 10px; | ||
border-radius: 10px; | ||
margin: 5px 0; | ||
max-width: 80%; | ||
} | ||
|
||
.user-message { | ||
background-color: #A31F34; | ||
color: white; | ||
padding: 10px; | ||
border-radius: 10px; | ||
margin: 5px 0; | ||
max-width: 80%; | ||
align-self: flex-end; | ||
} | ||
|
||
/* Chat Footer */ | ||
.chat-footer { | ||
display: flex; | ||
border-top: 1px solid #ddd; | ||
position: absolute; | ||
bottom: 0; | ||
width: inherit; | ||
} | ||
|
||
.chat-input { | ||
flex: 1; | ||
border: none; | ||
padding: 10px; | ||
font-size: 14px; | ||
} | ||
|
||
.chat-input:focus { | ||
outline: none; | ||
} | ||
|
||
.send-button { | ||
background-color: #A31F34; | ||
color: white; | ||
border: none; | ||
padding: 10px 15px; | ||
cursor: pointer; | ||
font-size: 14px; | ||
} | ||
|
||
.send-button:hover { | ||
background-color: #A31F34; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,21 @@ | ||
<div> | ||
<button type="button" onclick="alert('Hello World!')">Hello World!</button> | ||
<!-- Chat Button --> | ||
<div class="chat-button"> | ||
Help me with this problem | ||
</div> | ||
|
||
<!-- Chat Window --> | ||
<div class="chat-window"> | ||
<div class="chat-header"> | ||
<span>MIT Teaching Assistant</span> | ||
<span class="close-chat">×</span> | ||
</div> | ||
<div class="chat-body"> | ||
<p class="bot-message">Hi! How can I assist you today?</p> | ||
</div> | ||
<div class="chat-footer"> | ||
<input type="text" class="chat-input" placeholder="Type your message here..."> | ||
<button class="send-button">Send</button> | ||
</div> | ||
</div> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
resources( | ||
name="ol_chat_js", | ||
sources=["src_js/*.js","lib/*.js"], | ||
sources=["*.js"], | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
function AiChatAsideView(runtime, element) { | ||
$('.chat-button').on('click', function () { | ||
$('.chat-window').fadeIn(); | ||
$('.chat-button').hide(); | ||
}); | ||
|
||
// Close chat window | ||
$('.close-chat').on('click', function () { | ||
$('.chat-window').fadeOut(); | ||
$('.chat-button').fadeIn(); | ||
}); | ||
|
||
// Send message | ||
function sendMessage() { | ||
const message = $('.chat-input').val().trim(); | ||
if (message !== '') { | ||
// Display user message | ||
const userMessage = $('<p>') | ||
.addClass('user-message') | ||
.text(message); | ||
$('.chat-body').append(userMessage); | ||
|
||
// Clear input field | ||
$('.chat-input').val(''); | ||
|
||
// Simulate bot response | ||
// setTimeout(() => { | ||
// const botMessage = $('<p>') | ||
// .addClass('bot-message') | ||
// .text('Thanks for reaching out! We will get back to you shortly.'); | ||
// $('.chat-body').append(botMessage); | ||
// | ||
// // Scroll to the bottom of the chat body | ||
// $('.chat-body').scrollTop($('.chat-body')[0].scrollHeight); | ||
// }, 1000); | ||
|
||
// Scroll to the bottom after user message | ||
$('.chat-body').scrollTop($('.chat-body')[0].scrollHeight); | ||
|
||
$.ajax({ | ||
type: "POST", | ||
url: runtime.handlerUrl(element, 'mock_handler'), | ||
data: JSON.stringify({"message": message}), | ||
success: function(resp) { | ||
console.log(resp.message) | ||
setTimeout(() => { | ||
const botMessage = $('<p>') | ||
.addClass('bot-message') | ||
.text(resp.message); | ||
$('.chat-body').append(botMessage); | ||
|
||
$('.chat-body').scrollTop($('.chat-body')[0].scrollHeight); | ||
}, 1000 | ||
); | ||
} | ||
}); | ||
} | ||
} | ||
|
||
// Send message on button click | ||
$('.send-button').on('click', sendMessage); | ||
|
||
// Send message on pressing Enter | ||
$('.chat-input').on('keypress', function (event) { | ||
if (event.which === 13) { | ||
sendMessage(); | ||
} | ||
}); | ||
} |