1
0
Fork 0
oldhaven/app/assets/javascripts/vkontakte.coffee

83 lines
2.3 KiB
CoffeeScript
Raw Normal View History

2011-09-07 23:47:11 +00:00
class window.Vkontakte
2011-09-09 22:13:02 +00:00
api_id: null
constructor: (@api_id) ->
getApiId: ->
@api_id
init: ->
window.vkAsyncInit = ->
VK.init apiId: _vkontakte.getApiId()
VK.Auth.getLoginStatus (response) ->
_vkontakte.authInfo(response)
2011-06-29 04:11:54 +00:00
2011-09-09 22:13:02 +00:00
setTimeout ->
$('#vk_api_transport').append('<script async="async" type="text/javascript" src="http://vkontakte.ru/js/api/openapi.js"></script>')
, 0
authInfo: (response) ->
if typeof response isnt 'undefined' and response.session
_session = new Session(response.session)
_session.query '/user/auth', {}, (ar) ->
if ar.newbie
VK.Api.call 'getVariable', key: 1281, (r) ->
_session.query '/user/update', params: { name: r.response }, (ar2) ->
2011-09-09 22:13:02 +00:00
_session.setUser ar2.user
2011-09-09 23:30:03 +00:00
$('#username')
.html (if _session.getUser().name then _session.getUser().name else '%username%')
2011-09-09 22:13:02 +00:00
window._session = _session
_ajax.detectPage()
_session.displayAuthorizedContent()
2011-09-15 09:38:24 +00:00
$('#authorized').css display: 'block'
if ar.ok_reload
window.location.reload()
false
else if ar.ok_reload
window.location.reload()
false
2011-09-09 22:13:02 +00:00
else
_session.setUser ar.user
2011-09-09 23:30:03 +00:00
$('#username')
.html (if _session.getUser().name then _session.getUser().name else '%username%')
_session.displayAuthorizedContent()
2011-09-09 22:13:02 +00:00
window._session = _session
_ajax.detectPage()
$('.fullscreen').hide();
if response.session.expire?
setTimeout ->
_vkontakte.auth()
false
, response.session.expire * 1000 - new Date().getTime() + 1000
else
_session = new Session({})
_session.setUser {}
_session.hideAuthorizedContent()
2011-09-09 22:13:02 +00:00
window._session = _session
_ajax.detectPage()
$('.fullscreen').hide();
auth: ->
VK.Auth.getLoginStatus (response) ->
_vkontakte.authInfo(response)
false
, 8
false
2011-06-27 18:41:36 +00:00
2011-09-15 09:38:24 +00:00
$('#login').live 'click', ->
2011-09-09 22:13:02 +00:00
VK.Auth.login (response) ->
_vkontakte.authInfo(response)
false
, 8
false
2011-09-15 09:38:24 +00:00
$('#logout').live 'click', ->
2011-09-09 22:13:02 +00:00
VK.Auth.logout (response) ->
_vkontakte.authInfo(response)
2011-09-19 08:21:03 +00:00
$('.button-container').hide()
2011-09-09 22:13:02 +00:00
false
false