Permalink
Browse files

FaceBook

  • Loading branch information...
1 parent 084b074 commit f325029cf17f06ce769ef404e4a3dff359c6e211 @LinusU LinusU committed Sep 12, 2012
Showing with 73 additions and 2 deletions.
  1. +13 −0 fb.html
  2. +7 −2 src/app.coffee
  3. +53 −0 src/fb.coffee
View
@@ -0,0 +1,13 @@
+<!DOCTYPE html>
+<html>
+ <head>
+ <title>SWASH - FACEBOOK</title>
+ </head>
+ <body>
+ <script type="text/javascript">
+ token = /[\#\?\&]access_token=([^&#]+)/.exec(window.location.hash);
+ localStorage.setItem('fb-access-token', token[1]);
+ window.close();
+ </script>
+ </body>
+</html>
View
@@ -10,21 +10,26 @@ window.Swash =
if e.ctrlKey and e.keyCode == 65
window.Swash.run_code()
+ log: (msg)->
+ a.innerHTML += msg + '<br />'
+
run_code: ->
a = document.getElementById 'a'
b = document.getElementById 'b'
a.innerHTML += '<b>' + b.innerHTML + '</b><br />'
code = '(function () {\n'
for v of @context
code += 'var ' + v + ' = window.Swash.context.' + v + ';\n'
+ code += 'var p = window.Swash.log;\n'
code += 'return '
code += (CoffeeScript.compile 'return ->\n ' + b.innerText.replace(/\n/g, '\n ')).replace(/(\b)([a-zA-Z][a-zA-Z0-9]* = )/g, '$1$2window.Swash.context.$2')
code += '}).call({})\n'
out = ''
try
r = eval code
- out = r().toString()
+ s = r()
+ out = typeof s == 'string' ? s : null
catch e
out = '<b style="color: red;">' + e.toString() + '</b>'
- a.innerHTML += out + '<br />'
+ a.innerHTML += out + '<br />' if out
b.innerText = ''
View
@@ -0,0 +1,53 @@
+
+fb = null
+access_token = null
+
+graph = (url, cb)->
+ $.getJSON 'https://graph.facebook.com/' + url + '?callback=?&access_token=' + fb._token(), cb
+
+class FB_User
+ constructor: (@id, data = null)->
+ @_data = data || null
+ data: (cb)->
+ if @_data
+ cb.apply @_data
+ else
+ graph @id, (data)=>
+ cb.apply (@_data = data)
+ name: (cb)->
+ if @_data.name
+ cb.apply @_data.name
+ else
+ @data ->
+ @name
+ friends: (cb)->
+ id = @id
+ cb.apply {
+ each: (cb)=>
+ graph id + '/friends', (data)->
+ $.each data.data, ->
+ cb.apply
+ find: (name, cb)->
+ throw "Not implemented"
+ }
+
+Swash.context.fb = fb =
+ init: ->
+ if !fb._token()
+ url = 'https://www.facebook.com/dialog/oauth'
+ url += '?client_id=409185285801923'
+ url += '&redirect_uri=' + window.location + 'fb-init'
+ url += '&scope=user_about_me,friends_about_me,user_events,friends_events,user_groups,friends_groups,user_photos,friends_photos,user_status,friends_status'
+ url += '&response_type=token'
+ window.open(url)
+
+ _token: ->
+ localStorage.getItem 'fb-access-token'
+
+ me: new FB_User "me"
+
+ user: (username)->
+ alert "hej"
+
+ friends: (cb)->
+ fb.me.friends cb

0 comments on commit f325029

Please sign in to comment.