-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.js
More file actions
197 lines (149 loc) · 5.92 KB
/
main.js
File metadata and controls
197 lines (149 loc) · 5.92 KB
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
$(function () {
var chatMessages = $("#chat-messages");
var chatContainer = document.getElementById("chat-container");
function updateChat() {
var isAtBottom = chatContainer.scrollHeight - chatContainer.scrollTop === chatContainer.clientHeight;
// Fetch and display chat messages
$.get("fetch.php", function (data) {
var scrollNeeded = isAtBottom; // Check if scrolling is needed
chatMessages.html(data);
if (scrollNeeded) {
scrollChatToBottom();
}
setTimeout(updateChat, 1000);
});
}
updateChat();
const timeoutId = setTimeout(scrollChatToBottom, 300);
setTimeout(() => {
clearTimeout(timeoutId);
}, 600);
//send message and handle file uploading
$("#send").on("click", function () {
var message = $("#message").val();
var fileInput = document.getElementById('file');
var file = fileInput.files[0];
if (message.trim() !== "" || file) {
var formData = new FormData();
formData.append('message', message);
formData.append('file', file);
$.ajax({
// url: "send_chat_message.php",
url: "send_message.php",
type: "POST",
data: formData,
processData: false,
contentType: false,
success: function () {
updateChat();
$("#message").val("");
$("#file").val("");
setTimeout(scrollChatToBottom, 100);
}
});
}
});
// Log In
$("#login").on("click", function () {
window.location.href = 'login.php';
});
// Chat Anonymously
// $("#chat-anonymously").on("click", function () {
// var expirationDate = new Date();
// expirationDate.setDate(expirationDate.getDate() + 30); // Set the expiration date to 30 days from the current date
// var expires = "expires=" + expirationDate.toUTCString();
// document.cookie = "chatOption=anonymous; " + expires + "; path=/";
// location.reload();
// });
$("#chat-anonymously").on("click", function () {
var expirationDate = new Date();
expirationDate.setDate(expirationDate.getDate() + 30);
var expires = "expires=" + expirationDate.toUTCString();
document.cookie = "chatOption=anonymous; " + expires + "; path=/";
$.ajax({
url: 'create_anonym_user.php',
type: 'POST',
success: function (data) {
location.reload();
},
error: function (xhr, status, error) {
console.error("Error creating anonymous user: " + error);
}
});
});
});
function scrollChatToBottom() {
var chatMessages = document.getElementById("chat-container");
chatMessages.scrollTop = chatMessages.scrollHeight;
}
// function openVideoPopup(videoUrl) {
// var width = 800; // Set the desired width for the popup
// var height = 600; // Set the desired height for the popup
// var left = (screen.width - width) / 2;
// var top = (screen.height - height) / 2;
// // Open a new popup window with the video player
// var videoPopup = window.open('', 'VideoPopup', 'width=' + width + ',height=' + height + ',left=' + left + ',top=' + top);
// videoPopup.document.write("<video controls width='100%' height='100%'><source src='" + videoUrl + "' type='video/mp4'></video>");
// }
function openVideoPopup(videoUrl) {
var modal = document.getElementById("videoPopup");
var modalVideo = document.getElementById("popupVideo");
modal.style.display = "block";
modalVideo.src = videoUrl;
modalVideo.load();
modalVideo.play();
}
// Function to close the video popup
function closeVideoPopup() {
var modal = document.getElementById("videoPopup");
var modalVideo = document.getElementById("popupVideo");
modal.style.display = "none";
modalVideo.src = "";
}
// Function to close the video popup when clicking outside
window.addEventListener("click", function (event) {
var modal = document.getElementById("videoPopup");
if (event.target == modal) {
closeVideoPopup();
}
});
// Function to open the image popup
function openImagePopup(imageUrl) {
var modal = document.getElementById("imagePopup");
var modalImg = document.getElementById("popupImage");
modal.style.display = "block";
modalImg.src = imageUrl;
}
// Function to close the image popup
function closeImagePopup() {
var modal = document.getElementById("imagePopup");
modal.style.display = "none";
}
// Function to close the image popup when clicking outside
window.addEventListener("click", function (event) {
var modal = document.getElementById("imagePopup");
if (event.target == modal) {
closeImagePopup();
}
});
// const resizeableDiv = document.getElementById("chat-containe");
// let isResizing = false;
// resizeableDiv.addEventListener("mousedown", (e) => {
// isResizing = true;
// e.preventDefault();
// const initialHeight = resizeableDiv.offsetHeight;
// const initialY = e.clientY;
// document.addEventListener("mousemove", resize);
// document.addEventListener("mouseup", stopResize);
// function resize(e) {
// if (isResizing) {
// const height = initialHeight + (e.clientY - initialY);
// resizeableDiv.style.height = `${height}px`;
// }
// }
// function stopResize() {
// isResizing = false;
// document.removeEventListener("mousemove", resize);
// document.removeEventListener("mouseup", stopResize);
// }
// });