More stable, I hope...

This commit is contained in:
magnolia-fan
2011-11-27 13:56:10 +04:00
parent 8cf69faf32
commit 453e809646
12 changed files with 107 additions and 61 deletions
+19 -8
View File
@@ -3,6 +3,14 @@ class window.Ajax
referer: false
previous_page: null
showSpinner: ->
$('#artist-load-spinner').show()
false
hideSpinner: ->
$('#artist-load-spinner').hide()
false
load404Page: ->
$.get '/404.html', (data) ->
$('.data-container .inner').html data
@@ -43,19 +51,22 @@ class window.Ajax
detectPage: () ->
return false if @previous_page == _ajax.getAnchor()
@previous_page = _ajax.getAnchor()
path = _ajax.getAnchor()
if path == "/"
path = "/greetings/"
log "Ajax controller is detecting page ..."
log "Ajax controller is detecting page for #{path} ..."
if m = _ajax.getAnchor().match /\/artist\/(.+)\//
if m = path.match /\/artist\/(.+)\//
_search.loadArtistData m[1]
else if _ajax.getAnchor().match /\/settings\//
else if path.match /\/settings\//
_settings.loadSettingsPage()
else if _ajax.getAnchor().match /\/about\//
_ajax.loadAboutPage()
else if _ajax.getAnchor().match /\/stat\//
_ajax.loadStatPage()
else
_ajax.loadIndexPage();
this.showSpinner()
_session.query path, {}, (response) ->
_page.render response
_ajax.hideSpinner()
false
false
$(window).bind 'hashchange', ->
+5 -1
View File
@@ -15,6 +15,9 @@ jQuery ->
l.href = 'http://beathaven.org/'+ l.hash
window.log = (str) ->
_beathaven.logs.push
timestamp: Date()
info: str
console.log(str) if console?
$.ajaxSetup
@@ -28,9 +31,10 @@ class window.BeatHaven
last_height: false
lang: 'ru'
logs: []
init: ->
log "Initiatin BeatHaven ..."
log "Initiating BeatHaven ..."
window._vkontakte = new Vkontakte(2335068)
window._vkontakte.init()
+17
View File
@@ -1,5 +1,22 @@
class window.Page
@data: {}
@html: ""
@status: ""
render: (params) ->
@data = params.data
@html = params.html
@title = params.title
@status = params.status
log "Rendering page titled \"#{@title}\" of type \"#{params.renderer}\" ..."
$('#content').html(@html)
# yaCounter7596904.hit _ajax.getAnchor(), @title, _ajax.referer
_ajax.setTitle @title
false
print: (html) ->
$('#content').html(html)
false
+2
View File
@@ -12,7 +12,9 @@ class window.Session
@vk_params = _params
setUser: (user) ->
log "Setting user ..."
@user = user
log "Hello, #{if user.name? then user.name else "%username%"}!"
false
getUser: ->
+7 -4
View File
@@ -8,11 +8,10 @@ class window.Vkontakte
@api_id
init: ->
log "Initiatin Vkontakte API ..."
log "Initiating Vkontakte API ..."
window.vkAsyncInit = ->
VK.init apiId: _vkontakte.getApiId()
VK.Auth.getLoginStatus (response) ->
_vkontakte.authInfo(response)
_vkontakte.auth()
setTimeout ->
$('#vk_api_transport').append($('<script async="async" type="text/javascript" src="http://vkontakte.ru/js/api/openapi.js">'))
@@ -50,10 +49,13 @@ class window.Vkontakte
$('.fullscreen').hide();
if response.session.expire?
expire_in = response.session.expire * 1000 - new Date().getTime()
log "Session will expire in #{Math.round(expire_in / 1000)} seconds"
setTimeout ->
log "Session expired"
_vkontakte.auth()
false
, response.session.expire * 1000 - new Date().getTime() + 1000
, expire_in + 1000
else
_session = new Session({})
_session.setUser {}
@@ -63,6 +65,7 @@ class window.Vkontakte
$('.fullscreen').hide();
auth: ->
log "Requesting new Vkontakte session ..."
VK.Auth.getLoginStatus (response) ->
_vkontakte.authInfo(response)
false