-
-
Save bloudermilk/3455989 to your computer and use it in GitHub Desktop.
Initialize Facebook JS SDK in Coffeescript
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@FBootloader = new class FBootloader | |
callbacks: [] | |
isReady: false | |
ready: -> | |
callback() for callback in @callbacks | |
bind: (callback) -> | |
if @isReady | |
callback() | |
else | |
@callbacks.push callback | |
@fbAsyncInit = -> | |
FB.init | |
appId: document.getElementById("fb-root").getAttribute("data-id") | |
FBootloader.ready() | |
# Async load the JS SDK | |
id = "facebook-jssdk" | |
ref = document.getElementsByTagName("script")[0] | |
unless 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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<title>My awesome webpage!</title> | |
<script src="/fb_init.js"></script> | |
<script src="/something_rad.js"></script> | |
</head> | |
<body> | |
<div id="fb-root" data-id="1234567890"></div> | |
</body> | |
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
FBootloader.bind -> FB.someRadThing("Foo bar baz!") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment