GrandTabernacleAutoVI/public_html/js/phone.js

57 lines
1.2 KiB
JavaScript
Raw Normal View History

2023-12-11 15:24:48 +01:00
class Phone{
constructor(){
this.position = 0;
this.messages = [];
}
addMessage(message){
this.messages.push(message);
let msg = document.createElement("div");
msg.className = "message";
let h2 = document.createElement("h2");
h2.className = "messageTitle";
h2.innerHTML = message.title;
let p = document.createElement("p");
p.className = "messageContent";
p.innerHTML = message.content;
msg.appendChild(h2);
msg.appendChild(p);
2023-12-11 18:49:13 +01:00
let chatMessages = document.getElementById("chatMessages");
chatMessages.appendChild(msg);
chatMessages.scrollTop = chatMessages.scrollHeight;
2023-12-11 15:24:48 +01:00
}
sendMessage(title, content){
let message = {
title: player.name,
content: content
}
this.addMessage(message);
net.sendMessage(title, content);
}
keyPress(input){
if(event.key=='Enter'){
if(input.value!=''){
this.sendMessage(player.name, input.value);
input.value = '';
2023-12-13 13:58:34 +01:00
input.blur()
2023-12-11 15:24:48 +01:00
}
}
}
2023-12-11 18:49:13 +01:00
changePosition(){
if(this.position == 0){
document.getElementById("phoneContainer").className = "visible";
this.position = 1;
}else{
document.getElementById("phoneContainer").className = "hidden";
this.position = 0;
}
}
2023-12-11 15:24:48 +01:00
}