Last active
May 2, 2018 10:51
-
-
Save kaneshin/5360120 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
<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