Skip to content

Instantly share code, notes, and snippets.

@sungmin-park
Last active December 10, 2015 03:08
Show Gist options
  • Save sungmin-park/4372271 to your computer and use it in GitHub Desktop.
Save sungmin-park/4372271 to your computer and use it in GitHub Desktop.
Facebook Javascript SDK loader with jQuery
$.facebook = (id, {locale}={}, callback=->) ->
locale ?= 'en_US'
window.fbAsyncInit = ->
FB.init appId: id, status: true, cookie: true, xfbml: true
FB.Canvas.setAutoGrow()
FB.getLoginStatus callback
$('body').append $('<div>').attr('id', 'fb-root')
$('<script>').each ->
@id = 'facebook-jssdk'
@async = true
@src = "//connect.facebook.net/#{locale}/all.js"
$('head').append @
// Generated by CoffeeScript 1.3.3
(function() {
$.facebook = function(id, _arg, callback) {
var locale;
locale = (_arg != null ? _arg : {}).locale;
if (callback == null) {
callback = function() {};
}
if (locale == null) {
locale = 'en_US';
}
window.fbAsyncInit = function() {
FB.init({
appId: id,
status: true,
cookie: true,
xfbml: true
});
FB.Canvas.setAutoGrow();
return FB.getLoginStatus(callback);
};
$('body').append($('<div>').attr('id', 'fb-root'));
return $('<script>').each(function() {
this.id = 'facebook-jssdk';
this.async = true;
this.src = "//connect.facebook.net/" + locale + "/all.js";
return $('head').append(this);
});
};
}).call(this);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment