Skip to content

Instantly share code, notes, and snippets.

@gashtio
Created February 22, 2013 08:47
Show Gist options
  • Save gashtio/5011854 to your computer and use it in GitHub Desktop.
Save gashtio/5011854 to your computer and use it in GitHub Desktop.
Displaying a button with a varying background image, depending on whether the user is logged in (in the Unity3D Facebook integration with Coherent UI sample)
var appID = '344764665598630';
var appURL = 'http://www.coherent-labs.com/sample.html';
if (window.location.hash.length == 0)
{
// Not logged in
$(function () {
var button = $('<div id="fbButton" class="fbLogoDisabled"></div>');
button.click(function () {
var path = 'https://www.facebook.com/dialog/oauth?';
var queryParams = {
client_id: appID,
redirect_uri: appURL,
response_type: 'token,signed_request,code',
scope: 'user_photos,publish_stream'
};
var url = path + $.param(queryParams);
// redirect the view to the facebook authorization dialog
window.location.href = url;
});
$('body').append(button);
});
}
else
{
// Logged in
// Load the Facebook SDK source
(function(d){
var js, id = 'facebook-jssdk', ref = d.getElementsByTagName('script')[0];
if (d.getElementById(id)) {return;}
js = d.createElement('script'); js.id = id; js.async = true;
js.src = "http://connect.facebook.net/en_US/all.js";
ref.parentNode.insertBefore(js, ref);
}(document));
$(function () {
var button = $('<div id="fbButton" class="fbLogoEnabled"></div>');
$('body').append(button);
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment