-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
173 lines (141 loc) · 4.77 KB
/
index.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
<!DOCTYPE html>
<html>
<head>
<title>group-chat-app</title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta/css/bootstrap.min.css" integrity="sha384-/Y6pD6FV/Vv2HJnA6t+vslU6fwYXjCFtcEpHbNJ0lyAFsXTsjBbfaDjzALeQsN6M" crossorigin="anonymous">
<link rel="stylesheet" href="style.css">
<script src="https://code.jquery.com/jquery-3.2.1.min.js" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.11.0/umd/popper.min.js" integrity="sha384-b/U6ypiBEHpOf/4+1nzFpr53nxSS+GLCkfwBdFNTxtclqqenISfwAzpKaMNFNmj4" crossorigin="anonymous"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta/js/bootstrap.min.js" integrity="sha384-h0AbiXch4ZDo7tp9hKZ4TsHbi047NrKGLO3SEJAg45jXxnGIfYzk4Si90RDIqNm1" crossorigin="anonymous"></script>
<script src="/socket.io/socket.io.js"></script>
<script src="script.js"></script>
<link rel="stylesheet" href="jquery.toast.css">
<script src="jquery.toast.js"></script>
</head>
<body>
<div class="heading">
<div id="wrapper">
<h1 class="chrome">Group Chat</h1>
</div>
</div>
<div class="initial">
<input id = "name" class="form-control" placeholder="Name">
<br>
<button class="user-button rot-bu rot-bu-two">Enter</button>
</div>
<div class="container hidden">
<br>
<div id="messages" class="chatbox">
<br>
<br>
</div>
<div class="jumbotron">
<h1 class="display-4">Send Message</h1>
<br>
<textarea id = "message" class="form-control" placeholder="Enter Your Message Here. Press Enter or the 'Send' button when done."></textarea>
<br>
<div class='del'><button id="send" class="rot-bu rot-bu-two">Send</button></div>
</div>
<div class='del'><a href="/delete"><button class="cool rot-bu rot-bu-two">Delete</button></a></div>
</div>
<script>
var socket = io();
var input = document.getElementById("message");
// Execute a function when the user releases a key on the keyboard
input.addEventListener("keyup", function(event) {
// Number 13 is the "Enter" key on the keyboard
if (event.keyCode === 13) {
document.getElementById("send").click();
// Cancel the default action, if needed
event.preventDefault();
// Trigger the button element with a click
}
});
$(() => {
let dan = document.getElementById('messages');
dan.onscroll = function (e) {
if(e.isTrusted==true){
clearInterval(window.value)
console.log('down')
}
else{
console.log('up')
}
}
$(".chatbox").scroll(function(event){chk_scroll(event)});
$("#send").click(() => {
if ($("#message").val() == "") {
$.toast({
heading: 'Error',
text: 'Cannot be blank!',
showHideTransition: 'fade',
icon: 'error'
})
} else {
sendMessage({
name: $("#name").val(),
message: $("#message").val()
});
$("#message").val("");
submitPoll();
$('#messages').animate({
scrollTop: $('#messages')[0].scrollHeight
}, 800);
}
})
// var position = $(window).scrollTop();
// // should start at 0
// $(".chatbox").scroll(function() {
// var scroll = $(".chatbox").scrollTop();
// if (scroll < position) {
// clearInterval(window.value)
// console.log('up')
// break
// } else {
// window.value = setInterval(function() {
// $('#messages').animate({
// scrollTop: $('#messages')[0].scrollHeight
// }, 800);
// }, 1000);
// console.log('down')
// }
// position = scroll;
// });
getMessages()
})
socket.on('message', addMessages)
function addMessages(message) {
$("#messages").append(`<h4> ${message.name} </h4> <p> ${message.message} </p>`);
}
function getMessages() {
$.get('/messages', (data) => {
data.forEach(addMessages);
})
}
function sendMessage(message) {
$.post('/messages', message)
}
function submitPoll() {
document.getElementById("send").disabled = true;
setTimeout(function() {
document.getElementById("send").disabled = false;
}, 1000);
}
function chk_scroll(e) {
var elem = $(e.currentTarget);
if (elem[0].scrollHeight - elem.scrollTop() == elem.outerHeight()) {
window.value = setInterval(function() {
$('#messages').animate({
scrollTop: $('#messages')[0].scrollHeight
}, 800);
}, 1000);
console.log("interval engaged")
} if (elem[0].scrollHeight - elem.scrollTop() != elem.outerHeight()) {
console.log("interval is there")
} else{
console.log("interval is nope")
}
}
</script>
</body>
</html>