Last active
December 10, 2015 03:08
-
-
Save sungmin-park/4372271 to your computer and use it in GitHub Desktop.
Facebook Javascript SDK loader with jQuery
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
$.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 @ | |
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
// 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