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

77 lines
2.2 KiB
JavaScript

var Search;
Search = (function() {
function Search() {}
Search.prototype.pics = [];
Search.prototype.showSpinner = function() {
$('.search-container input').attr({
disabled: 'disabled'
}).blur();
$('.search-container img').show();
$('.autocomplete-container').hide();
$('.artist_loading.failed').hide();
this.hideSuggestions();
return false;
};
Search.prototype.hideSpinner = function() {
$('.search-container input').removeAttr('disabled');
$('.search_field').focus();
$('.search-container img').hide();
return false;
};
Search.prototype.showSuggestions = function(values) {
var item, _i, _len;
for (_i = 0, _len = values.length; _i < _len; _i++) {
item = values[_i];
$('.suggestions ul').append('\
<li>\
<a class="data artist">' + item.name + '</a>\
' + (item.desc != null ? '<br/><span>' + item.desc + '</span>' : '') + '\
</li>');
}
$('.suggestions').show();
return false;
};
Search.prototype.hideSuggestions = function() {
$('.suggestions ul li').remove();
$('.suggestions').hide();
return false;
};
Search.prototype.showArtistPics = function(pics) {
var pic, _i, _len;
$('.artist_loading.ok, .artist_pics').show();
for (_i = 0, _len = pics.length; _i < _len; _i++) {
pic = pics[_i];
if (this.pics.indexOf(pic) === -1) {
this.pics.push(pic);
$('.artist_pics').append('\
<div class="pic">\
<img src="' + pic + '" alt=""/>\
</div>');
}
}
return false;
};
Search.prototype.showError = function() {
$('.artist_loading.ok, .artist_pics').hide();
$('.artist_loading.failed').show();
return this.pics = [];
};
return Search;
})();
$('.search').live('click', function() {
_ajax.go('/search/');
return false;
});
$('#search_form').live('submit', function() {
$('.autocomplete-container').remove();
_ajax.loadArtistData($('#search_field').val());
return false;
});
$('.suggestions a').live('click', function() {
$('#search_field').val($(this).text());
return false;
});
$('.data.artist').live('click', function() {
_ajax.go('/artist/' + $(this).text().replace(' ', '+') + '/');
return false;
});