Skip to content

Instantly share code, notes, and snippets.

@ElliotChong
Created October 2, 2012 23:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ElliotChong/3823888 to your computer and use it in GitHub Desktop.
Save ElliotChong/3823888 to your computer and use it in GitHub Desktop.
Include Facebook within a webpage via JS - No DOM elements necessary
window.fbAsyncInit = ->
FB.init
appId: '0123456789' # App ID
channelUrl: "//#{ window.location.hostname }/channel.html" # Channel File
status: true # Check login status
cookie: true # Enable cookies to allow the server to access the session
xfbml: true # parse XFBML
frictionlessRequests: true # Enable frictionless Request dialogs
# Application-specific initialization code goes here
((document) ->
# Create fb-root div if it doesn't exist
do ->
id = 'fb-root'
if document.getElementById(id)? then return
ref = document.getElementsByTagName('body')[0]
div = document.createElement 'div'
div.id = id
ref.insertBefore div
# Load the JS SDK if it isn't already loaded
do ->
id = 'facebook-jssdk'
if document.getElementById(id)? then return
ref = document.getElementsByTagName('script')[0]
js = document.createElement 'script'
js.id = id
js.async = true
js.src = "//connect.facebook.net/en_US/all.js"
ref.parentNode.insertBefore js, ref
)(window.document)
(function() {
window.fbAsyncInit = function() {
FB.init({
appId: '0123456789',
channelUrl: "//" + window.location.hostname + "/channel.html",
status: true,
cookie: true,
xfbml: true,
frictionlessRequests: true
});
return angular.bootstrap(window.document, ['cake']);
};
(function(document) {
(function() {
var div, id, ref;
id = 'fb-root';
if (document.getElementById(id) != null) {
return;
}
ref = document.getElementsByTagName('body')[0];
div = document.createElement('div');
div.id = id;
return ref.insertBefore(div);
})();
return (function() {
var id, js, ref;
id = 'facebook-jssdk';
if (document.getElementById(id) != null) {
return;
}
ref = document.getElementsByTagName('script')[0];
js = document.createElement('script');
js.id = id;
js.async = true;
js.src = "//connect.facebook.net/en_US/all.js";
return ref.parentNode.insertBefore(js, ref);
})();
})(window.document);
}).call(this);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment