forked from michaljaz/webmc
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathChat.js
More file actions
57 lines (49 loc) · 1.01 KB
/
Chat.js
File metadata and controls
57 lines (49 loc) · 1.01 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
// Generated by CoffeeScript 2.5.1
var Chat;
Chat = class Chat {
constructor(game) {
this.game = game;
this.chatDiv = document.querySelector(".chat");
this.listen();
this.history = [];
return;
}
listen() {
var _this;
_this = this;
window.addEventListener("wheel", function(e) {
if (_this.game.FPC.gameState !== "chat") {
e.preventDefault();
}
}, {
passive: false
});
return this;
}
isElementScrolledToBottom(el) {
if (el.scrollTop >= (el.scrollHeight - el.offsetHeight)) {
return true;
}
return false;
}
scrollToBottom(el) {
el.scrollTop = el.scrollHeight;
}
log(message) {
var atBottom;
atBottom = this.isElementScrolledToBottom(this.chatDiv);
$(".chat").append(message + "<br>");
if (atBottom) {
this.scrollToBottom(this.chatDiv);
}
}
command(com) {
if (com !== "") {
this.history.push(com);
return this.game.socket.emit("command", com);
}
}
};
export {
Chat
};