-
Notifications
You must be signed in to change notification settings - Fork 0
/
live-group-chat.html
318 lines (286 loc) · 7.19 KB
/
live-group-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
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
<!DOCTYPE html>
<html>
<head>
<!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<!-- jQuery library -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<!-- Latest compiled JavaScript -->
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<link href='https://fonts.googleapis.com/css?family=Source+Sans+Pro:400,600,700,300' rel='stylesheet' type='text/css'>
<script>try{Typekit.load({ async: true });}catch(e){}</script>
<link rel='stylesheet prefetch' href='https://cdnjs.cloudflare.com/ajax/libs/meyer-reset/2.0/reset.min.css'><link rel='stylesheet prefetch' href='https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.6.2/css/font-awesome.min.css'>
<style class="cp-pen-styles">body {
display: flex;
align-items: center;
justify-content: center;
min-height: 100vh;
background: #2369a3;
font-family: "proxima-nova", "Source Sans Pro", sans-serif;
font-size: 2em;
letter-spacing: 0.1px;
color: #32465a;
text-rendering: optimizeLegibility;
text-shadow: 1px 1px 1px rgba(0, 0, 0, 0.004);
-webkit-font-smoothing: antialiased;
}
#frame {
width: 95%;
min-width: 360px;
max-width: 1000px;
height: 100vh;
min-height: 300px;
background: #E6EAEA;
}
@media screen and (max-width: 360px) {
#frame {
width: 100%;
height: 60vh;
}
}
#frame .content {
float: right;
width: 60%;
height: 100%;
overflow: hidden;
position: relative;
}
@media screen and (max-width: 735px) {
#frame .content {
width: calc(100% - 58px);
min-width: 300px !important;
}
}
@media screen and (min-width: 900px) {
#frame .content {
width: calc(100%);
}
}
#frame .content .contact-profile {
width: 100%;
height: 60px;
line-height: 60px;
background: #f5f5f5;
}
#frame .content .contact-profile img {
width: 40px;
border-radius: 50%;
float: left;
margin: 9px 12px 0 9px;
}
#frame .content .contact-profile p {
float: left;
}
#frame .content .messages {
height: auto;
min-height: calc(100% - 200px);
max-height: calc(100% - 200px);
overflow-y: scroll;
overflow-x: hidden;
}
@media screen and (max-width: 735px) {
#frame .content .messages {
max-height: calc(100% - 200px);
}
}
#frame .content .messages::-webkit-scrollbar {
width: 8px;
background: transparent;
}
#frame .content .messages::-webkit-scrollbar-thumb {
background-color: rgba(0, 0, 0, 0.3);
}
#frame .content .messages ul li {
display: inline-block;
clear: both;
float: left;
margin: 15px 15px 5px 15px;
width: calc(100% - 25px);
font-size: 2em;
}
#frame .content .messages ul li:nth-last-child(1) {
margin-bottom: 20px;
}
#frame .content .messages ul li.sent img {
margin: 6px 8px 0 0;
}
#frame .content .messages ul li.sent p {
background: #435f7a;
color: #f5f5f5;
}
#frame .content .messages ul li.replies img {
float: right;
margin: 6px 0 0 8px;
}
#frame .content .messages ul li.replies p {
background: #f5f5f5;
float: right;
}
#frame .content .messages ul li img {
width: 22px;
border-radius: 50%;
float: left;
}
#frame .content .messages ul li p {
display: inline-block;
padding: 10px 15px;
border-radius: 20px;
max-width: 205px;
line-height: 130%;
}
@media screen and (min-width: 735px) {
#frame .content .messages ul li p {
max-width: 300px;
}
}
#frame .content .message-input {
position: absolute;
bottom: 0;
width: 100%;
z-index: 99;
}
#frame .content .message-input .wrap {
position: relative;
}
#frame .content .message-input .wrap input {
font-family: "proxima-nova", "Source Sans Pro", sans-serif;
float: left;
border: none;
width: calc(100% - 50px);
padding: 11px 32px 10px 8px;
font-size: 1.5em;
color: #32465a;
}
@media screen and (max-width: 735px) {
#frame .content .message-input .wrap input {
padding: 15px 32px 16px 8px;
}
}
#frame .content .message-input .wrap input:focus {
outline: none;
}
#frame .content .message-input .wrap .attachment {
position: absolute;
right: 60px;
z-index: 4;
margin-top: 10px;
font-size: 1em;
color: #435f7a;
opacity: .5;
cursor: pointer;
}
@media screen and (max-width: 735px) {
#frame .content .message-input .wrap .attachment {
margin-top: 17px;
right: 65px;
}
}
#frame .content .message-input .wrap .attachment:hover {
opacity: 1;
}
#frame .content .message-input .wrap button {
float: right;
border: none;
width: 50px;
padding: 12px 0;
cursor: pointer;
background: #32465a;
color: #f5f5f5;
}
@media screen and (max-width: 735px) {
#frame .content .message-input .wrap button {
padding: 16px 0;
}
}
#frame .content .message-input .wrap button:hover {
background: #435f7a;
}
#frame .content .message-input .wrap button:focus {
outline: none;
}
</style></head><body>
<div id="frame">
<div class="content">
<div class="contact-profile">
<p style="margin-left: 40%;">Group Chat - Nearby</p>
</div>
<div class="messages" id="chatBox">
<ul>
</ul>
</div>
<div class="message-input">
<div class="wrap">
<input type="text" placeholder="Write your message..." />
<button class="submit"><i class="fa fa-paper-plane" aria-hidden="true"></i></button>
</div>
</div>
</div>
</div>
<script>
$(".messages").animate({ scrollTop: $(document).height() }, "fast");
var user_id;
function newMessage() {
message = $(".message-input input").val();
if($.trim(message) == '') {
return false;
}
writeUserData(message);
};
$('.submit').click(function() {
newMessage();
});
$(window).on('keydown', function(e) {
if (e.which == 13) {
newMessage();
return false;
}
});
</script>
<!-- Firebase -->
<script src="https://www.gstatic.com/firebasejs/4.13.0/firebase.js"></script>
<script>
// Initialize Firebase
var config = {
apiKey: "AIzaSyB6sXgYCNr9tYBd3sX5o5pAaD15_lV6LPM",
authDomain: "group-chat-codinginfinite.firebaseapp.com",
databaseURL: "https://group-chat-codinginfinite.firebaseio.com",
projectId: "group-chat-codinginfinite",
storageBucket: "group-chat-codinginfinite.appspot.com",
messagingSenderId: "129035491745"
};
firebase.initializeApp(config);
var user = firebase.auth().signInAnonymously();
firebase.auth().onAuthStateChanged(function(user) {
if (user) {
// User is signed in.
var isAnonymous = user.isAnonymous;
user_id = user.uid;
} else {
// User is signed out.
}
});
</script>
<script>
// get firebase database reference...
var db_ref = firebase.database().ref('/');
db_ref.on('child_added', function (data) {
var type;
if(data.val().user_id == user_id){
type="sent";
}
else{
type="replies";
}
$('<li class="'+type+'"><p>' + data.val().message + '</p></li>').appendTo($('.messages ul'));
$('.message-input input').val(null);
$('.contact.active .preview').html('<span>You: </span>' + data.val().message);
$(".messages").animate({ scrollTop: $(".messages")[0].scrollHeight }, 0);
});
function writeUserData(message) {
db_ref.push({
user_id: user_id,
message: message
});
}
</script>
</body></html>