var connection = null;
var show_log = true;
+var roster = new Array();
+
function log(msg) {
var entry = $('<div></div>').append(document.createTextNode(msg));
$('#log').append(entry);
return jid.split('@').join('-').split('.').join('-');
}
-function _cbVCard(e) {
- var jid = e.getAttribute('from');
+function populateVCard(e, jid) {
+ var easy_cases = new Array('FN', 'FAMILY', 'MIDDLE', 'GIVEN', 'NICKNAME', 'BDAY', 'CTRY', 'USERID');
+ for (var i=0; i<easy_cases.length; i++) {
+ var text = e.getElementsByTagName(easy_cases[i])[0];
+ if (text) {
+ text = Strophe.getText(text);
+ $('#'+easy_cases[i]).append(document.createTextNode(text));
+ }
+ }
var avatar = e.getElementsByTagName('PHOTO')[0];
if (avatar) {
var mime = Strophe.getText(avatar.getElementsByTagName('TYPE')[0]);
var binval = Strophe.getText(avatar.getElementsByTagName('BINVAL')[0]);
$("#"+jid2id(jid)+" img").attr('src', 'data:'+mime+';base64,'+binval);
+ $("#PHOTO img").attr('src', 'data:'+mime+';base64,'+binval);
+ }
+ $('#vCard_container').slideDown("normal");
+}
+
+function _cbVCard(e) {
+ var jid = e.getAttribute('from');
+ if (roster[jid2id(jid)].vCard == "") {
+ roster[jid2id(jid)].vCard = e;
+ }
+ if ($('#vCard_container').is(':visible')) {
+ $('#vCard_container').hide();
}
+ $('#vCard_container').empty();
+ $('#vCard_container').load('vCard.html #vCard', function() {populateVCard(e, jid);});
return false;
}
-function getAvatar(jid) {
+function getVCard(jid) {
var id = 'getvCard'+jid2id(jid);
- var vCardiq = $iq({'to':jid,
+ if (roster[jid2id(jid)].vCard == "") {
+ var vCardiq = $iq({'to':jid,
'id':id,
'type':'get'}
- ).c('vCard', {'xmlns':NS_VCARD});
- connection.addHandler(_cbVCard, null, 'iq', 'result', id);
- connection.send(vCardiq.tree());
+ ).c('vCard', {'xmlns':NS_VCARD});
+ connection.addHandler(_cbVCard, null, 'iq', 'result', id);
+ connection.send(vCardiq.tree());
+ } else {
+ _cbVCard(roster[jid2id(jid)].vCard);
+ }
}
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() {
- getAvatar(jid);
+ getVCard(jid);
});
}
var button = $('#connect').get(0);
$('#log').empty();
+ $('#vCard_container').empty();
$('#friends').empty();
$('label').show();
jid.show();
connection.rawInput = rawInput;
connection.rawOutput = rawOutput;
- $("#log_toggle").bind('click', function () {
+ $("#log_toggle").click(function () {
$("#log").toggle();
- }
- );
+ });
+
+ $('#vCard_container').click(function () {
+ $('#vCard_container').slideUp("normal");
+ });
$('#cred').bind('submit', function () {
var button = $('#connect').get(0);
--- /dev/null
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http: //www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
+<html xmlns="http: //www.w3.org/1999/xhtml">
+<head>
+ <title>vCard</title>
+</head>
+<body>
+ <div id='vCard'>
+ <div id="PHOTO"><span class="vCardName">Avatar: </span><img src="imgs/none.png" /></div>
+ <div id="FN"><span class="vCardName">Full Name: </span></div>
+ <div id="FAMILY"><span class="vCardName">Last Name: </span></div>
+ <div id="GIVEN"><span class="vCardName">First Name: </span></div>
+ <div id="MIDDLE"><span class="vCardName">Middle Name: </span></div>
+ <div id="NICKNAME"><span class="vCardName">Nickname: </span></div>
+ <div id="BDAY"><span class="vCardName">Birthday: </span></div>
+ <div id="TELWORK"><span class="vCardName">Telephone (Work): </span></div>
+ <div id="TELHOME"><span class="vCardName">Telephone (Home): </span></div>
+ <div id="CTRY"><span class="vCardName">Country: </span></div>
+ <div id="USERID"><span class="vCardName">E-Mail: </span></div>
+ </div>
+</body>
+</html>
+