FBF rewrite

by Kenneth Luplau-Brøgger

HTML

<!doctype html>
<html class="da-dk not-ready not-connected loading loading-userdata" lang="da"
xmlns:og="https://ogp.me/ns" xmlns:fb="https://www.facebook.com/2008/fbml">
  
  <head>
    <meta property="fb:app_id" content='369846153104611' />
  </head>
  
  <body></body>

</html>

JavaScript

$(function () {
  $.FBF = {};
  
  //A set of functions used by FBF
  $.FBF.fn = {
    //Gets the app Id from meta tags in the head
    _getAppId: function() {
      var metaTags = document.getElementsByTagName("meta"),
          appId;
      for (var i = 0; i < metaTags.length; i++) {
        if (metaTags[i].getAttribute("property") == "fb:app_id") {
          appId = metaTags[i].getAttribute("content");
          break
        }
      }
      return appId
    },
    
    loading: {
      init: function() {
        $.FBF.config.$container.addClass("not-ready not-connected loading loading-userdata");
      },
      set: function (loading) {
      }
    }
  };
  
  //The default options/configuation of FBF
  $.FBF.config = {
      appId: this.appId || $.FBF.fn._getAppId(), //Facebook App ID
      scope: null, //Array of permissions
      facebookpage: null, //If the application is a Page Tab App, this setting should be set to whatever page the app is located on
      $container: $("body"), //Bindings and classes will be added to this selector
      redirectUrl: document.location.protocol + "//" + document.location.host + document.location.pathname, //The URL which the application should redirect back to, if redirected to Facebook
      mobileUrl: document.location.protocol + "//" + document.location.host + document.location.pathname, //The URL which mobiles will be redirected to
      loading: true //Adds loading classes to the $container element
  };
  
  //Initial function which are kicked on by user
  $.FBF.init = function (config, callback) {    
    $.FBF.config = $.extend($.FBF.config, config);
    
    //Handle loading
    if ($.FBF.config.loading && typeof $.FBF.config.$container !== "undefined") {
      $.FBF.fn.loading.init();
    }
    
    //Callbackhandler. Init returns selected properties to the user
    if (callback) {
      var initReturn = $.FBF.initReturn = {};
      
      //All information returned to the client, defined as strings
      var...