var Ajax; Ajax = (function() { function Ajax() {} Ajax.prototype.referer = false; Ajax.prototype.loadArtistData = function(name) { _search.showSpinner(); name = name.split(' ').join('+'); $.get('/artist/' + name + '/', function(data) { if (data.status != null) { if (data.status === 'loading') { _search.showArtistPics(data.pics); setTimeout(function() { return _ajax.loadArtistData(name); }, 3000); } else if (data.status === 'corrected') { _ajax.loadArtistData(data.page); } else if (data.status === 'suggestions') { _search.hideSpinner(); _search.showSuggestions(data.values); } else if (data.status === 'loading_failed') { _search.hideSpinner(); _search.showError(); } return _beathaven.redrawScrollbar(); } else { _ajax.setArchor('/artist/' + name + '/'); return _pages.renderArtist(data); } }); return false; }; Ajax.prototype.loadSearchPage = function() { $.get('/templates/search.html', function(data) { _ajax.setArchor('/search/'); return _pages.renderSearch(data); }); return false; }; Ajax.prototype.loadSettingsPage = function() { $.get('/templates/settings.html', function(data) { _ajax.setArchor('/settings/'); return _pages.renderSettings(data); }); return false; }; Ajax.prototype.load404Page = function() { $.get('/404.html', function(data) { $('.data-container .inner').html(data); return _beathaven.redrawScrollbar(); }); return false; }; Ajax.prototype.loadAboutPage = function() { $.get('/templates/about.html', function(data) { _pages.renderTextpage(data); return _ajax.setTitle('About'); }); return false; }; Ajax.prototype.setArchor = function(anchor) { this.referer = this.getAnchor(); return window.location.hash = '#' + anchor; }; Ajax.prototype.getAnchor = function() { return window.location.hash.substring(1); }; Ajax.prototype.setTitle = function(title) { return document.title = title + ' @ BeatHaven'; }; Ajax.prototype.go = function(url) { this.setArchor(url); return false; }; Ajax.prototype.detectPage = function() { var m; if (m = _ajax.getAnchor().match(/\/artist\/(.+)\//)) { _ajax.loadArtistData(m[1]); } else if (_ajax.getAnchor() === '' || _ajax.getAnchor().match(/\/search\//)) { _ajax.loadSearchPage(); } else if (_ajax.getAnchor().match(/\/settings\//)) { _ajax.loadSettingsPage(); } else if (_ajax.getAnchor().match(/\/about\//)) { _ajax.loadAboutPage(); } else { _ajax.loadSearchPage(); } return false; }; return Ajax; })(); $('a.data.artist').live('click', function() { _ajax.loadArtistData($(this).html()); return false; }); $(window).bind('hashchange', function() { _ajax.detectPage(); return false; });