Socialmedia supports the AddThis facebook like button, but not the more complete "Like button" widget provided by facebook (http://developers.facebook.com/docs/reference/plugins/like/) which can include extended functionalities as text font, send button,...
Patch is proposed below. Thanks for this great module !

Comments

pverrier’s picture

StatusFileSize
new4.04 KB

I've updated the patch (was not taking the good url).

KoCo’s picture

sorry, wrong queue, ah now I'm following, which is also fine ;-).
And currently testing the patch too.

TomDude48’s picture

Status: Active » Needs review

Thanks for the patch. This is a great addition, will be in my next push.

pverrier’s picture

StatusFileSize
new3.31 KB

Thanks Tom ! :) Glad to contribute a little !

I propose some modifications, because I've problems when there are more than one widget loading the facebook library in the same page...

For now, the FB loading script (in socialmedia.widgets.inc L471 socialmedia_widgets_facebook_js_sdk()) is :

<script>if(window.FB){ window.FB = null ;}//eat this !</script>
<div id="fb-root"></div>
<script>(function(d, s, id) {
  var js, fjs = d.getElementsByTagName(s)[0];
  if (d.getElementById(id)) {return;}
  js = d.createElement(s); js.id = id;
  js.src = "//connect.facebook.net/en_US/all.js#xfbml=1&appId=223324211035941";
  fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));</script>

It's generated just before the tag producing the widget, each time.

I presume the first line <script>if(window.FB){ window.FB = null ;}//eat this !</script>, which is not part of the facebook script, was to nullify and force the reloading of the FB library in the case of more than one widget generates its loading. That doesn't work for me (FF10 or Chrome17), and no widget is displayed.

I propose the patch below (from the current dev version), which needs some explanations :

  global $language;
  $loc = $language->language.'_'.variable_get('site_default_country', 'US');
  $facebook_js_sdk = '<script>
if (!document.getElementById("fb-root")) {
  fb_root = document.createElement("div");
  fb_root.id = "fb-root";
  document.body.insertBefore(fb_root,document.body.firstChild);
  (function(d, s, id) {
    var js, fjs = d.getElementsByTagName(s)[0];
    if (d.getElementById(id)) {return;}
    js = d.createElement(s); js.id = id;
    js.src = "//connect.facebook.net/'.$loc.'/all.js#xfbml=1";
    fjs.parentNode.insertBefore(js, fjs);
  }(document, "script", "facebook-jssdk"));
}</script>';
  1. My widgets were displayed in english, but I want them in french. I added the localization in the javascript library path, based on site language and country.
  2. I removed the &appId=223324211035941, but I'm not sure it's correct. If I've well understood the appId is linked to the site, which must be registred on facebook, so I don't think it can be a constant like this... Please tell me if I'm wrong !
  3. The current version generates a <div id="fb-root"></div> each time a facebook widget is displayed, in my case two times because I use the like button I added, and the like box (in another set)... And the browser doesn't like having the same id twice... So I test the existence of this id to generate the div/id and the library import only once.
  4. I insert this div just at the beginning of the body, I think it's a better place (Twitter and AddThis apparently do the same, and it's recommended by Facebook).

I also added in the patch the corrections #1.

TomDude48’s picture

It seems to work well. I had to make one adjustment to how the country was handled for sites where the county had not been set. Other that that your patch worked.

TomDude48’s picture

Issue summary: View changes

text correction