facebook-ext.js 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. /* appjet:version 0.1 */
  2. /* appjet:library */
  3. // Copyright (c) 2009, 2010, Herbert Vojčík
  4. // Licensed by MIT license (http://www.opensource.org/licenses/mit-license.php)
  5. import("facebook", "storage");
  6. // TODO new FBML tags
  7. importTags(this, [
  8. "FB:INTL",
  9. "FB:TAG-ATTRIBUTE",
  10. "FB:TAG",
  11. ]);
  12. /**
  13. * Contains uid usable in not-logged canvas scenarios as well.
  14. * Either it contains fb.uid, canvas user or
  15. * "loggedinuser"
  16. */
  17. fb.any_uid = fb.uid;
  18. if (fb.any_uid == -1) {
  19. fb.any_uid = request.params.fb_sig_canvas_user;
  20. if (!fb.any_uid) fb.any_uid = "loggedinuser";
  21. }
  22. fb.requireLogin = function (perms) {
  23. if (request.params.fb_sig_added != '1') {
  24. fb.redirect("http://www.facebook.com/login.php?"
  25. +"v=1.0&"
  26. +"canvas=1&"
  27. +(perms?"req_perms="+perms.join()+"&":"")
  28. +"api_key="+storage.facebooklib.apiKey+"&"
  29. +"next="+encodeURIComponent(fb.fullCanvasUrl));
  30. }
  31. };
  32. /** Place for convenience extension functions for UI */
  33. fb.ui = {
  34. /**
  35. * Creates tabs according to items parameter.
  36. * If actual url matches one of them, it is selected.
  37. * Next example renders tabs for .../callback/profile, .../callback/invite and .../callback/play.
  38. @example
  39. print(fb.ui.tabs("profile_Profile", "invite_Invite friends", "play_Play!"));
  40. */
  41. tabs: function (items) {
  42. var menu = FB_TABS();
  43. var lastSegment = request.path.split("/").pop();
  44. items.forEach (function (item) {
  45. var split = item.split("_");
  46. menu.push(FB_TAB_ITEM({
  47. href: split[0],
  48. title: split[1],
  49. selected: lastSegment === split[0]
  50. }));
  51. });
  52. return menu;
  53. }
  54. };