tmort / Socialite

Other
1.68k stars 163 forks source link

Conflict with Facebook Comments #12

Closed graygilmore closed 10 years ago

graygilmore commented 12 years ago

Facebook Comments require the following code to be present on the page:

<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";
  fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));</script>

This seems to cause some sort of conflict with Socialite. If that code is already present on the page, the Facebook Like button will not display. Has anyone else run into this? I feel like I'm missing something simple here.

dbushell commented 12 years ago

The like button requires the exact same code. On the first instance Socialite will embed this and it does the work, following instances are created with an iframe. It's very likely that because this already exists for Facebook Comments the first like button fails.

I'll push up a fix soon. Thanks for the bug report!

dbushell commented 12 years ago

Pushed a fix.

By the way, you could remove that code entirely and just keep the single .fb-comments element. If you have a Facebook like button on the page Socialite will trigger the comments too. In future, I'll include the comments class so Socialite looks for it.

graygilmore commented 12 years ago

I'll check out the fix.

Your other option works unless you're displaying comment counts on the page (eg, "8 Comments") as those need to be loaded before any of the share buttons get triggered.

dbushell commented 12 years ago

I see — good point!

To be honest, if you're using Facebook Comments (or other plugins) it might be less hassle to just bite the bullet and use their .fb-like element for the Like button to avoid confusion — at least until Socialite adds broader support. The JavaScript SDK include is one of the biggest resources which you won't be able to defer for long in this scenario.

tmort commented 10 years ago

Going to rework fb integration to hopefully cure these issues. For now, closing the issue and setting it to milestone v2.1