Bladeren bron

multiline refactor

Herbert Vojčík 14 jaren geleden
bovenliggende
commit
73d3d92d66
1 gewijzigde bestanden met toevoegingen van 15 en 13 verwijderingen
  1. 15 13
      lib-app/facebook-ext.js

+ 15 - 13
lib-app/facebook-ext.js

@@ -3,7 +3,7 @@
 // Copyright (c) 2009, 2010, Herbert Vojčík
 // Licensed by MIT license (http://www.opensource.org/licenses/mit-license.php)
 
-import("facebook", "storage", "lib-support/useful");
+import("facebook", "storage");
 
 // TODO new FBML tags
 importTags(this, [
@@ -64,8 +64,8 @@ fb.ui = {
    * 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
-   * that is replaced with BR()s, 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.
    * If replacer function does not exist, the token is not inserted
@@ -74,19 +74,21 @@ fb.ui = {
   fbIntl: function fbIntl (element) {
     var result = FB_INTL({desc: element.desc});
 
+    result.push(element.body);
+
+    var tokens = element.tokens ? element.tokens.split(",") : [],
+      tokenFuns = fbIntl.tokens;
     if (element.multiline) {
-      parts = splitReplace([element.body], element.multiline, BR());
-      result.push.apply(result, parts);
-    } else {
-      result.push(element.body);
+      tokens.push(element.multiline);
+      tokenFuns = object(tokenFuns);
+      var br = BR();
+      tokenFuns[element.multiline] = function () { return br; };
     }
 
-    if (element.tokens) {
-      element.tokens.split(",").forEach(function (token) {
-        var f = fbIntl.tokens[token];
-        if (f) { result.push(FB_INTL_TOKEN({name:token}, f(token, element))); }
-      });
-    }
+    tokens.forEach(function (token) {
+      var f = tokenFuns[token];
+      if (f) { result.push(FB_INTL_TOKEN({name:token}, f(token, element))); }
+    });
 
     return result;
   },