codecombat/app/core/services/facebook.coffee

42 lines
1.4 KiB
CoffeeScript
Raw Normal View History

module.exports = initializeFacebook = ->
# Additional JS functions here
window.fbAsyncInit = ->
FB.init
2014-07-04 20:54:30 -04:00
appId: (if document.location.origin is 'http://localhost:3000' then '607435142676437' else '148832601965463') # App ID
channelUrl: document.location.origin + '/channel.html' # Channel File
status: true # check login status
cookie: true # enable cookies to allow the server to access the session
xfbml: true # parse XFBML
Backbone.Mediator.publish 'auth:facebook-api-loaded', {}
2014-06-19 21:18:40 -04:00
# This is fired for any auth related change, such as login, logout or session refresh.
2014-07-04 20:54:30 -04:00
FB.Event.subscribe 'auth.authResponseChange', (response) ->
2014-06-19 21:18:40 -04:00
# Here we specify what we do with the response anytime this event occurs.
2014-07-04 20:54:30 -04:00
if response.status is 'connected'
2014-06-19 21:18:40 -04:00
# They have logged in to the app.
2014-08-28 14:16:55 -04:00
Backbone.Mediator.publish 'auth:logged-in-with-facebook', response: response
2014-07-04 20:54:30 -04:00
else if response.status is 'not_authorized'
#
else
#
# Load the SDK asynchronously
((d) ->
js = undefined
2014-07-04 20:54:30 -04:00
id = 'facebook-jssdk'
ref = d.getElementsByTagName('script')[0]
return if d.getElementById(id)
2014-07-04 20:54:30 -04:00
js = d.createElement('script')
js.id = id
js.async = true
2014-07-04 20:54:30 -04:00
js.src = '//connect.facebook.net/en_US/all.js'
2014-06-19 21:18:40 -04:00
2014-07-04 20:54:30 -04:00
#js.src = '//connect.facebook.net/en_US/all/debug.js'
ref.parentNode.insertBefore js, ref
return
) document