leaderboard.js.coffee 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. $(document).ready ->
  2. friends_loaded = false
  3. community_loaded = false
  4. load_friends_leaderboard = () ->
  5. unless friends_loaded
  6. friends_loaded = true
  7. url = '/dashboard/user_scores?friends=true'
  8. selector = '#leaderboard-friends'
  9. load_friends_list(url, selector)
  10. load_community_leaderboard = () ->
  11. unless community_loaded
  12. community_loaded = true
  13. url = '/dashboard/user_scores'
  14. selector = '#leaderboard-community'
  15. load_friends_list(url, selector)
  16. toggle = () ->
  17. toggle_on = $(this).attr('toggle_on')
  18. toggle_off = $(this).attr('toggle_off')
  19. $('#leaderboard-title-' + toggle_on).addClass('active')
  20. $('#leaderboard-' + toggle_on).addClass('active')
  21. $('#leaderboard-title-' + toggle_off).removeClass('active')
  22. $('#leaderboard-' + toggle_off).removeClass('active')
  23. if toggle_on == "friends"
  24. load_friends_leaderboard()
  25. else
  26. load_community_leaderboard()
  27. load_friends_list = (url, selector) ->
  28. $.ajax url,
  29. type: 'GET'
  30. dataType: 'html'
  31. error: (jqXHR, textStatus, errorThrown) ->
  32. # $(selector).html "Error Loading Friend List: #{textStatus}"
  33. $(selector).html ""
  34. success: (data, textStatus, jqXHR) ->
  35. $(selector).slideUp 'slow', ->
  36. $(selector).html(data)
  37. $("abbr.timeago").timeago()
  38. $(selector + ' ul>li').click ->
  39. $(selector + ' ul>li.score-card').addClass('hide')
  40. $(this).parent().find('li.score-card').removeClass('hide')
  41. $(selector).slideDown()
  42. $("a[toggle_on]").click(toggle)
  43. if $('#leaderboard-title-friends.active').length > 0
  44. load_friends_leaderboard()
  45. if $('#leaderboard-title-community.active').length > 0
  46. load_community_leaderboard()