1
0
Fork 0
oldhaven/public/javascripts/coffee/ajax.js

88 lines
2.9 KiB
JavaScript
Raw Normal View History

2011-06-27 18:41:36 +00:00
/* DO NOT MODIFY. This file was compiled Mon, 27 Jun 2011 17:43:40 GMT from
* /Users/chez/Sites/beathaven/app/coffeescripts/ajax.coffee
*/
(function() {
var Ajax;
Ajax = (function() {
function Ajax() {}
Ajax.prototype.referer = false;
Ajax.prototype.loadArtistData = function(name) {
search.showSpinner();
name = name.split(' ').join('+');
return $.get('/artist/' + name + '/', function(data) {
if (data.status != null) {
if (data.status === 'loading') {
search.showArtistPics(data.pics);
return setTimeout(function() {
return this.loadArtistData(name);
}, 3000);
} else if (data.status === 'corrected') {
return ajax.loadArtistData(data.page);
} else if (data.status === 'suggestions') {
search.hideSpinner();
return search.showSuggestions(data.values);
} else if (data.status === 'loading_failed') {
search.hideSpinner();
return search.showError();
}
} else {
this.setArchor('/artist/' + name + '/');
pages.renderArtist(data);
return beathaven.redrawScrollbar();
}
});
};
Ajax.prototype.loadSearchPage = function() {
return $.get('/templates/search.html', function(data) {
this.setArchor('/search/');
return pages.renderSearch(data);
});
};
Ajax.prototype.loadSettingsPage = function() {
return $.get('/templates/settings.html', function(data) {
this.setArchor('/settings/');
return pages.renderSettings(data);
});
};
Ajax.prototype.load404Page = function() {
return $.get('/404.html', function(data) {
$('.data-container .inner').html(data);
return beathaven.redrawScrollbar();
});
};
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.detectPage = function() {
var m;
if (m = this.getAnchor().match(/\/artist\/(.+)\//)) {
return this.loadArtistData(m[1]);
} else if (this.getAnchor() === '' || Ajax.getAnchor().match(/\/search\//)) {
return this.loadSearchPage();
} else if (this.getAnchor().match(/\/settings\//)) {
return this.loadSearchPage();
} else {
return this.load404Page();
}
};
return Ajax;
})();
$(function() {
$('a.data.artist').live('click', function() {
ajax.loadArtistData($(this).html());
return false;
});
return $(window).bind('hashchange', function() {
return ajax.detectPage();
});
});
}).call(this);