123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115 |
- /* 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", "lib-app/facebook-oauth", "storage");
- // TODO new FBML tags
- importTags(this, [
- "FB:INTL",
- "FB:INTL-TOKEN",
- "FB:TAG-ATTRIBUTE",
- "FB:TAG-BODY",
- "FB:FBML-ATTRIBUTE",
- "FB:TAG",
- "FB:DATE",
- "FB:WALL",
- ]);
- /**
- * 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.isAppAdded = +request.params.fb_sig_added;
- fb.canvasPath = function (tail) { return fb.fullCanvasUrl+tail; };
- 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));
- }
- };
- import("lib-support/useful");
- /** 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;
- },
- /**
- * Creates FB_INTL from supplied element.
- * Element should have desc (description),
- * body (text that may contain {tokens}),
- * tokens (comma-separated list of token names
- * to be inserted as FB_INTL_TOKEN, optional)
- * and multiline (if defined, contains delimiter token name
- * that is inserted as <br />, optional).
- * fbIntl.tokens contains functions that populate token bodies,
- * you should populate it if you want to have FB_INTL_TOKENs inserted.
- * Token populator functions in localTokenFuns arg are also used, if supplied.
- * If replacer function does not exist, the token is not inserted
- * and no warning or error is raised.
- */
- fbIntl: function fbIntl (element, localTokenFuns) {
- var result = FB_INTL({desc: element.desc});
- var body = [element.body];
- var tokens = element.tokens ? element.tokens.split(",") : [],
- tokenFuns = fbIntl.tokens;
- if (!localTokenFuns) { localTokenFuns = {}; }
- if (element.multiline) {
- tokens.push(element.multiline);
- var br = BR();
- localTokenFuns[element.multiline] = function () { return br; };
- }
- tokens.forEach(function (token) {
- var f = localTokenFuns[token] || tokenFuns[token];
- if (f) {
- if (f.direct) {
- splitReplace(body, "{"+token+"}", f(token, element));
- } else {
- result.push(FB_INTL_TOKEN({name:token}, f(token, element)));
- }
- }
- });
- result.unshift.apply(result, body);
- return result;
- }//,
- };
- fb.ui.fbIntl.tokens = {};
|