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

75 lines
1.5 KiB
CoffeeScript

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
false
loadIndexPage: ->
$('#content').load '/greetings/'
_ajax.setTitle ''
false
loadAboutPage: ->
$('#content').load '/about/'
_ajax.setTitle 'About'
false
loadStatPage: ->
$('#content').load '/stat/'
_ajax.setTitle 'Statistics'
false
setArchor: (anchor) ->
@referer = this.getAnchor()
window.location.hash = '#' +anchor
getAnchor: () ->
window.location.hash.substring 1;
setTitle: (title) ->
if title?
document.title = title+ ' @ BeatHaven'
else
document.title ='BeatHaven'
go: (url) ->
this.setArchor url
false
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 for #{path} ..."
if m = path.match /\/artist\/(.+)\//
_search.loadArtistData m[1]
else if path.match /\/settings\//
_settings.loadSettingsPage()
else
this.showSpinner()
_session.query path, {}, (response) ->
_page.render response
_ajax.hideSpinner()
false
false
$(window).bind 'hashchange', ->
_ajax.detectPage()
false