]> git.scottworley.com Git - reliable-chat/blame - webclient/rc.js
Send messages with <img src="...">
[reliable-chat] / webclient / rc.js
CommitLineData
991a5820
SW
1var servers = ['chkno.net', 'localhost']
2
3var session = Math.random();
4
5function addport(server) {
6 // Add the default port if server doesn't contain a port number already
7 if (server.indexOf(":") == -1) {
8 return server + ":21059";
9 } else {
10 return server;
11 }
12}
13
14function rcsend(d, message) {
15 var id = new Date().getTime() + "-" + session + "-" + Math.random();
16 var path = "/speak" +
17 "?id=" + encodeURIComponent(id) +
18 "&text=" + encodeURIComponent(message);
19 for (i in servers) {
20 var uri = "http://" + addport(servers[i]) + path;
21 var img = document.createElement("img");
22 img.setAttribute("src", uri);
23 d.appendChild(img);
24 }
25}
26
827f21bb
SW
27function rckeydown(event) {
28 if (event.keyCode == 13) {
29 var d = document.createElement("div");
30 d.appendChild(document.createTextNode(document.input.say.value));
31 var h = document.getElementById("history");
32 h.appendChild(d);
33 window.scrollTo(0, document.body.scrollHeight);
991a5820 34 rcsend(d, document.input.say.value);
827f21bb
SW
35 document.input.say.value = "";
36 return false;
37 }
38}