Skip to content

Instantly share code, notes, and snippets.

@lautapercuspain
Forked from joho/layout.html.erb
Created August 24, 2012 17:35
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lautapercuspain/3453258 to your computer and use it in GitHub Desktop.
Save lautapercuspain/3453258 to your computer and use it in GitHub Desktop.
Doing custom facebook JS api stuff while loading their API async (from the layout).
<body>
<script>
window.fbAsyncInit = function() {
FB.init({
appId : 'YOUR_APP_ID', // App ID
status : true, // check login status
});
// check if the view has registered an "after facebook load callback"
if(typeof window.appSpecificFbAsyncInit == 'function') {
appSpecificFbAsyncInit();
}
};
// Load the SDK Asynchronously
(function(d){
var js, id = 'facebook-jssdk'; if (d.getElementById(id)) {return;}
js = d.createElement('script'); js.id = id; js.async = true;
js.src = "//connect.facebook.net/en_US/all.js";
d.getElementsByTagName('head')[0].appendChild(js);
}(document));
</script>
<%= yield %>
</body>
<script>
// some specific facebook stuff to for this view
window.appSpecificFbAsyncInit = function() {
FB.uid({ someUIoption : 'blahblahbla' });
};
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment