-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathchat.html
324 lines (279 loc) · 9 KB
/
chat.html
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
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>JWChat - Chat</title>
<meta http-equiv="content-type" content="text/html; charset=utf-8">
<script src="shared.js"></script>
<script src="browsercheck.js"></script>
<script src="emoticons.js"></script>
<script src="switchStyle.js"></script>
<script src="statusLed.js"></script>
<script src="jsjac.js"></script>
<script>
<!--
var user;
var srcW;
var cFrame;
var scrollHeight=0;
function putMsgHTML(msg) {
var msgHTML = '';
var body = '';
var err = false;
if (msg.getType() == 'error') {
var error = aJSJaCPacket.getNode().getElementsByTagName('error').item(0);
if (error && error.getElementsByTagName('text').item(0))
body = error.getElementsByTagName('text').item(0).firstChild.nodeValue;
err = true;
} else
body = msg.getBody();
var now;
if (msg.jwcTimestamp)
now = msg.jwcTimestamp;
else
now = new Date();
var mtime = (now.getHours()<10)? "0" + now.getHours() : now.getHours();
mtime += ":";
mtime += (now.getMinutes()<10)? "0" + now.getMinutes() : now.getMinutes();
mtime += ":";
mtime += (now.getSeconds()<10)? "0" + now.getSeconds() : now.getSeconds();
if (msg.getTo() == user.jid){ // msg sent by me
nick = htmlEnc(srcW.roster.nick);
nickcolor = 'blue';
dir = 'to';
} else {
nick = user.name;
nickcolor = 'red';
dir = 'from';
}
msgHTML += "<div title=\"@ "+mtime+"\" cDate=\""+now.getTime()+"\" dir=\""+dir+"\" body=\""+htmlEnc(body)+"\"><span class=time>["+mtime+"] </span>";
body = msgFormat(body);
if (err) {
msgHTML += "<span style='color:red;'> ";
} else if (body.match(/^\/me /)) {
body = body.replace(/^\/me /,"<span style=\"color:green;font-weight:bold;\" class=msgnick>* "+nick+"</span> ");
} else {
msgHTML += "<span style=\"color:"+nickcolor+";\" class=msgnick><" + nick + "></span> ";
}
msgHTML += body;
if (err)
msgHTML += '</span>';
msgHTML += "</div>";
var auto_scroll = false;
if (cFrame.body.scrollTop+cFrame.body.clientHeight >= cFrame.body.scrollHeight) // scrollbar at bottom
auto_scroll = true;
cFrame.body.innerHTML += msgHTML;
if (auto_scroll)
chat.scrollTo(0,cFrame.body.scrollHeight);
}
function popMsgs() {
while (user.chatmsgs.length>0) {
var msg;
if (is.ie5||is.op) {
msg = user.chatmsgs[0];
user.chatmsgs = user.chatmsgs.slice(1,user.chatmsgs.length);
} else
msg = user.chatmsgs.shift();
// calc date
putMsgHTML(msg);
}
if (jwcMain.focusWindows) {
window.focus();
document.forms.chatform.msgbox.focus();
}
if (user.lastsrc != null && user.messages.length == 0) {
var images = srcW.roster.getUserIcons(user.jid);
for (var i=0; i<images.length; i++)
images[i].src = user.lastsrc;
user.lastsrc = null;
if (srcW.roster.usersHidden && user.status == 'unavailable') // remove user from roster if not available any more
srcW.roster.print();
}
}
function openUserInfo() {
return jwcMain.openUserInfo(user.jid);
}
function openUserHistory() {
return jwcMain.openUserHistory(user.jid);
}
function updateUserPresence() {
// var user = srcW.roster.getUserByJID(jid);
var awaymsg = document.getElementById('awaymsg');
document.getElementById('user_name').innerHTML = user.name;
if (user.statusMsg) {
awaymsg.style.display = '';
awaymsg.innerHTML = htmlEnc(user.statusMsg);
} else
awaymsg.style.display = 'none';
var img = document.images['statusLed'];
img.src = eval(user.status + "Led").src;
}
function submitClicked() {
var body = document.forms[0].elements["msgbox"].value;
if (body == '') // don't send empty message
return false;
var aMessage = new JSJaCMessage();
aMessage.setType('chat');
aMessage.setTo(user.jid);
aMessage.setBody(body);
jwcMain.con.send(aMessage);
// insert into chat window
putMsgHTML(aMessage);
// add message to our message history
jwcMain.addtoHistory(body);
document.forms["chatform"].msgbox.value=''; // empty box
document.forms["chatform"].msgbox.focus(); // set focus back on input field
return false;
}
var jwcMain;
function init() {
getArgs();
jid = passedArgs['jid'];
if (opener.top.roster) {
srcW = opener.top;
if (srcW.srcW)
jwcMain = srcW.srcW;
else
jwcMain = srcW;
} else {
alert("error starting chat");
window.close();
}
cDate = new Date();
cFrame = chat.document;
user = srcW.roster.getUserByJID(jid);
document.title = "Chat with "+user.name;
document.getElementById('user_name').innerHTML = user.name;
if (typeof(srcW.loghost) == 'undefined')
document.getElementById('hist_button').style.display = 'none';
updateUserPresence();
popMsgs();
displayTimestamp();
}
function displayTimestamp() {
var tstyle;
if (is.ie) {
tstyle = cFrame.styleSheets('timestampstyle');
tstyle.disabled = jwcMain.timestamps;
} else {
tstyle = cFrame.getElementById("timestampstyle");
tstyle.sheet.disabled = jwcMain.timestamps;
}
}
var group_open = new Image();
group_open.src = 'images/group_open.gif';
var group_close = new Image();
group_close.src = 'images/group_close.gif';
var msgbox_toggled = false;
function toggle_msgbox(el) {
if (msgbox_toggled) {
document.getElementById('msgbox').style.height = '1.4em';
document.getElementById('chat').style.height = '100%';
document.getElementById('submitbutton').style.display = 'none';
el.src = group_close.src;
} else {
document.getElementById('msgbox').style.height = '4.2em';
document.getElementById('chat').style.height = '99%';
document.getElementById('submitbutton').style.display = '';
el.src = group_open.src;
}
msgbox_toggled = !msgbox_toggled;
}
function msgboxKeyPressed(el,e) {
var keycode;
if (window.event) { e = window.event; keycode = window.event.keyCode; }
else if (e) keycode = e.which;
else return true;
switch (keycode) {
case 13:
if (e.shiftKey) {
if (!msgbox_toggled) {
toggle_msgbox(document.getElementById('toggle_icon'));
return false;
}
} else
return submitClicked();
break;
}
return true;
}
function msgboxKeyDown(el,e) {
var keycode;
if (window.event) { e = window.event; keycode = window.event.keyCode; }
else if (e) keycode = e.which;
else return true;
switch (keycode) {
case 38: // shift+up
if (e.ctrlKey) {
el.value = jwcMain.getHistory('up', el.value);
el.focus(); el.select();
}
break;
case 40: // shift+down
if (e.ctrlKey) {
el.value = jwcMain.getHistory('down', el.value);
el.focus(); el.select();
}
break;
case 76:
if (e.ctrlKey) { // ctrl+l
chat.document.body.innerHTML = '';
return false;
}
break;
case 27:
window.close();
break;
}
return true;
}
function cleanUp() {
if (!srcW.enableLog || typeof(srcW.loghost) == 'undefined')
return;
var nodes = cFrame.body.getElementsByTagName("div");
if (nodes.length == 0)
return;
var aIQ = new JSJaCIQ();
aIQ.setType('set');
aIQ.setTo(jwcMain.loghost);
var aStore =
aIQ.appendNode(
'store',
{'xmlns': 'http://jabber.org/protocol/archive',
'with': user.jid,
'start': jabberDate(cDate)});
for (var i=0; i<nodes.length; i++) {
var node = nodes.item(i);
var aItem = aStore.appendChild(aIQ.getDoc().createElement(node.getAttribute('dir')));
aItem.setAttribute('secs',Math.round((node.getAttribute('cDate')-cDate.getTime())/1000));
aItem.appendChild(aIQ.getDoc().createElement("body")).appendChild(aIQ.getDoc().createTextNode(node.getAttribute('body')));
}
jwcMain.Debug.log(aIQ.xml(),2);
jwcMain.con.send(aIQ);
}
onload = init;
onunload = cleanUp;
//-->
</script>
</head>
<body style="margin:8px;">
<table width="100%" height="100%">
<tr><td colspan=2>
<table border=0 cellspacing=0 cellpadding=0 width="100%">
<tr>
<td width="100%" valign=top><img src="images/unavailable.gif" name="statusLed" width=16 height=16 border=0 align=left><span id="user_name" class="nickName" style="padding:2px;"></span><br clear=all>
<span id="awaymsg" class="statusMsg"></span></td>
<td align=right valign=top><button id='hist_button' onClick="return openUserHistory();">History</button></td></table>
</td></tr>
<tr><td width="100%" height="100%" colspan=2><iframe src="chat_iframe.html" id="chat" name="chat" scrolling="auto"></iframe></td></tr>
<form name="chatform" style="border:0px;margin:0px;padding:0px;">
<tr>
<td valign=top><img id="toggle_icon" src="images/group_close.gif" width="14" height="14" onClick="toggle_msgbox(this);"></td>
<td width="100%">
<textarea id="msgbox" wrap="virtual" style="width:100%;height:1.4em;" onKeyPress="return msgboxKeyPressed(this,event);" onKeyDown="return msgboxKeyDown(this,event);"></textarea>
</td>
</tr>
<tr id="submitbutton" style="display:none;"><td colspan=2 align=right><button onClick="submitClicked(); return false;">Send</button></td></tr>
</form>
</table>
</body>
</html>