1 myname: localStorage
["username"] || "anonymous",
2 oppName: "anonymous", //opponent name, revealed after a game (if provided)
3 chats: [], //chat messages after human game
11 attrs: { "id": "close-chat", "for": "modal-chat" },
12 "class": { "modal-close": true },
17 attrs: { "id": "titleChat" },
18 "class": { "section": true },
19 domProps: { innerHTML: translations
["Chat with "] + this.oppName
},
23 for (let chat
of this.chats
)
29 "my-chatmsg": chat
.author
==this.myid
,
30 "opp-chatmsg": chat
.author
==this.oppid
,
32 domProps: { innerHTML: chat
.msg
}
37 chatEltsArray
= chatEltsArray
.concat([
43 placeholder: translations
["Type here"],
45 on: { keyup: this.trySendChat
}, //if key is 'enter'
50 attrs: { id: "sendChatBtn"},
51 on: { click: this.sendChat
},
52 domProps: { innerHTML: translations
["Send"] },
59 attrs: { "id": "modal-chat", type: "checkbox" },
60 "class": { "modal": true },
64 attrs: { "role": "dialog", "aria-labelledby": "titleChat" },
69 "class": { "card": true, "smallpad": true },
76 elementArray
= elementArray
.concat(modalChat
);
81 this.chats
.push({msg:data
.msg
, author:this.oppid
});
84 // Receive opponent's name
85 this.oppName
= data
.name
;
89 // TODO: complete this component
90 trySendChat: function(e
) {
91 if (e
.keyCode
== 13) //'enter' key
94 sendChat: function() {
95 let chatInput
= document
.getElementById("input-chat");
96 const chatTxt
= chatInput
.value
;
98 this.chats
.push({msg:chatTxt
, author:this.myid
});
99 this.conn
.send(JSON
.stringify({
100 code:"newchat", oppid: this.oppid
, msg: chatTxt
}));
102 startChat: function(e
) {
103 this.getRidOfTooltip(e
.currentTarget
);
104 document
.getElementById("modal-chat").checked
= true;