File: chat.html.gr

package info (click to toggle)
jwchat 1.0beta2-13
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 5,200 kB
  • ctags: 405
  • sloc: xml: 462; sh: 80; makefile: 6
file content (304 lines) | stat: -rw-r--r-- 8,945 bytes parent folder | download
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
<!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="xmlextras.js"></script>
    <script src="JSJaCPacket.js"></script>
    <script>
      <!--
var user;
var srcW;
var cFrame;

var scrollHeight=0;
function putMsgHTML(msg,mtime,user,usercolor,err) {
  var msgHTML = '';
  
  msg = msgFormat(msg);
  
  msgHTML += "<div title='@ "+mtime+"'><span class=time>["+mtime+"] </span>";
	if (err) {
		msgHTML += "<span style='color:red;'>";
  } else if (msg.match(/^\/me /)) {
    msg = msg.replace(/^\/me /,"<span style=\"color:green;font-weight:bold;\" class=msgnick>*&nbsp;"+user+"</span> ");
  } else {
    msgHTML += "<span style=\"color:"+usercolor+";\" class=msgnick>&lt;" + user + "&gt;</span>";
  }
  msgHTML += "&nbsp;" + msg;
	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
		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();

  
    putMsgHTML(msg.getBody(),mtime,user.name,"red");
  }
  if (jwcMain.focusWindows) 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 = user.statusMsg;
	} else
		awaymsg.style.display = 'none';

	var img = document.images['statusLed'];
	img.src = eval(user.status + "Led").src;
}

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();
  }

  cFrame = chat.document;
  user = srcW.roster.getUserByJID(jid);
  document.title = "Chat with "+user.name;

	document.getElementById('user_name').innerHTML = user.name;

	if (typeof(jwcMain.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;
  }
}

function submitClicked() {
	var body = document.forms[0].elements["msgbox"].value;
	if (body == '') // don't send empty message
		return true;

	var aMessage = new JSJaCMessage();
	aMessage.setType('chat');
	aMessage.setTo(user.jid);
	aMessage.setBody(body);

	jwcMain.con.send(aMessage);

	// store message - [TODO]
	if (jwcMain.enableLog && typeof(jwcMain.loghost) != 'undefined') {
		var aIQ = new JSJaCIQ();
		aIQ.setType('set');
		aIQ.setTo(jwcMain.loghost);
		var aNode = aIQ.getNode().appendChild(aIQ.getDoc().createElement('archive'));
		aNode.setAttribute('xmlns','http://jabber.org/protocol/archive');
		aNode.appendChild(aMessage.getNode().cloneNode(true));
		if (typeof(window.cid) != 'undefined') {
			aNode.setAttribute('cid',user.chatW.cid);
			jwcMain.con.send(aIQ);
		} else {
			storeCID = jwcMain.storeCID;
			jwcMain.con.send(aIQ,storeCID,user.jid);
		}
	}

	// insert into chat window
	var 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();
	putMsgHTML(body,mtime,srcW.roster.nick,"blue");

	// 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 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'));
		} 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 (typeof(window.cid) != 'undefined') {
		var aIQ = new JSJaCIQ();
		aIQ.setType('set');
		aIQ.setTo(jwcMain.loghost);
		var aNode= aIQ.getNode().appendChild(aIQ.getDoc().createElement('done'));
		aNode.setAttribute('xmlns','http://jabber.org/protocol/archive');
		aNode.setAttribute('cid',window.cid);
		jwcMain.con.syncSend(aIQ.clone());
	}
}

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="link" onClick="return openUserInfo();" style="padding:2px;" title="Click to show user's vcard"></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="yes" style="width:100%;height:100%;"></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>