From: Florian Zeitz Date: Thu, 19 Aug 2010 19:08:17 +0000 (+0200) Subject: (Coding) style X-Git-Url: https://cgit.babelmonkeys.de/?a=commitdiff_plain;ds=sidebyside;p=socialXMPP.git (Coding) style * Tabs → Spaces * New strophejs version * Padding on vCards --- diff --git a/css/standard.css b/css/standard.css index 146a622..d0e6938 100644 --- a/css/standard.css +++ b/css/standard.css @@ -30,6 +30,7 @@ label { background: white; text-align: center; margin: 2em auto; + padding: 1em; width: 50%; overflow: auto; } diff --git a/scripts/basic.js b/scripts/basic.js index 7038a9a..4b0c0d0 100644 --- a/scripts/basic.js +++ b/scripts/basic.js @@ -38,7 +38,7 @@ function genCaps() { S += 'client/web//' + appName + '<'; features.sort(); for (i = 0; i < features.length; i++) { - S += features[i] + '<'; + S += features[i] + '<'; } return b64_sha1(S); } @@ -46,48 +46,48 @@ function genCaps() { function populateVCard(e, jid) { var easy_cases = ['FN', 'FAMILY', 'MIDDLE', 'GIVEN', 'NICKNAME', 'BDAY', 'CTRY', 'USERID'], i, text, avatar, mime, binval; for (i = 0; i < easy_cases.length; i++) { - text = e.getElementsByTagName(easy_cases[i])[0]; - if (text) { - text = Strophe.getText(text); - $('#' + easy_cases[i]).append(Strophe.xmlTextNode(text)); - } + text = e.getElementsByTagName(easy_cases[i])[0]; + if (text) { + text = Strophe.getText(text); + $('#' + easy_cases[i]).append(Strophe.xmlTextNode(text)); + } } avatar = e.getElementsByTagName('PHOTO')[0]; if (avatar) { - mime = Strophe.getText(avatar.getElementsByTagName('TYPE')[0]); - binval = Strophe.getText(avatar.getElementsByTagName('BINVAL')[0]); + mime = Strophe.getText(avatar.getElementsByTagName('TYPE')[0]); + binval = Strophe.getText(avatar.getElementsByTagName('BINVAL')[0]); - $("#"+jid2id(jid)+" img").attr('src', 'data:'+mime+';base64,'+binval); - $("#PHOTO img").attr('src', 'data:'+mime+';base64,'+binval); + $("#"+jid2id(jid)+" img").attr('src', 'data:'+mime+';base64,'+binval); + $("#PHOTO img").attr('src', 'data:'+mime+';base64,'+binval); } $(e).find('TEL:has(HOME)').each(function() { - $('#TELHOME').append(' '); + $('#TELHOME').append(' '); $('#TELHOME').append(Strophe.xmlTextNode($(this).find('NUMBER').text())); }); $(e).find('TEL:has(WORK)').each(function() { - $('#TELWORK').append(' '); + $('#TELWORK').append(' '); $('#TELWORK').append(Strophe.xmlTextNode($(this).find('NUMBER').text())); }); $(e).find('EMAIL:has(HOME)').each(function() { - $('#EMAILHOME').append(' '); + $('#EMAILHOME').append(' '); $('#EMAILHOME').append(Strophe.xmlTextNode($(this).find('USERID').text())); }); $(e).find('EMAIL:has(WORK)').each(function() { - $('#EMAILWORK').append(' '); + $('#EMAILWORK').append(' '); $('#EMAILWORK').append(Strophe.xmlTextNode($(this).find('USERID').text())); }); if (!roster[jid2id(jid)].tune.isEmpty()) { - $('#vCard ul').append('
  • Tune: Listening to '+ - roster[jid2id(jid)].tune.title + ' by ' + roster[jid2id(jid)].tune.artist + - ' from ' + roster[jid2id(jid)].tune.source + '
  • '); + $('#vCard ul').append('
  • Tune: Listening to '+ + roster[jid2id(jid)].tune.title + ' by ' + roster[jid2id(jid)].tune.artist + + ' from ' + roster[jid2id(jid)].tune.source + '
  • '); } $('#vCard').click(function () { $('#vCard_container').slideUp("normal", function() { - $('#box-overlay').hide(); - }); - roster[jid2id(jid)].visible = false; + $('#box-overlay').hide(); + }); + roster[jid2id(jid)].visible = false; }); $('#box-overlay').show(); @@ -98,10 +98,10 @@ function populateVCard(e, jid) { function _cbVCard(e) { var jid = e.getAttribute('from'); if (roster[jid2id(jid)].vCard === "") { - roster[jid2id(jid)].vCard = e; + roster[jid2id(jid)].vCard = e; } if ($('#vCard_container').is(':visible')) { - $('#vCard_container').hide(); + $('#vCard_container').hide(); } $('#vCard_container').empty(); $('#vCard_container').load('vCard.html #vCard', function() {populateVCard(e, jid);}); @@ -114,18 +114,18 @@ function _cbOwnVCard(e) { $('#ownInfo').empty(); $('#ownInfo').load('vCard.html #ownvCard', function() { for (i = 0; i < easy_cases.length; i++) { - text = e.getElementsByTagName(easy_cases[i])[0]; - if (text) { - text = Strophe.getText(text); - $('#own' + easy_cases[i]).append(Strophe.xmlTextNode(text)); - } + text = e.getElementsByTagName(easy_cases[i])[0]; + if (text) { + text = Strophe.getText(text); + $('#own' + easy_cases[i]).append(Strophe.xmlTextNode(text)); + } } avatar = e.getElementsByTagName('PHOTO')[0]; if (avatar) { - mime = Strophe.getText(avatar.getElementsByTagName('TYPE')[0]); - binval = Strophe.getText(avatar.getElementsByTagName('BINVAL')[0]); + mime = Strophe.getText(avatar.getElementsByTagName('TYPE')[0]); + binval = Strophe.getText(avatar.getElementsByTagName('BINVAL')[0]); - $("#ownPHOTO img").attr('src', 'data:'+mime+';base64,'+binval); + $("#ownPHOTO img").attr('src', 'data:'+mime+';base64,'+binval); } $(e).find('TEL:has(HOME)').each(function() { $('#ownTELHOME').append(Strophe.xmlTextNode($(this).find('NUMBER').text())); @@ -148,21 +148,21 @@ function _cbOwnVCard(e) { function getVCard(jid) { var id = connection.getUniqueId('vCardGet'), vCardiq; if (roster[jid2id(jid)].vCard === "") { - vCardiq = $iq({'to':jid, - 'id':id, - 'type':'get'} - ).c('vCard', {'xmlns': Strophe.NS.VCARD}); - connection.addHandler(_cbVCard, null, 'iq', 'result', id); - connection.send(vCardiq.tree()); + vCardiq = $iq({'to':jid, + 'id':id, + 'type':'get'} + ).c('vCard', {'xmlns': Strophe.NS.VCARD}); + connection.addHandler(_cbVCard, null, 'iq', 'result', id); + connection.send(vCardiq.tree()); } else { - _cbVCard(roster[jid2id(jid)].vCard); + _cbVCard(roster[jid2id(jid)].vCard); } } function getOwnInfo() { var id = connection.getUniqueId('vCardGet'), vCardiq = $iq({'id': id, 'type': 'get'} - ).c('vCard', {'xmlns': Strophe.NS.VCARD}); + ).c('vCard', {'xmlns': Strophe.NS.VCARD}); connection.addHandler(_cbOwnVCard, null, 'iq', 'result', id); connection.send(vCardiq.tree()); } @@ -170,24 +170,26 @@ function getOwnInfo() { function createBubble(jid) { var id = jid2id(jid) + 'Chat'; $('body').append('
    Close' + - ' ' + jid + '

    '); + ' ' + jid + '

    '); $('#' + id).append('
    '); - $('#' + id).css( 'top', $('#' + jid2id(jid)).position().top + 40); - $('#' + id).css( 'left', $('#' + jid2id(jid)).position().left + 40); + if ($('#' + jid2id(jid)).length > 0) { + $('#' + 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('

    '+nick+'
    '); $('#' + jid2id(jid) + ' img').click(function() { - getVCard(jid); + getVCard(jid); }); $('#' + jid2id(jid) + ' a').click(function() { - var id = jid2id(jid) + 'Chat'; - if ($('#' + id).length <= 0) { - createBubble(jid); - } - $('#' + id).show(); + var id = jid2id(jid) + 'Chat'; + if ($('#' + id).length <= 0) { + createBubble(jid); + } + $('#' + id).show(); }); } @@ -195,26 +197,26 @@ 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 + '
  • '); - } - } + 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(); + $('#tune').remove(); } roster[jid2id(jid)].tune = tune; } @@ -222,12 +224,12 @@ function handleTune(jid, tuneXML) { function _cbPEP(e) { var from = e.getAttribute('from'), items; if (Strophe.getBareJidFromJid(from) == Strophe.getBareJidFromJid(connection.jid)) { - return true; // Drop own PEP events + 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]); + handleTune(from, items.getElementsByTagName('tune')[0]); } return true; } @@ -236,11 +238,11 @@ function _cbRoster(e) { var query = e.getElementsByTagName('query')[0], entries = query.getElementsByTagName('item'), item, nick, initialPresence; for (item = 0; item < entries.length; item++) { - nick = entries[item].getAttribute('name'); - if (!nick) { - nick = entries[item].getAttribute('jid').split('@')[0]; - } - addFriend(entries[item].getAttribute('jid'), nick); + nick = entries[item].getAttribute('name'); + if (!nick) { + nick = entries[item].getAttribute('jid').split('@')[0]; + } + addFriend(entries[item].getAttribute('jid'), nick); } connection.addHandler(_cbPEP, Strophe.NS.PEP, 'message'); 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: Strophe.NS.CAPS, hash: 'sha-1', node: 'http://jabber.babelmonkeys.de', ver: genCaps()}).up(); @@ -256,8 +258,8 @@ function getRoster() { id = connection.getUniqueId('roster'); rosteriq = $iq({'id':id, - 'type':'get'} - ).c('query', {'xmlns':Strophe.NS.ROSTER}); + 'type':'get'} + ).c('query', {'xmlns':Strophe.NS.ROSTER}); connection.addHandler(_cbRoster, null, 'iq', 'result', id); connection.send(rosteriq.tree()); @@ -269,14 +271,14 @@ function _cbDisco(e) { jid = e.getAttribute('from'); if (jid) { - response = $iq({id: id, type: 'result', to: jid}); + response = $iq({id: id, type: 'result', to: jid}); } else { - response = $iq({id: id, type: 'result'}); + response = $iq({id: id, type: 'result'}); } query = response.c('query', {xmlns: Strophe.NS.DISCO_INFO}); query.c('identity', {category: 'client', type: 'web', name: appName}).up(); for (i = 0; i < features.length; i++) { - query.c('feature', {'var': features[i]}).up(); + query.c('feature', {'var': features[i]}).up(); } connection.send(response.tree()); @@ -286,15 +288,15 @@ function _cbDisco(e) { function sendMessage(form, to) { var id, message; if (form.text.value) { - id = jid2id(to) + 'Chat'; - message = $msg({'type': 'chat', 'to': to}).c('body').t(form.text.value); - connection.send(message.tree()); - if ($('#' + id + ' p *').length > 0) { - $('#' + id + ' p').append('
    '); - } - $('#' + id + ' p').append('' + localJID + ': '); - $('#' + id + ' p').append(form.text.value); - form.text.value = ''; + id = jid2id(to) + 'Chat'; + message = $msg({'type': 'chat', 'to': to}).c('body').t(form.text.value); + connection.send(message.tree()); + if ($('#' + id + ' p *').length > 0) { + $('#' + id + ' p').append('
    '); + } + $('#' + id + ' p').append('' + localJID + ': '); + $('#' + id + ' p').append(form.text.value); + form.text.value = ''; } return false; @@ -303,7 +305,7 @@ function sendMessage(form, to) { function _cbMessage(msg) { var id, jid, body; if ($(msg).attr('type') != 'chat') { - return true; + return true; } jid = $(msg).attr('from'); id = jid2id(jid) + 'Chat'; @@ -315,10 +317,10 @@ function _cbMessage(msg) { body = body.replace(/%26/g, '&'); body = unescape(body); if ($('#' + id).length <= 0) { - createBubble(jid); + createBubble(jid); } if ($('#' + id + ' p *').length > 0) { - $('#' + id + ' p').append('
    '); + $('#' + id + ' p').append('
    '); } $('#' + id + ' p').append('' + jid + ': '); $('#' + id + ' p').append(body); @@ -331,7 +333,7 @@ function showConnect() { var jid, pass, button; jid = $('#jid'); pass = $('#pass'); - button = $('#connect').get(0); + button = $('#connect').get(0); $('#log').empty(); $('#ownInfo').empty(); @@ -349,26 +351,26 @@ function showConnect() { function onConnect(status) { if (status == Strophe.Status.CONNECTING) { - log('Strophe is connecting.'); + log('Strophe is connecting.'); } else if (status == Strophe.Status.CONNFAIL) { - log('Strophe failed to connect.'); - showConnect(); + log('Strophe failed to connect.'); + showConnect(); } else if (status == Strophe.Status.DISCONNECTING) { - log('Strophe is disconnecting.'); + log('Strophe is disconnecting.'); } else if (status == Strophe.Status.DISCONNECTED) { - log('Strophe is disconnected.'); - showConnect(); + log('Strophe is disconnected.'); + showConnect(); } else if (status == Strophe.Status.AUTHFAIL) { - log('Authentication failed'); - if (connection) { - connection.disconnect(); - } + log('Authentication failed'); + if (connection) { + connection.disconnect(); + } } else if (status == Strophe.Status.CONNECTED) { - log('Strophe is connected.'); - getOwnInfo(); - getRoster(); - connection.addHandler(_cbDisco, Strophe.NS.DISCO_INFO, 'iq', 'get'); - connection.addHandler(_cbMessage, Strophe.NS.CLIENT, 'message'); + log('Strophe is connected.'); + getOwnInfo(); + getRoster(); + connection.addHandler(_cbDisco, Strophe.NS.DISCO_INFO, 'iq', 'get'); + connection.addHandler(_cbMessage, Strophe.NS.CLIENT, 'message'); } } @@ -376,7 +378,7 @@ function showDisconnect() { var jid, pass, button; jid = $('#jid'); pass = $('#pass'); - button = $('#connect').get(0); + button = $('#connect').get(0); button.value = 'disconnect'; pass.hide(); @@ -388,31 +390,31 @@ function showDisconnect() { $(document).ready(function () { var button, jid, pass; if (DEBUG) { - $('#log_container').show(); + $('#log_container').show(); } connection = new Strophe.Connection(BOSH_SERVICE); connection.rawInput = rawInput; connection.rawOutput = rawOutput; $("#log_toggle").click(function () { - $("#log").toggle(); + $("#log").toggle(); }); $('#cred').bind('submit', function () { - button = $('#connect').get(0); - jid = $('#jid'); - pass = $('#pass'); - localJID = jid.get(0).value; - - if (button.value == 'connect') { - showDisconnect(); - connection.connect(localJID, - pass.get(0).value, - onConnect); - } else { - connection.disconnect(); - } - return false; + button = $('#connect').get(0); + jid = $('#jid'); + pass = $('#pass'); + localJID = jid.get(0).value; + + if (button.value == 'connect') { + showDisconnect(); + connection.connect(localJID, + pass.get(0).value, + onConnect); + } else { + connection.disconnect(); + } + return false; }); }); @@ -434,8 +436,8 @@ function doDrag(eve) { mouseY = eve.pageY; if (dragElement) { - dragElement.style.left = (mouseX - offX) + 'px'; - dragElement.style.top = (mouseY - offY) + 'px'; + dragElement.style.left = (mouseX - offX) + 'px'; + dragElement.style.top = (mouseY - offY) + 'px'; } } @@ -445,7 +447,7 @@ function stopDrag(eve) { onunload = function() { if (connection) { - connection.disconnect(); + connection.disconnect(); } }; diff --git a/scripts/strophejs b/scripts/strophejs index 6d7b886..2a276a4 160000 --- a/scripts/strophejs +++ b/scripts/strophejs @@ -1 +1 @@ -Subproject commit 6d7b8863f0f36f73c0b65686956437d26bd93c01 +Subproject commit 2a276a4a6a7a988f43ba142d7bae5eda99fd5e08