facebook-ext.js 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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:INTL-TOKEN",
  10. "FB:TAG-ATTRIBUTE",
  11. "FB:TAG",
  12. ]);
  13. /**
  14. * Contains uid usable in not-logged canvas scenarios as well.
  15. * Either it contains fb.uid, canvas user or
  16. * "loggedinuser"
  17. */
  18. fb.any_uid = fb.uid;
  19. if (fb.any_uid == -1) {
  20. fb.any_uid = request.params.fb_sig_canvas_user;
  21. if (!fb.any_uid) fb.any_uid = "loggedinuser";
  22. }
  23. fb.requireLogin = function (perms) {
  24. if (request.params.fb_sig_added != '1') {
  25. fb.redirect("http://www.facebook.com/login.php?"
  26. +"v=1.0&"
  27. +"canvas=1&"
  28. +(perms?"req_perms="+perms.join()+"&":"")
  29. +"api_key="+storage.facebooklib.apiKey+"&"
  30. +"next="+encodeURIComponent(fb.fullCanvasUrl));
  31. }
  32. };
  33. /** Place for convenience extension functions for UI */
  34. fb.ui = {
  35. /**
  36. * Creates tabs according to items parameter.
  37. * If actual url matches one of them, it is selected.
  38. * Next example renders tabs for .../callback/profile, .../callback/invite and .../callback/play.
  39. @example
  40. print(fb.ui.tabs("profile_Profile", "invite_Invite friends", "play_Play!"));
  41. */
  42. tabs: function (items) {
  43. var menu = FB_TABS();
  44. var lastSegment = request.path.split("/").pop();
  45. items.forEach (function (item) {
  46. var split = item.split("_");
  47. menu.push(FB_TAB_ITEM({
  48. href: split[0],
  49. title: split[1],
  50. selected: lastSegment === split[0]
  51. }));
  52. });
  53. return menu;
  54. }
  55. };