Skip to content

Instantly share code, notes, and snippets.

@andershaig
Forked from GCheung55/FB.init.detector.js
Created November 21, 2011 19:12
Show Gist options
  • Save andershaig/1383584 to your computer and use it in GitHub Desktop.
Save andershaig/1383584 to your computer and use it in GitHub Desktop.
Facebook Init detector!
// Sample of usage
$(document).bind('FB.ready',function(){
console.log('FB is ready');
FB.api('/me',function(response){
console.log(response);
});
});
// Init Detector
var _FB = {
count: 0
,interval : setInterval(function(){
try{
if(FB._session && (typeof FB._session !== 'undefined')){
clearInterval(_FB.interval);
$(document).trigger('FB.ready');
}
} catch(e){
if(_FB.count++ > 100) {
clearInterval(_FB.interval);
throw new Error('`FB` hasn\'t become available.');
}
}
},15)
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment