facebook-ext.js 1.6 KB

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