X-Git-Url: http://cgit.babelmonkeys.de/?p=xmppchat.git;a=blobdiff_plain;f=main.js;h=2ed9acef9159bc94562e32073f60a4c1c4e08eaa;hp=13ab10a73b8c38aa5495d740d14f47430c3607aa;hb=ca57ec7f2f9247c44a572e5e85926eaed6a277f9;hpb=dc7d1f18950078b98d3ba8fe8f6918df09818d5f diff --git a/main.js b/main.js index 13ab10a..2ed9ace 100644 --- a/main.js +++ b/main.js @@ -77,12 +77,30 @@ function handleDisconnected() { 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 += 'Close'; + div += '
'; + div += '
'; + div += ''; + div += '
'; + div += '
'; + root.innerHTML += div; + } + document.getElementById(id).style.display = 'block'; +} + function handleMessage(aJSJaCPacket) { var html = ''; + sender = aJSJaCPacket.getFromJID().getResource() html += '
'; - if (aJSJaCPacket.getFromJID().getResource()) { + if (sender) { html += ''; - html += aJSJaCPacket.getFromJID().getResource(); + html += sender; html += ': '; html += aJSJaCPacket.getBody().htmlEnc() + '
'; } else { @@ -90,8 +108,14 @@ function handleMessage(aJSJaCPacket) { html += aJSJaCPacket.getBody().htmlEnc() + ''; } - 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) { @@ -103,7 +127,7 @@ function handlePresence(aJSJaCPacket) { element = document.getElementById(nick); roster_list.removeChild(element); } else { - roster_list.innerHTML += '
  • ' + nick + '
  • '; + roster_list.innerHTML += '
  • ' + nick + '
  • '; } } @@ -144,6 +168,27 @@ function sendMessage(aForm) { 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 += '
    '; + html += ''; + html += nickname; + html += ': '; + html += message.getBody().htmlEnc() + '
    '; + document.getElementById(to + 'BubbleChat').innerHTML += html; + document.getElementById(to + 'BubbleChat').lastChild.scrollIntoView(); + + } + return false; +} + function randomString() { var chars = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXTZabcdefghiklmnopqrstuvwxyz"; var string_length = 20; @@ -155,10 +200,37 @@ function randomString() { 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;