1
0
Fork 0
oldhaven/app/coffeescripts/search.coffee

63 lines
1.5 KiB
CoffeeScript

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