Skip to content

Instantly share code, notes, and snippets.

@dpmccabe
Created April 10, 2013 18:59
Show Gist options
  • Save dpmccabe/5357443 to your computer and use it in GitHub Desktop.
Save dpmccabe/5357443 to your computer and use it in GitHub Desktop.
jQuery ->
$.ajax
url: "//connect.facebook.net/en_US/all.js"
dataType: 'script'
cache: true
$('a.requires-fb').click (e) ->
e.preventDefault()
return_to = $(this).attr('href')
ask_for_fb(return_to)
$('#simple-side a.close').click (e) ->
$(this).parents('.alert').hide()
e.preventDefault()
@ask_for_fb = (return_to='#', callback_code=null) ->
load_login_modal()
$('#login-modal .modal-body').append('<iframe src="' + gon.signup_modal_path + '" class="hidden-iframe"></iframe>')
$('input#new-student-return-to, input#log-in-return-to').val(return_to) if return_to != '#'
$('a#fb-connect').click (e) ->
e.preventDefault()
try
FB.login (response) ->
if response.authResponse
$('a#fb-connect').spin()
$.get '/auth/facebook/callback',
signed_request: response.authResponse.signedRequest
, ->
if return_to != '#'
window.location.replace(return_to)
else
callback_code() if callback_code
$.post gon.refresh_navigation_path
, scope: 'email'
catch error
$('#fb-connect-error').fadeIn()
window.fbAsyncInit = ->
FB.init(appId: gon.global.FACEBOOK_APP_ID, cookie: true)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment