Browse files

Keep the song highlighted after voting for it or removing your vote

  • Loading branch information...
1 parent 70ce50a commit cbd207696e495e5169c8392a532c7f27a83adebd @lukeledet committed Jan 13, 2013
Showing with 14 additions and 11 deletions.
  1. +9 −9 app/assets/javascripts/keys.js.coffee
  2. +4 −0 app/assets/javascripts/songs.js.coffee
  3. +1 −2 app/views/votes/new.js.erb
View
18 app/assets/javascripts/keys.js.coffee
@@ -3,7 +3,7 @@ window.selected_song = null
key.filter = (e) -> true
key '/,s', ->
- return if $('.navbar-search input').is(':focus')
+ return if $('.navbar-search input').is(':focus')
$('.navbar-search input').focus()
return false
@@ -16,31 +16,31 @@ key 'down', ->
window.selected_song = if selected_song != null then selected_song + 1 else 1
window.selected_song = $('#song_list tr').length - 1 if selected_song >= $('#song_list tr').length
- $('#song_list tr').removeClass('selected')
- $('#song_list tr:eq('+selected_song+')').addClass('selected')
+ highlight_selected_song()
+
return false
key 'up', ->
- return if $('.navbar-search input').is(':focus')
+ return if $('.navbar-search input').is(':focus')
$('.navbar-search input').blur()
window.selected_song = if selected_song != null then selected_song - 1 else 1
if selected_song < 1
- $('.navbar-search input').focus()
+ $('.navbar-search input').focus()
window.selected_song = null
- $('#song_list tr').removeClass('selected')
- $('#song_list tr:eq('+selected_song+')').addClass('selected')
+ highlight_selected_song()
+
return false
key 'left', ->
- return if $('.navbar-search input').is(':focus')
+ return if $('.navbar-search input').is(':focus')
$('.pagination .prev a').click()
return false
key 'right', ->
- return if $('.navbar-search input').is(':focus')
+ return if $('.navbar-search input').is(':focus')
$('.pagination .next_page a').click()
return false
View
4 app/assets/javascripts/songs.js.coffee
@@ -15,6 +15,10 @@ window.cancel_search = ->
$('.navbar-search input').val('').keyup().blur()
$('#cancel-search').hide()
+window.highlight_selected_song = ->
+ $('#song_list tr').removeClass('selected')
+ $('#song_list tr:eq('+selected_song+')').addClass('selected')
+
jQuery ($) ->
$('.search-query')
.on 'keyup', (e) ->
View
3 app/views/votes/new.js.erb
@@ -1,6 +1,5 @@
<% if @vote %>
$('#queue').html('<%= escape_javascript(render 'songs/queue') %>');
$('#song_'+<%= @song.id %>).replaceWith('<%= escape_javascript(render partial: 'songs/song', object: @song) %>');
-<% else %>
-
+ highlight_selected_song();
<% end %>

0 comments on commit cbd2076

Please sign in to comment.