-
Notifications
You must be signed in to change notification settings - Fork 3
/
meetup_players.js.coffee
60 lines (50 loc) · 1.8 KB
/
meetup_players.js.coffee
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
delay = @rb757.Utils.delay
shuffle = @rb757.Utils.shuffle
class MeetupPlayers
@signedURL = 'https://api.meetup.com/2/members.json/?offset=0&format=json&group_id=1068870&only=link%2Cname%2Cphoto%2Cother_services&page=200&order=name&sig_id=3695330&sig=22f83da2503545273f1330c4963c0820d87a59bb'
@defaultPlayerSrc = 'http://identicons.github.com/metaskills.png'
constructor: ->
@players = $('.players')
@header = @players.find('header')
@count = @players.find('.players-count')
@health = @players.find('.players-health')
@playersArea = $('.players-area')
@setupEvents()
@getPlayers()
# Private
mousedown: =>
@players.addClass 'active'
false
mouseup: =>
@players.removeClass 'active'
false
setupEvents: ->
@players.on 'mousedown touchstart', @mousedown
@players.on 'mouseup touchend', @mouseup
getPlayers: ->
url = @constructor.signedURL
$.ajax url: url, dataType: 'jsonp', success: @renderPlayers
renderPlayers: (data, status, xhr) =>
players = shuffle(data.results)
content = $('<section>')
count = 0
for player in players when player.photo?.thumb_link
el = $ '<aside>', class: 'player', 'data-link': player.link
link = $ '<a>', href: player.link
img = $ '<img>', src: @constructor.defaultPlayerSrc, 'data-src': player.photo.thumb_link
el.append(link.append(img))
content.append el
count += 1
# Fancy visual count up.
health = []
for i in [1..count] by 1
do (i) => delay 20 * i, =>
h = 20 * Math.floor(i / 20 + 0.5)
unless h in health
health.push(h)
@health.text Array(health.length+1).join('Œ')
@count.text(i)
if i is count
@playersArea.append content.html()
true
$ -> rb757.meetupPlayers = new MeetupPlayers