Skip to content

Instantly share code, notes, and snippets.

@patbenatar
Created August 24, 2012 21:29
Show Gist options
  • Save patbenatar/3455814 to your computer and use it in GitHub Desktop.
Save patbenatar/3455814 to your computer and use it in GitHub Desktop.
Initialize Facebook JS SDK in Coffeescript
# Important: this requires your Facebook App ID to be in data-id on #fb-root
window.fbAsyncInit = ->
FB.init
appId: document.getElementById("fb-root").getAttribute("data-id")
# Async load the JS SDK
id = "facebook-jssdk"
ref = document.getElementsByTagName("script")[0]
return if document.getElementById(id)
js = document.createElement("script")
js.id = id
js.async = true
js.src = "//connect.facebook.net/en_US/all.js"
ref.parentNode.insertBefore(js, ref)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment