Skip to content

Instantly share code, notes, and snippets.

@mmhan
Forked from ralphholzmann/FBReady.js
Created April 25, 2011 02:18
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 mmhan/940073 to your computer and use it in GitHub Desktop.
Save mmhan/940073 to your computer and use it in GitHub Desktop.
function FBReady( func ) {
// If facebook is already loaded,
// just call the function
if ( FBReady.done ) return func();
// If the stack already exists,
// push the function onto it,
// otherwise, initialize a stack
// of functions
FBReady.stack ?
FBReady.stack.push( func ) :
FBReady.stack = [ func ] ;
};
FBReady.callStack = function( FB ) {
// Call the stack of functions
for ( var i = 0, count = FBReady.stack.length; i < count; i++ ) {
FBReady.stack[ i ].call( FB );
}
// Empty the stack
FBReady.stack = null;
};
window.fbAsyncInit = function() {
FB.init({
appId: '132217840124735'
, status: true
, cookie: true
, xfbml: true
});
// If a stack of functions exist, start
// calling them
FBReady.stack && FBReady.callStack( FB );
// Flag that we're done so any functions
// passed to FBReady after this point
// will execute immediately
FBReady.done = true;
};
// Asynchronous FB API loading, copied from their site
(function() {
var e = document.createElement('script');
e.async = true;
e.src = document.location.protocol +
'//connect.facebook.net/en_US/all.js';
document.getElementById('fb-root').appendChild(e);
}());
// Examples
FBReady(function(){
alert('facebook is ready!')
// FB.getLoginStatus( function(){ // Do stuff } );
});
FBReady(function(){
// You can pass multiple functions to FBReady and they
// will all execute in the order they were passed
alert('Hello World!')
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment