Skip to content

Instantly share code, notes, and snippets.

@jiggliemon
Last active September 26, 2015 19:47
Show Gist options
  • Save jiggliemon/1149852 to your computer and use it in GitHub Desktop.
Save jiggliemon/1149852 to your computer and use it in GitHub Desktop.
(function(jq){
var _events = [];
var _FB = {
count: 0
,interval : setInterval(function(){
try{
if(FB._session && (typeof FB._session !== 'undefined')){
clearInterval(_FB.interval);
jq.each(_events, function(indexhereisretarded,fn){
fn();
});
delete _events;
jq.fbReady = function(fn){
fn();
}
} else {
throw new Error('`FB` has no session');
}
} catch(e){
if(_FB.count++ > 100) {
clearInterval(_FB.interval);
throw new Error('`FB` hasn\'t become available.');
}
}
},15)
};
jq.fbReady = (function(){
return function(fn){
_events.push(fn);
};
})();
})(jQuery);
/*
Usage:
$.fbReady(function(){
console.log('FB is ready');
FB.api('/me',function(response){
console.log(response);
});
});
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment