document.getElementById('entry').style.display = 'none';
}
+function addBubble(nick) {
+ id = nick + 'Bubble';
+ if (!document.getElementById(id)) {
+ root = document.getElementsByTagName('body')[0];
+ var div = '';
+ div += '<div id="' + id + '" class="bubble" onmousedown="startDrag(this)">';
+ div += '<a href="#" onclick="' +"document.getElementById('" + id + "').style.display='none'" + '">Close</a>';
+ div += '<div id="' + id + 'Chat" class="bubbleChat"></div>';
+ div += '<form id="' + id + 'Form" class="bubbleForm" onsubmit="return sendChatMessage(this,' + "'" + nick + "');" + '" action="#">';
+ div += '<input type="text" name="text" id="' + id + 'Text" class="bubbleForm"/>';
+ div += '</form>';
+ div += '</div>';
+ root.innerHTML += div;
+ }
+ document.getElementById(id).style.display = 'block';
+}
+
function handleMessage(aJSJaCPacket) {
var html = '';
+ sender = aJSJaCPacket.getFromJID().getResource()
html += '<div class="msg">';
- if (aJSJaCPacket.getFromJID().getResource()) {
+ if (sender) {
html += '<span class="sender">';
- html += aJSJaCPacket.getFromJID().getResource();
+ html += sender;
html += ':</span> ';
html += aJSJaCPacket.getBody().htmlEnc() + '</div>';
} else {
html += aJSJaCPacket.getBody().htmlEnc() + '</span></div>';
}
- document.getElementById('chat').innerHTML += html;
- document.getElementById('chat').lastChild.scrollIntoView();
+ if (aJSJaCPacket.getType() == 'chat') {
+ addBubble(sender);
+ document.getElementById(id + 'Chat').innerHTML += html;
+ document.getElementById(id + 'Chat').lastChild.scrollIntoView();
+ } else {
+ document.getElementById('chat').innerHTML += html;
+ document.getElementById('chat').lastChild.scrollIntoView();
+ }
}
function handlePresence(aJSJaCPacket) {
element = document.getElementById(nick);
roster_list.removeChild(element);
} else {
- roster_list.innerHTML += '<li id="' + nick + '">' + nick + '</li>';
+ roster_list.innerHTML += '<li id="' + nick + '" onclick="addBubble(' + "'" + nick + "')" + '" >' + nick + '</li>';
}
}
return false;
}
+function sendChatMessage(aForm, to) {
+ if (aForm.text.value) {
+ message = new JSJaCMessage();
+ message.setBody(aForm.text.value);
+ message.setType('chat');
+ message.setTo(room + '/' + to);
+ con.send(message);
+ aForm.text.value = '';
+ var html = '';
+ html += '<div class="msg">';
+ html += '<span class="sender">';
+ html += nickname;
+ html += ':</span> ';
+ html += message.getBody().htmlEnc() + '</div>';
+ document.getElementById(to + 'BubbleChat').innerHTML += html;
+ document.getElementById(to + 'BubbleChat').lastChild.scrollIntoView();
+
+ }
+ return false;
+}
+
function randomString() {
var chars = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXTZabcdefghiklmnopqrstuvwxyz";
var string_length = 20;
return randomstring;
}
+var dragElement = null;
+var mouseX = 0;
+var mouseY = 0;
+var offX = 0;
+var offY = 0;
+
+function startDrag(element) {
+ dragElement = element;
+ offX = mouseX - dragElement.offsetLeft;
+ offY = mouseY - dragElement.offsetTop;
+}
+
+function doDrag(eve) {
+ mouseX = eve.pageX;
+ mouseY = eve.pageY;
+
+ if (dragElement) {
+ dragElement.style.left = (mouseX - offX) + 'px';
+ dragElement.style.top = (mouseY - offY) + 'px';
+ }
+}
+function stopDrag(eve) {
+ dragElement = null;
+}
onunload = function() {
if (con.connected())
con.disconnect();
}
+onmousemove = doDrag;
+
+onmouseup = stopDrag;