From: Florian Zeitz Date: Sat, 20 Jun 2009 19:39:50 +0000 (+0200) Subject: Message sending X-Git-Url: http://cgit.babelmonkeys.de/?p=socialXMPP.git;a=commitdiff_plain;h=b12b35d39a99293eadee739b291f64433f5da34e Message sending * Added message sending support * Added moveable bubbles --- diff --git a/css/standard.css b/css/standard.css index 25e4aed..62dbe00 100644 --- a/css/standard.css +++ b/css/standard.css @@ -44,9 +44,18 @@ color: blue; } +.receiver { + color: darkred; +} + .chat { + position: fixed; + background-color: white; width: 30%; - height: 30%; padding: 1em; border: 2px solid; } + +.chatForm { + width: 100%; +} diff --git a/scripts/basic.js b/scripts/basic.js index 1ef9115..aecaa7e 100644 --- a/scripts/basic.js +++ b/scripts/basic.js @@ -4,6 +4,7 @@ var NS_PEP = 'http://jabber.org/protocol/pubsub#event'; var NS_TUNE = 'http://jabber.org/protocol/tune'; var BOSH_SERVICE = 'http://localhost:5280/http-bind/'; +var localJID = null; var connection = null; var show_log = true; @@ -59,6 +60,11 @@ function populateVCard(e, jid) { $(e).find('EMAIL:has(WORK)').each(function() { $('#EMAILWORK').append(Strophe.xmlTextNode($(this).find('USERID').text())); }); + + $('#vCard').click(function () { + $('#vCard_container').slideUp("normal"); + }); + $('#vCard_container').slideDown("normal"); } @@ -141,10 +147,18 @@ function getOwnInfo() { function addFriend(jid, nick) { roster[jid2id(jid)] = new Buddy(nick, jid); - $('#friends').append('

'+nick+'
'); - $('#'+jid2id(jid)).click(function() { + $('#friends').append('

'+nick+'
'); + $('#' + jid2id(jid) + ' img').click(function() { getVCard(jid); }); + $('#' + jid2id(jid) + ' a').click(function() { + var id = jid2id(jid) + 'Chat'; + if ($('#' + id).length <= 0) { + createBubble(jid); + } + $('#' + id).show(); + }); + } function _cbRoster(e) { @@ -158,7 +172,7 @@ function _cbRoster(e) { addFriend(entries[item].getAttribute('jid'), nick); } connection.addHandler(_cbPEP, NS_PEP, 'message'); - var initialPresence = $pres().c('show').t('online').up().c('status').t('Hy, I am an socialXMPP instance').up().c('priority').t('0').up().c('c', {xmlns: NS_CAPS, hash: 'sha-1', node: 'http://jabber.babelmonkeys.de', ver: genCaps()}).up(); + var initialPresence = $pres().c('show').t('online').up().c('status').t('Hy, I am an socialXMPP instance').up().c('priority').t('1').up().c('c', {xmlns: NS_CAPS, hash: 'sha-1', node: 'http://jabber.babelmonkeys.de', ver: genCaps()}).up(); connection.send(initialPresence.tree()); return false; @@ -190,11 +204,34 @@ function _cbDisco(e) { return true; } +function sendMessage(form, to) { + if (form.text.value) { + var id = jid2id(to) + 'Chat'; + var message = $msg({'type': 'chat', 'to': to}).c('body').t(form.text.value); + connection.send(message.tree()); + $('#' + id + ' p').append('
'); + $('#' + id + ' p').append('' + localJID + ': '); + $('#' + id + ' p').append(form.text.value); + form.text.value = ''; + } + + return false; +} + +function createBubble(jid) { + var id = jid2id(jid) + 'Chat'; + $('body').append('
Close

'); + $('#' + id).append('
') + $('#' + id).css( 'top', $('#' + jid2id(jid)).position().top + 40); + $('#' + id).css( 'left', $('#' + jid2id(jid)).position().left + 40); +} + + function _cbMessage(msg) { if ($(msg).attr('type') != 'chat') - return; + return true; var jid = $(msg).attr('from'); - var id = jid2id($(msg).attr('from')) + 'Chat'; + var id = jid2id(jid) + 'Chat'; var body = $(msg).find('body:first').text(); body = escape(body); body = body.replace(/%0A/g, '
'); @@ -202,13 +239,13 @@ function _cbMessage(msg) { body = body.replace(/%3E/g, '>'); body = body.replace(/%26/g, '&'); body = unescape(body); - if ($('#' + id).length > 0) { - $('#' + id + ' p').append('
'); - $('#' + id + ' p').append('' + jid + ': '); - $('#' + id + ' p').append(body); - } else { - $('body').append('

' + jid + ': ' + body + '

'); + if ($('#' + id).length <= 0) { + createBubble(jid); } + $('#' + id + ' p').append('
'); + $('#' + id + ' p').append('' + jid + ': '); + $('#' + id + ' p').append(body); + $('#' + id).show(); return true; } @@ -268,9 +305,10 @@ function onConnect(status) { log('Strophe is disconnected.'); showConnect(); } else if (status == Strophe.Status.AUTHFAIL) { - log('Authentication failed.'); - connection.disconnect(); - showConnect(); + log('Authentication failed'); + if (connection) { + connection.disconnect(); + } } else if (status == Strophe.Status.CONNECTED) { log('Strophe is connected.'); getOwnInfo(); @@ -317,19 +355,16 @@ $(document).ready(function () { $("#log_toggle").click(function () { $("#log").toggle(); }); - - $('#vCard_container').click(function () { - $('#vCard_container').slideUp("normal"); - }); $('#cred').bind('submit', function () { var button = $('#connect').get(0); var jid = $('#jid'); var pass = $('#pass'); + localJID = jid.get(0).value; if (button.value == 'connect') { showDisconnect(); - connection.connect(jid.get(0).value, + connection.connect(localJID, pass.get(0).value, onConnect); } else { @@ -339,3 +374,40 @@ $(document).ready(function () { return false; }); }); + +// Element moving +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 (connection) { + connection.disconnect(); + } +} + +onmousemove = doDrag; +onmouseup = stopDrag; + diff --git a/scripts/classes.js b/scripts/classes.js index c991a8a..62d962f 100644 --- a/scripts/classes.js +++ b/scripts/classes.js @@ -6,6 +6,11 @@ Tune = function() { this.title = ''; this.track = 1; this.uri = ''; + this.isEmpty = function() { + return ( (this.artist == '') && (this.length == 0) && (this.rating == 1) + && (this.source == '') && (this.title == '') && (this.track == 1) + && (this.uri == '') ); + } } Buddy = function(name, jid) { diff --git a/scripts/strophejs b/scripts/strophejs index 76af4af..b3177bf 160000 --- a/scripts/strophejs +++ b/scripts/strophejs @@ -1 +1 @@ -Subproject commit 76af4af579d71ded60a18e84ea99333b98c8e2d2 +Subproject commit b3177bf164e2a8d26f18535d117a18f935340379