Skip to content

Instantly share code, notes, and snippets.

@zholmquist
Created October 11, 2011 22:33
Show Gist options
  • Save zholmquist/1279669 to your computer and use it in GitHub Desktop.
Save zholmquist/1279669 to your computer and use it in GitHub Desktop.
OAuth Popups
/* netflix oauth */
this.beginNetflixOAuth = function()
{
var popupParams = 'location=0,status=0,width=320,height=480';
self._netflixWindow = window.open('/login/', 'netflixWindow', popupParams);
self._netflixInterval = window.setInterval(self.completeNetflixConnect, 1000);
self.logEvent('Authentication', 'netflix', 'begin')
};
/* netflix is complete. */
this.completeNetflixConnect = function()
{
if (self._netflixWindow.closed)
{
self.logEvent('Authentication', 'netflix', 'complete')
window.clearInterval(self._netflixInterval);
window.location.reload();
}
};
/* twitter connect */
this.beginTwitterOAuth = function()
{
var popupParams = 'location=0,status=0,width=850,height=450';
self._twitterWindow = window.open('/connect/twitter/', 'twitterWindow', popupParams);
self._twitterInterval = window.setInterval(self.completeTwitterConnect, 1000);
self.logEvent('Authentication', 'twitter', 'begin')
}
this.beginFacebookOAuth = function()
{
var popupParams = 'location=0,status=0,width=600,height=300';
self._facebookWindow = window.open('/connect/facebook/', 'facebookWindow', popupParams);
self._facebookInterval = window.setInterval(self.completeFacebookConnect, 1000);
self.logEvent('Authentication', 'facebook', 'begin')
}
this.completeFacebookConnect = function()
{
if (self._facebookWindow.closed)
{
self.logEvent('Authentication', 'facebook', 'complete')
window.clearInterval(self._facebookInterval);
$('#fb-connect').html('Disconnect Facebook');
$('#fb-connect').attr('href','/disconnect/facebook/');
$('#fb-connect').unbind('click');
$('#fb-connect').attr('id','fb-disconnect');
// tie up new event
$('#fb-disconnect').bind('click', function(){
self.disconnectFacebook();
return false;
});
}
};
/* twitter complete */
this.completeTwitterConnect = function()
{
if (self._twitterWindow.closed)
{
self.logEvent('Authentication', 'twitter', 'complete')
window.clearInterval(self._twitterInterval);
$('#twitter-connect').html('Disconnect Twitter');
$('#twitter-connect').attr('href','/disconnect/twitter/');
$('#twitter-connect').unbind('click');
$('#twitter-connect').attr('id','twitter-disconnect');
// tie up new event
$('#twitter-disconnect').bind('click', function(){
self.disconnectTwitter();
return false;
});
}
}
this.disconnectTwitter = function()
{
$.post('/disconnect/twitter/', function(data) {
if(data['success']) {
$('#twitter-disconnect').html('Connect Twitter');
$('#twitter-disconnect').attr('href','/connect/twitter/');
$('#twitter-disconnect').unbind('click');
$('#twitter-disconnect').attr('id','twitter-connect');
$('#twitter-connect').click(function(){
self.beginTwitterOAuth();
return false;
});
}
})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment