Last active
September 26, 2015 19:47
-
-
Save jiggliemon/1149852 to your computer and use it in GitHub Desktop.
This file contains 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
(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