2014-06-15 17:19:37 -04:00
|
|
|
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
|
2014-06-15 17:19:37 -04:00
|
|
|
status: true # check login status
|
|
|
|
cookie: true # enable cookies to allow the server to access the session
|
|
|
|
xfbml: true # parse XFBML
|
|
|
|
|
2014-08-27 15:24:03 -04:00
|
|
|
Backbone.Mediator.publish 'auth:facebook-api-loaded', {}
|
2014-06-19 21:18:40 -04:00
|
|
|
|
2014-06-15 17:19:37 -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
|
|
|
|
2014-06-15 17:19:37 -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-06-15 17:19:37 -04:00
|
|
|
|
2014-07-04 20:54:30 -04:00
|
|
|
else if response.status is 'not_authorized'
|
2014-06-15 17:19:37 -04:00
|
|
|
#
|
|
|
|
else
|
2014-08-27 15:24:03 -04:00
|
|
|
#
|
2014-06-15 17:19:37 -04:00
|
|
|
|
|
|
|
# Load the SDK asynchronously
|
|
|
|
((d) ->
|
|
|
|
js = undefined
|
2014-07-04 20:54:30 -04:00
|
|
|
id = 'facebook-jssdk'
|
|
|
|
ref = d.getElementsByTagName('script')[0]
|
2014-06-15 17:19:37 -04:00
|
|
|
return if d.getElementById(id)
|
2014-07-04 20:54:30 -04:00
|
|
|
js = d.createElement('script')
|
2014-06-15 17:19:37 -04:00
|
|
|
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'
|
2014-06-15 17:19:37 -04:00
|
|
|
ref.parentNode.insertBefore js, ref
|
|
|
|
return
|
|
|
|
) document
|