strophe.vcard.js 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. // Generated by CoffeeScript 1.3.3
  2. /*
  3. Plugin to implement the vCard extension.
  4. http://xmpp.org/extensions/xep-0054.html
  5. Author: Nathan Zorn (nathan.zorn@gmail.com)
  6. CoffeeScript port: Andreas Guth (guth@dbis.rwth-aachen.de)
  7. */
  8. /* jslint configuration:
  9. */
  10. /* global document, window, setTimeout, clearTimeout, console,
  11. XMLHttpRequest, ActiveXObject,
  12. Base64, MD5,
  13. Strophe, $build, $msg, $iq, $pres
  14. */
  15. var buildIq;
  16. buildIq = function(type, jid, vCardEl) {
  17. var iq;
  18. iq = $iq(jid ? {
  19. type: type,
  20. to: jid
  21. } : {
  22. type: type
  23. });
  24. iq.c("vCard", {
  25. xmlns: Strophe.NS.VCARD
  26. });
  27. if (vCardEl) {
  28. iq.cnode(vCardEl);
  29. }
  30. return iq;
  31. };
  32. Strophe.addConnectionPlugin('vcard', {
  33. _connection: null,
  34. init: function(conn) {
  35. this._connection = conn;
  36. return Strophe.addNamespace('VCARD', 'vcard-temp');
  37. },
  38. /*Function
  39. Retrieve a vCard for a JID/Entity
  40. Parameters:
  41. (Function) handler_cb - The callback function used to handle the request.
  42. (String) jid - optional - The name of the entity to request the vCard
  43. If no jid is given, this function retrieves the current user's vcard.
  44. */
  45. get: function(handler_cb, jid, error_cb) {
  46. var iq;
  47. iq = buildIq("get", jid);
  48. return this._connection.sendIQ(iq, handler_cb, error_cb);
  49. },
  50. /* Function
  51. Set an entity's vCard.
  52. */
  53. set: function(handler_cb, vCardEl, jid, error_cb) {
  54. var iq;
  55. iq = buildIq("set", jid, vCardEl);
  56. return this._connection.sendIQ(iq, handler_cb, error_rb);
  57. }
  58. });