X-Git-Url: http://git.babelmonkeys.de/?p=socialXMPP.git;a=blobdiff_plain;f=scripts%2Fbasic.js;h=c1ba6cbbfd580f7e8e3a81b4fe3f4c11067f36c2;hp=7b57e5262f69df21cfafec1c64b13f172e62783f;hb=8c4afe807502d8fc5abb0155a14505363dbf4cfd;hpb=fa6912a322f9abcac6d2c3cce4bf3e35ee09b950
diff --git a/scripts/basic.js b/scripts/basic.js
index 7b57e52..c1ba6cb 100644
--- a/scripts/basic.js
+++ b/scripts/basic.js
@@ -1,19 +1,19 @@
var DEBUG = false;
var BOSH_SERVICE = '/http-bind/';
-var NS_VCARD = 'vcard-temp';
-var NS_CAPS= 'http://jabber.org/protocol/caps';
-var NS_PEP = 'http://jabber.org/protocol/pubsub#event';
-var NS_TUNE = 'http://jabber.org/protocol/tune';
+Strophe.addNamespace('VCARD', 'vcard-temp');
+Strophe.addNamespace('CAPS', 'http://jabber.org/protocol/caps');
+Strophe.addNamespace('PEP', 'http://jabber.org/protocol/pubsub#event');
+Strophe.addNamespace('TUNE', 'http://jabber.org/protocol/tune');
var localJID = null;
-var connection = null;
-var show_log = true;
+var connection = null;
+var show_log = true;
-var features = new Array(NS_CAPS, NS_TUNE+'+notify', Strophe.NS.DISCO_INFO);
+var features = [Strophe.NS.CAPS, Strophe.NS.TUNE + '+notify', Strophe.NS.DISCO_INFO];
var appName = 'socialXMPP';
-var roster = new Array();
+var roster = [];
function log(msg) {
var entry = $('
').append(document.createTextNode(msg));
@@ -33,19 +33,29 @@ function jid2id(jid) {
return jid.split('@').join('-').split('.').join('-');
}
+function genCaps() {
+ var S = '', i;
+ S += 'client/web//' + appName + '<';
+ features.sort();
+ for (i = 0; i < features.length; i++) {
+ S += features[i] + '<';
+ }
+ return b64_sha1(S);
+}
+
function populateVCard(e, jid) {
- var easy_cases = new Array('FN', 'FAMILY', 'MIDDLE', 'GIVEN', 'NICKNAME', 'BDAY', 'CTRY', 'USERID');
- for (var i=0; iTune: Listening to '+
roster[jid2id(jid)].tune.title + ' by ' + roster[jid2id(jid)].tune.artist +
- ' from ' + roster[jid2id(jid)].tune.source + '')
+ ' from ' + roster[jid2id(jid)].tune.source + '');
}
$('#vCard').click(function () {
@@ -87,7 +97,7 @@ function populateVCard(e, jid) {
function _cbVCard(e) {
var jid = e.getAttribute('from');
- if (roster[jid2id(jid)].vCard == "") {
+ if (roster[jid2id(jid)].vCard === "") {
roster[jid2id(jid)].vCard = e;
}
if ($('#vCard_container').is(':visible')) {
@@ -100,20 +110,20 @@ function _cbVCard(e) {
}
function _cbOwnVCard(e) {
+ var easy_cases = ['FN', 'FAMILY', 'MIDDLE', 'GIVEN', 'NICKNAME', 'BDAY', 'CTRY', 'USERID'], i, text, avatar, mime, binval;
$('#ownInfo').empty();
$('#ownInfo').load('vCard.html #ownvCard', function() {
- var easy_cases = new Array('FN', 'FAMILY', 'MIDDLE', 'GIVEN', 'NICKNAME', 'BDAY', 'CTRY', 'USERID');
- for (var i=0; iClose' +
+ ' ' + jid + '');
+ $('#' + id).append('');
+ $('#' + id).css( 'top', $('#' + jid2id(jid)).position().top + 40);
+ $('#' + id).css( 'left', $('#' + jid2id(jid)).position().left + 40);
+}
+
function addFriend(jid, nick) {
roster[jid2id(jid)] = new Buddy(nick, jid);
$('#friends').append('');
$('#' + jid2id(jid) + ' img').click(function() {
- getVCard(jid);
+ getVCard(jid);
});
$('#' + jid2id(jid) + ' a').click(function() {
var id = jid2id(jid) + 'Chat';
@@ -173,18 +192,58 @@ function addFriend(jid, nick) {
}
+function handleTune(jid, tuneXML) {
+ var tune = new Tune();
+ if (tuneXML.childNodes.length > 0) {
+ tune.artist = Strophe.getText(tuneXML.getElementsByTagName('artist')[0]);
+ tune.length= Strophe.getText(tuneXML.getElementsByTagName('length')[0]);
+ tune.rating= Strophe.getText(tuneXML.getElementsByTagName('rating')[0]);
+ tune.source= Strophe.getText(tuneXML.getElementsByTagName('source')[0]);
+ tune.title= Strophe.getText(tuneXML.getElementsByTagName('title')[0]);
+ tune.track= Strophe.getText(tuneXML.getElementsByTagName('track')[0]);
+ tune.uri= Strophe.getText(tuneXML.getElementsByTagName('uri')[0]);
+ if (roster[jid2id(jid)].visible === true) {
+ if ( $('#tune').length > 0) {
+ $('#tune').empty();
+ $('#tune').append('Tune: ');
+ $('#tune').append(Strophe.xmlTextNode('Listening to '+ tune.title +
+ ' by ' + tune.artist + ' from ' + tune.source));
+ } else {
+ $('#vCard ul').append('Tune: Listening to '+ tune.title +
+ ' by ' + tune.artist + ' from ' + tune.source + '');
+ }
+ }
+ } else {
+ $('#tune').remove();
+ }
+ roster[jid2id(jid)].tune = tune;
+}
+
+function _cbPEP(e) {
+ var from = e.getAttribute('from'), items;
+ if (Strophe.getBareJidFromJid(from) == Strophe.getBareJidFromJid(connection.jid)) {
+ return true; // Drop own PEP events
+ }
+ items = e.getElementsByTagName('items')[0];
+ // Handle Tune
+ if (items.getAttribute('node') == Strophe.NS.TUNE) {
+ handleTune(from, items.getElementsByTagName('tune')[0]);
+ }
+ return true;
+}
+
function _cbRoster(e) {
- var query = e.getElementsByTagName('query')[0];
- var entries = query.getElementsByTagName('item');
- for (var item=0; item 0) {
$('#' + id + ' p').append('
');
@@ -238,22 +300,14 @@ function sendMessage(form, to) {
return false;
}
-function createBubble(jid) {
- var id = jid2id(jid) + 'Chat';
- $('body').append('');
- $('#' + 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')
+ var id, jid, body;
+ if ($(msg).attr('type') != 'chat') {
return true;
- var jid = $(msg).attr('from');
- var id = jid2id(jid) + 'Chat';
- var body = $(msg).find('body:first').text();
+ }
+ jid = $(msg).attr('from');
+ id = jid2id(jid) + 'Chat';
+ body = $(msg).find('body:first').text();
body = escape(body);
body = body.replace(/%0A/g, '
');
body = body.replace(/%3C/g, '<');
@@ -273,54 +327,24 @@ function _cbMessage(msg) {
return true;
}
-function genCaps() {
- var S = '';
- S += 'client/web//' + appName + '<'
- features.sort();
- for (var i = 0; i < features.length; i++) {
- S += features[i] + '<';
- }
- return b64_sha1(S);
-}
-
-function handleTune(jid, tuneXML) {
- var tune = new Tune();
- if (tuneXML.childNodes.length > 0) {
- tune.artist = Strophe.getText(tuneXML.getElementsByTagName('artist')[0]);
- tune.length= Strophe.getText(tuneXML.getElementsByTagName('length')[0]);
- tune.rating= Strophe.getText(tuneXML.getElementsByTagName('rating')[0]);
- tune.source= Strophe.getText(tuneXML.getElementsByTagName('source')[0]);
- tune.title= Strophe.getText(tuneXML.getElementsByTagName('title')[0]);
- tune.track= Strophe.getText(tuneXML.getElementsByTagName('track')[0]);
- tune.uri= Strophe.getText(tuneXML.getElementsByTagName('uri')[0]);
- if (roster[jid2id(jid)].visible == true) {
- if ( $('#tune').length > 0) {
- $('#tune').empty();
- $('#tune').append('Tune: ');
- $('#tune').append(Strophe.xmlTextNode('Listening to '+ tune.title +
- ' by ' + tune.artist + ' from ' + tune.source));
- } else {
- $('#vCard ul').append('Tune: Listening to '+ tune.title +
- ' by ' + tune.artist + ' from ' + tune.source + '')
- }
- }
- } else {
- $('#tune').remove();
- }
- roster[jid2id(jid)].tune = tune;
-}
+function showConnect() {
+ var jid, pass, button;
+ jid = $('#jid');
+ pass = $('#pass');
+ button = $('#connect').get(0);
-function _cbPEP(e) {
- var from = e.getAttribute('from');
- if (Strophe.getBareJidFromJid(from) == Strophe.getBareJidFromJid(connection.jid)) {
- return true; // Drop own PEP events
- }
- var items = e.getElementsByTagName('items')[0];
- // Handle Tune
- if (items.getAttribute('node') == NS_TUNE) {
- handleTune(from, items.getElementsByTagName('tune')[0]);
- }
- return true;
+ $('#log').empty();
+ $('#ownInfo').empty();
+ $('#ownInfo').hide();
+ $('#vCard_container').empty();
+ $('#friends').empty();
+ $('#friends').hide();
+ $('.chat').remove();
+ $('label').show();
+ jid.show();
+ pass.show();
+ button.value = 'connect';
+ return false;
}
function onConnect(status) {
@@ -348,29 +372,11 @@ function onConnect(status) {
}
}
-function showConnect() {
- var jid = $('#jid');
- var pass = $('#pass');
- var button = $('#connect').get(0);
-
- $('#log').empty();
- $('#ownInfo').empty();
- $('#ownInfo').hide();
- $('#vCard_container').empty();
- $('#friends').empty();
- $('#friends').hide();
- $('.chat').remove();
- $('label').show();
- jid.show();
- pass.show();
- button.value = 'connect';
- return false;
-}
-
function showDisconnect() {
- var jid = $('#jid');
- var pass = $('#pass');
- var button = $('#connect').get(0);
+ var jid, pass, button;
+ jid = $('#jid');
+ pass = $('#pass');
+ button = $('#connect').get(0);
button.value = 'disconnect';
pass.hide();
@@ -380,6 +386,7 @@ function showDisconnect() {
}
$(document).ready(function () {
+ var button, jid, pass;
if (DEBUG) {
$('#log_container').show();
}
@@ -392,13 +399,13 @@ $(document).ready(function () {
});
$('#cred').bind('submit', function () {
- var button = $('#connect').get(0);
- var jid = $('#jid');
- var pass = $('#pass');
+ button = $('#connect').get(0);
+ jid = $('#jid');
+ pass = $('#pass');
localJID = jid.get(0).value;
if (button.value == 'connect') {
- showDisconnect();
+ showDisconnect();
connection.connect(localJID,
pass.get(0).value,
onConnect);
@@ -436,12 +443,12 @@ function stopDrag(eve) {
dragElement = null;
}
-onunload = function() {
+var onunload = function() {
if (connection) {
connection.disconnect();
}
-}
+};
-onmousemove = doDrag;
-onmouseup = stopDrag;
+var onmousemove = doDrag;
+var onmouseup = stopDrag;