facebook-ext.js 1.7 KB

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