-
-
Save andershaig/1383584 to your computer and use it in GitHub Desktop.
Facebook Init detector!
This file contains hidden or 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
// 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