Created
July 4, 2016 10:43
-
-
Save Thaina/c99b966eefdc4007babf0ccb02db0ff4 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
var resolved = false; | |
var resolving; | |
/* global FB */ | |
var fbResolver = new Promise((resolve,reject) => { | |
if(resolved) | |
return resolve(); | |
resolving = resolve; | |
}); | |
window.fbAsyncInit = function() { | |
resolved = true; | |
resolving(); | |
} | |
/* exported */ | |
function PromiseFaceBook(appId,version,init) { | |
if(!init) | |
init = { cookie: true,xfbml: true }; | |
init.version = version || "v2.5"; | |
init.appId = appId; | |
return fbResolver.then(() => { | |
FB.init(init); | |
return new Promise((resolve,reject) => { | |
FB.getLoginStatus(function(response) { | |
if(response.status !== 'connected') | |
return FB.login((response) => PromiseFaceBook(appId,version,init).then(resolve)); | |
resolve(response); | |
}); | |
}); | |
},console.error); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment