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

85 lines
1.9 KiB
CoffeeScript
Raw Normal View History

2011-09-07 23:47:11 +00:00
class window.Ajax
2011-06-27 18:41:36 +00:00
referer: false
loadArtistData: (name) ->
2011-06-27 20:43:54 +00:00
_search.showSpinner()
2011-06-27 18:41:36 +00:00
name = name.split(' ').join('+')
$.get '/artist/' +name+ '/', (data) ->
if data.status?
if data.status is 'loading'
2011-06-27 20:43:54 +00:00
_search.showArtistPics data.pics
2011-06-27 18:41:36 +00:00
setTimeout () ->
2011-06-27 20:43:54 +00:00
_ajax.loadArtistData name
2011-06-27 18:41:36 +00:00
, 3000
else if data.status is 'corrected'
2011-06-27 20:43:54 +00:00
_ajax.loadArtistData data.page
2011-06-27 18:41:36 +00:00
else if data.status is 'suggestions'
2011-06-27 20:43:54 +00:00
_search.hideSpinner()
_search.showSuggestions data.values
2011-06-27 18:41:36 +00:00
else if data.status == 'loading_failed'
2011-06-27 20:43:54 +00:00
_search.hideSpinner()
_search.showError()
2011-06-27 18:41:36 +00:00
else
2011-06-27 20:43:54 +00:00
_ajax.setArchor '/artist/' +name+ '/'
_pages.renderArtist data
2011-09-08 13:10:52 +00:00
#_search.hideSpinner()
2011-06-27 20:43:54 +00:00
false
2011-06-27 18:41:36 +00:00
loadSearchPage: ->
2011-07-04 15:09:44 +00:00
2011-06-27 20:43:54 +00:00
false
2011-06-27 18:41:36 +00:00
loadSettingsPage: ->
$.get '/templates/settings.html', (data) ->
2011-06-27 20:43:54 +00:00
_ajax.setArchor '/settings/'
2011-06-30 05:12:52 +00:00
_pages.renderSettings _beathaven.localizeHTML $(data)
2011-06-27 20:43:54 +00:00
false
2011-06-27 18:41:36 +00:00
load404Page: ->
$.get '/404.html', (data) ->
$('.data-container .inner').html data
2011-06-27 20:43:54 +00:00
_beathaven.redrawScrollbar()
false
2011-06-27 18:41:36 +00:00
2011-06-29 04:11:54 +00:00
loadAboutPage: ->
$.get '/templates/about.html', (data) ->
_pages.renderTextpage data
_ajax.setTitle 'About'
false
2011-06-27 18:41:36 +00:00
setArchor: (anchor) ->
@referer = this.getAnchor()
window.location.hash = '#' +anchor
getAnchor: () ->
window.location.hash.substring 1;
setTitle: (title) ->
document.title = title+ ' @ BeatHaven'
2011-06-27 20:43:54 +00:00
go: (url) ->
this.setArchor url
false
2011-06-27 18:41:36 +00:00
detectPage: () ->
2011-06-27 20:43:54 +00:00
if m = _ajax.getAnchor().match /\/artist\/(.+)\//
_ajax.loadArtistData m[1]
else if _ajax.getAnchor() == '' or _ajax.getAnchor().match /\/search\//
_ajax.loadSearchPage();
else if _ajax.getAnchor().match /\/settings\//
_ajax.loadSettingsPage()
2011-06-29 04:11:54 +00:00
else if _ajax.getAnchor().match /\/about\//
_ajax.loadAboutPage()
2011-06-27 18:41:36 +00:00
else
2011-06-27 20:43:54 +00:00
_ajax.loadSearchPage()
false
2011-06-27 18:41:36 +00:00
2011-06-27 20:43:54 +00:00
$('a.data.artist').live 'click', ->
_ajax.loadArtistData $(this).html()
false
$(window).bind 'hashchange', ->
_ajax.detectPage()
false