class Ajax referer: false loadArtistData: (name) -> search.showSpinner() name = name.split(' ').join('+') $.get '/artist/' +name+ '/', (data) -> if data.status? if data.status is 'loading' search.showArtistPics data.pics setTimeout () -> this.loadArtistData name , 3000 else if data.status is 'corrected' ajax.loadArtistData data.page else if data.status is 'suggestions' search.hideSpinner() search.showSuggestions data.values else if data.status == 'loading_failed' search.hideSpinner() search.showError() else this.setArchor '/artist/' +name+ '/' pages.renderArtist data beathaven.redrawScrollbar() loadSearchPage: -> $.get '/templates/search.html', (data) -> this.setArchor '/search/' pages.renderSearch data loadSettingsPage: -> $.get '/templates/settings.html', (data) -> this.setArchor '/settings/' pages.renderSettings data load404Page: -> $.get '/404.html', (data) -> $('.data-container .inner').html data beathaven.redrawScrollbar() setArchor: (anchor) -> @referer = this.getAnchor() window.location.hash = '#' +anchor getAnchor: () -> window.location.hash.substring 1; setTitle: (title) -> document.title = title+ ' @ BeatHaven' detectPage: () -> if m = this.getAnchor().match /\/artist\/(.+)\// this.loadArtistData m[1] else if this.getAnchor() == '' or Ajax.getAnchor().match /\/search\// this.loadSearchPage(); else if this.getAnchor().match /\/settings\// this.loadSearchPage() else this.load404Page() $ -> window.ajax = new Ajax() $('a.data.artist').live 'click', -> ajax.loadArtistData $(this).html() false $(window).bind 'hashchange', -> ajax.detectPage()