-
Notifications
You must be signed in to change notification settings - Fork 3
/
chat.html
152 lines (123 loc) · 2.79 KB
/
chat.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
<style>
.chat {
position: fixed;
bottom: 0;
z-index: 1000;
right: 2rem;
width: 16rem;
height: 22rem;
background-color: #EEEEEE;
border: 2px solid rgb(51, 51, 51);
/* rgb(198, 156, 109); */
border-bottom: none;
font-family: 'Arial';
border-radius: 0.5rem 0.5rem 0 0;
overflow: hidden;
transition: all 0.2s;
}
.chat.hidden {
bottom: -20.5rem;
}
.heading {
width: 100%;
text-align: center;
color: white;
height: 1.5rem;
line-height: 1.5rem;
background-color: rgb(51, 51, 51);
position: relative;
cursor: pointer;
}
i.indicator {
display: inline-block;
position: absolute;
height: 0.75rem;
width: 0.75rem;
background-color: #CDDC39;
border-radius: 0.75rem;
float: right;
top: 0.375rem;
right: 0.375rem;
}
.input {
display: block;
position: absolute;
bottom: 0;
width: 100%;
background-color: #EFEFEF
padding: 0.25rem;
border-top: 1px solid rgb(198, 156, 109);
}
input {
background-color: white;
width: 100%;
padding: 1rem;
height: 2rem;
border: none;
font-size: 1rem;
outline: none;
}
input:foucs {
outline: none;
}
.messages {
overflow-y: scroll;
padding: 1rem;
margin-bottom: 2rem;
max-height: 16.5rem;
}
.message {
background-color: #B2DFDB;
padding: 0.25rem;
border-radius: 0.25rem;
margin-bottom: 0.25rem;
text-align: right;
text-overflow: ellipsis;
overflow: hidden;
}
.message.server {
background-color: rgba(198, 156, 109, 0.2);
text-align: left;
}
</style>
<div class="chat hidden" id="chatbot">
<div class="heading" id="chatHeading">Bec
<i class="indicator"></i>
</div>
<div class="messages" id="messages">
</div>
<form id="chatForm">
<div class="input">
<input type="text" placeholder="Message" id="chatbotInput">
</div>
</form>
</div>
<script>
window.ws = new WebSocket("ws://localhost:8888/ws/");
ws.onmessage = (message) => {
window.lastMessage = message;
let messageLM = document.createElement("div");
messageLM.textContent = message.data;
messageLM.classList.add("message", "server");
messages.appendChild(messageLM)
messageLM.scrollIntoView(true);
updateScroll()
}
function send_message(theMessage){
ws.send(theMessage);
}
chatHeading.onclick = (ev) => {
chatbot.classList.toggle('hidden');
}
chatForm.onsubmit = (ev) => {
ev.preventDefault();
send_message(chatbotInput.value);
let messageLM = document.createElement("div");
messageLM.textContent = chatbotInput.value;
messageLM.classList.add("message");
chatbotInput.value = "";
messages.appendChild(messageLM);
messageLM.scrollIntoView(true);
updateScroll()
}
</script>