59 lines
1.3 KiB
CoffeeScript
59 lines
1.3 KiB
CoffeeScript
class window.Ajax
|
|
|
|
referer: false
|
|
previous_page: null
|
|
|
|
showSpinner: ->
|
|
$('#artist-load-spinner').show()
|
|
false
|
|
|
|
hideSpinner: ->
|
|
$('#artist-load-spinner').hide()
|
|
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 in ["", "/"]
|
|
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()
|
|
if _session.getUser().id?
|
|
$('.authorized-action').show()
|
|
else
|
|
$('.authorized-action').hide()
|
|
false
|
|
false
|
|
|
|
$(window).bind 'hashchange', ->
|
|
_ajax.detectPage()
|
|
false
|