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;
$(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");
}
function addFriend(jid, nick) {
roster[jid2id(jid)] = new Buddy(nick, jid);
- $('#friends').append('<div class="friend" id="'+jid2id(jid)+'"><img src="imgs/none.png" /><br /><span class="nick">'+nick+'</span></div>');
- $('#'+jid2id(jid)).click(function() {
+ $('#friends').append('<div class="friend" id="'+jid2id(jid)+'"><img src="imgs/none.png" /><br /><a class="nick">'+nick+'</a></div>');
+ $('#' + 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) {
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;
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('<br/>');
+ $('#' + id + ' p').append('<span class="receiver">' + localJID + ': </span>');
+ $('#' + id + ' p').append(form.text.value);
+ form.text.value = '';
+ }
+
+ return false;
+}
+
+function createBubble(jid) {
+ var id = jid2id(jid) + 'Chat';
+ $('body').append('<div class="chat" id="' + id + '" onmousedown="startDrag(this)"><a href="#" onclick="$(' + "'#" + id + "'" + ').hide()">Close</a><p></p></div>');
+ $('#' + id).append('<form id="' + id + 'Form" class="chatForm" onsubmit="return sendMessage(this, \'' + jid + '\');" action="#"><input type="text" name="text" id="' + id + 'Text" class="chatForm" /></form>')
+ $('#' + 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, '<br/>');
body = body.replace(/%3E/g, '>');
body = body.replace(/%26/g, '&');
body = unescape(body);
- if ($('#' + id).length > 0) {
- $('#' + id + ' p').append('<br/>');
- $('#' + id + ' p').append('<span class="sender">' + jid + ': </span>');
- $('#' + id + ' p').append(body);
- } else {
- $('body').append('<div class="chat" id="' + id + '"><p><span class="sender">' + jid + ': </span>' + body + '</p></div>');
+ if ($('#' + id).length <= 0) {
+ createBubble(jid);
}
+ $('#' + id + ' p').append('<br/>');
+ $('#' + id + ' p').append('<span class="sender">' + jid + ': </span>');
+ $('#' + id + ' p').append(body);
+ $('#' + id).show();
return true;
}
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();
$("#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 {
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;
+