/* appjet:version 0.1 */ /* appjet:library */ // Copyright (c) 2009, 2010, Herbert Vojčík // Licensed by MIT license (http://www.opensource.org/licenses/mit-license.php) import("facebook", "storage"); // TODO new FBML tags importTags(this, [ "FB:INTL", "FB:INTL-TOKEN", "FB:TAG-ATTRIBUTE", "FB:TAG-BODY", "FB:TAG", ]); /** * Contains uid usable in not-logged canvas scenarios as well. * Either it contains fb.uid, canvas user or * "loggedinuser" */ fb.any_uid = fb.uid; if (fb.any_uid == -1) { fb.any_uid = request.params.fb_sig_canvas_user; if (!fb.any_uid) fb.any_uid = "loggedinuser"; } fb.requireLogin = function (perms) { if (request.params.fb_sig_added != '1') { fb.redirect("http://www.facebook.com/login.php?" +"v=1.0&" +"canvas=1&" +(perms?"req_perms="+perms.join()+"&":"") +"api_key="+storage.facebooklib.apiKey+"&" +"next="+encodeURIComponent(fb.fullCanvasUrl)); } }; /** Place for convenience extension functions for UI */ fb.ui = { /** * Creates tabs according to items parameter. * If actual url matches one of them, it is selected. * Next example renders tabs for .../callback/profile, .../callback/invite and .../callback/play. @example print(fb.ui.tabs("profile_Profile", "invite_Invite friends", "play_Play!")); */ tabs: function (items) { var menu = FB_TABS(); var lastSegment = request.path.split("/").pop(); items.forEach (function (item) { var split = item.split("_"); menu.push(FB_TAB_ITEM({ href: split[0], title: split[1], selected: lastSegment === split[0] })); }); return menu; } };