Skip to content

Instantly share code, notes, and snippets.

@kaneshin
Last active May 2, 2018 10:51
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save kaneshin/5360120 to your computer and use it in GitHub Desktop.
Save kaneshin/5360120 to your computer and use it in GitHub Desktop.
<script>
// fbAsyncInit
// http://developers.facebook.com/docs/reference/javascript/FB.getLoginStatus/
window.fbAsyncInit = function() {
// init the FB JS SDK
FB.init({
appId: '<?php echo(FB_APP_ID); ?>',
status: true,
cookie: true,
xfbml: true,
oauth: true
});
// Additional initialization code such as adding Event Listeners goes here
// declare objects
var $start_button = $('#start_button > a');
var login = function(success, cancel) {
FB.login(function(response) {
if (response.authResponse) {
if (success) success();
} else {
if (cancel) cancel();
}
}, { scope: '<?php echo FB_APP_SCOPE; ?>' });
};
var check_page_like = function(success, failure) {
FB.api('/me/likes/<?php echo FB_PAGE_ID?>', function(response) {
if (response.data.length) {
if (success) success();
} else {
if (failure) failure();
}
});
};
// To determine if a user has authenticated your app:
FB.getLoginStatus(function(response) {
});
FB.Event.subscribe('auth.statusChange', function(response) {
console.log('auth.statusChange: ', response.status);
if (response.status === 'connected') {
$start_button.on('click', function() {
check_page_like(function() {
location.href = '../../diagnosis/info';
}, function() {
// TODO: DEPRECATED display:none
$('#like_box').css('display', 'block');
});
});
} else if (response.status === 'not_authorized') {
$start_button.on('click', function() {
login(function() {
$start_button.off('click');
}, function() {
});
});
} else {
$start_button.on('click', function() {
login(function() {
$start_button.off('click');
}, function() {
});
});
}
});
FB.Event.subscribe('edge.create', function(response) {
location.href = '../../diagnosis/info';
});
};
// Load the SDK asynchronously
(function(d, s, id){
var js, fjs = d.getElementsByTagName(s)[0];
if (d.getElementById(id)) {return;}
js = d.createElement(s); js.id = id;
js.src = "//connect.facebook.net/en_US/all.js";
fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment